Annotation of loncom/interface/lonuserutils.pm, revision 1.97.2.14

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Utility functions for managing LON-CAPA user accounts
                      3: #
1.97.2.14! raeburn     4: # $Id: lonuserutils.pm,v 1.97.2.13 2010/01/20 21:42:30 raeburn Exp $
1.1       raeburn     5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ###############################################################
                     30: 
                     31: package Apache::lonuserutils;
                     32: 
                     33: use strict;
                     34: use Apache::lonnet;
                     35: use Apache::loncommon();
                     36: use Apache::lonhtmlcommon;
                     37: use Apache::lonlocal;
1.8       raeburn    38: use Apache::longroup;
                     39: use LONCAPA qw(:DEFAULT :match);
1.1       raeburn    40: 
                     41: ###############################################################
                     42: ###############################################################
                     43: # Drop student from all sections of a course, except optional $csec
                     44: sub modifystudent {
1.52      raeburn    45:     my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1       raeburn    46:     # if $csec is undefined, drop the student from all the courses matching
                     47:     # this one.  If $csec is defined, drop them from all other sections of
                     48:     # this course and add them to section $csec
1.17      raeburn    49:     my ($cnum,$cdom) = &get_course_identity($courseid);
1.1       raeburn    50:     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
                     51:     my ($tmp) = keys(%roles);
                     52:     # Bail out if we were unable to get the students roles
                     53:     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
                     54:     # Go through the roles looking for enrollment in this course
                     55:     my $result = '';
                     56:     foreach my $course (keys(%roles)) {
                     57:         if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
                     58:             # We are in this course
                     59:             my $section=$1;
                     60:             $section='' if ($course eq "/$cdom/$cnum".'_st');
                     61:             if (defined($csec) && $section eq $csec) {
                     62:                 $result .= 'ok:';
                     63:             } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
                     64:                 my (undef,$end,$start)=split(/\_/,$roles{$course});
                     65:                 my $now=time;
                     66:                 # if this is an active role
                     67:                 if (!($start && ($now<$start)) || !($end && ($now>$end))) {
                     68:                     my $reply=&Apache::lonnet::modifystudent
                     69:                         # dom  name  id mode pass     f     m     l     g
                     70:                         ($udom,$unam,'',  '',  '',undef,undef,undef,undef,
1.22      raeburn    71:                          $section,time,undef,undef,$desiredhost,'','manual',
1.52      raeburn    72:                          '',$courseid,'',$context);
1.1       raeburn    73:                     $result .= $reply.':';
                     74:                 }
                     75:             }
                     76:         }
                     77:     }
                     78:     if ($result eq '') {
1.37      raeburn    79:         $result = &mt('Unable to find section for this student');
1.1       raeburn    80:     } else {
                     81:         $result =~ s/(ok:)+/ok/g;
                     82:     }
                     83:     return $result;
                     84: }
                     85: 
                     86: sub modifyuserrole {
                     87:     my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
                     88:         $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
1.84      raeburn    89:         $end,$start,$checkid,$inststatus) = @_;
1.5       raeburn    90:     my ($scope,$userresult,$authresult,$roleresult,$idresult);
1.1       raeburn    91:     if ($setting eq 'course' || $context eq 'course') {
                     92:         $scope = '/'.$cid;
                     93:         $scope =~ s/\_/\//g;
1.97.2.6  raeburn    94:         if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
1.1       raeburn    95:             $scope .='/'.$sec;
                     96:         }
1.5       raeburn    97:     } elsif ($context eq 'domain') {
1.1       raeburn    98:         $scope = '/'.$env{'request.role.domain'}.'/';
1.13      raeburn    99:     } elsif ($context eq 'author') {
1.1       raeburn   100:         $scope =  '/'.$env{'user.domain'}.'/'.$env{'user.name'};
                    101:     }
                    102:     if ($context eq 'domain') {
                    103:         my $uhome = &Apache::lonnet::homeserver($uname,$udom);
                    104:         if ($uhome ne 'no_host') {
1.5       raeburn   105:             if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
1.1       raeburn   106:                 if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
                    107:                     ($umode eq 'localauth')) {
                    108:                     $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
                    109:                 }
                    110:             }
1.5       raeburn   111:             if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
                    112:                 ($env{'form.recurseid'}) && ($checkid)) {
                    113:                 my %userupdate = (
                    114:                                   lastname   => $last,
                    115:                                   middlename => $middle,
                    116:                                   firstname  => $first,
                    117:                                   generation => $gene,
                    118:                                   id         => $uid,
                    119:                                  );
                    120:                 $idresult = &propagate_id_change($uname,$udom,\%userupdate);
                    121:             }
1.1       raeburn   122:         }
                    123:     }
                    124:     $userresult =
                    125:         &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
                    126:                                     $middle,$last,$gene,$forceid,$desiredhome,
1.84      raeburn   127:                                     $email,$inststatus);
1.1       raeburn   128:     if ($userresult eq 'ok') {
1.5       raeburn   129:         if ($role ne '') {
1.22      raeburn   130:             $role =~ s/_/\//g;
1.1       raeburn   131:             $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
1.52      raeburn   132:                                                       $role,$end,$start,'',
                    133:                                                       '',$context);
1.1       raeburn   134:         }
                    135:     }
1.5       raeburn   136:     return ($userresult,$authresult,$roleresult,$idresult);
1.1       raeburn   137: }
                    138: 
1.5       raeburn   139: sub propagate_id_change {
                    140:     my ($uname,$udom,$user) = @_;
1.12      raeburn   141:     my (@types,@roles);
1.5       raeburn   142:     @types = ('active','future');
                    143:     @roles = ('st');
                    144:     my $idresult;
                    145:     my %roleshash = &Apache::lonnet::get_my_roles($uname,
1.12      raeburn   146:                         $udom,'userroles',\@types,\@roles);
                    147:     my %args = (
                    148:                 one_time => 1,
                    149:                );
1.5       raeburn   150:     foreach my $item (keys(%roleshash)) {
1.22      raeburn   151:         my ($cnum,$cdom,$role) = split(/:/,$item,-1);
1.5       raeburn   152:         my ($start,$end) = split(/:/,$roleshash{$item});
                    153:         if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.12      raeburn   154:             my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
                    155:             my %coursehash = 
                    156:                 &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
                    157:             my $cdesc = $coursehash{'description'};
                    158:             if ($cdesc eq '') { 
                    159:                 $cdesc = $cdom.'_'.$cnum;
                    160:             }
1.5       raeburn   161:             if ($result eq 'ok') {
1.12      raeburn   162:                 $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5       raeburn   163:             } else {
1.12      raeburn   164:                 $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
1.5       raeburn   165:             }
                    166:         }
                    167:     }
                    168:     return $idresult;
                    169: }
                    170: 
                    171: sub update_classlist {
1.63      raeburn   172:     my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
1.6       albertel  173:     my ($uid,$classlistentry);
1.5       raeburn   174:     my $fullname =
                    175:         &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
                    176:                                      $user->{'lastname'},$user->{'generation'},
                    177:                                      'lastname');
                    178:     my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
                    179:                                          $cdom,$cnum);
                    180:     my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
                    181:     my $ididx=&Apache::loncoursedata::CL_ID() - 2;
                    182:     my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
1.63      raeburn   183:     my $endidx = &Apache::loncoursedata::CL_END() - 2;
                    184:     my $startidx = &Apache::loncoursedata::CL_START() - 2;
1.5       raeburn   185:     for (my $i=0; $i<@classinfo; $i++) {
1.63      raeburn   186:         if ($i == $endidx) {
                    187:             if ($newend ne '') {
                    188:                 $classlistentry .= $newend.':';
                    189:             } else {
                    190:                 $classlistentry .= $classinfo[$i].':';
                    191:             }
                    192:         } elsif ($i == $startidx) {
                    193:             if ($newend ne '') {
                    194:                 if ($classinfo[$i] > $newend) {
                    195:                     $classlistentry .= $newend.':';
                    196:                 } else {
                    197:                     $classlistentry .= $classinfo[$i].':';
                    198:                 }
                    199:             } else {
                    200:                 $classlistentry .= $classinfo[$i].':';
                    201:             }
                    202:         } elsif ($i == $ididx) {
1.5       raeburn   203:             if (defined($user->{'id'})) {
                    204:                 $classlistentry .= $user->{'id'}.':';
                    205:             } else {
                    206:                 $classlistentry .= $classinfo[$i].':';
                    207:             }
                    208:         } elsif ($i == $nameidx) {
1.63      raeburn   209:             if (defined($user->{'lastname'})) {
                    210:                 $classlistentry .= $fullname.':';
                    211:             } else {
                    212:                 $classlistentry .= $classinfo[$i].':';
                    213:             }
1.5       raeburn   214:         } else {
                    215:             $classlistentry .= $classinfo[$i].':';
                    216:         }
                    217:     }
                    218:     $classlistentry =~ s/:$//;
                    219:     my $reply=&Apache::lonnet::cput('classlist',
                    220:                                     {"$uname:$udom" => $classlistentry},
                    221:                                     $cdom,$cnum);
                    222:     if (($reply eq 'ok') || ($reply eq 'delayed')) {
                    223:         return 'ok';
                    224:     } else {
                    225:         return 'error: '.$reply;
                    226:     }
                    227: }
                    228: 
                    229: 
1.1       raeburn   230: ###############################################################
                    231: ###############################################################
1.2       raeburn   232: # build a role type and role selection form
                    233: sub domain_roles_select {
                    234:     # Set up the role type and role selection boxes when in 
                    235:     # domain context   
                    236:     #
                    237:     # Role types
1.97.2.4  raeburn   238:     my @roletypes = ('domain','author','course','community');
1.2       raeburn   239:     my %lt = &role_type_names();
1.1       raeburn   240:     #
                    241:     # build up the menu information to be passed to
                    242:     # &Apache::loncommon::linked_select_forms
                    243:     my %select_menus;
1.2       raeburn   244:     if ($env{'form.roletype'} eq '') {
                    245:         $env{'form.roletype'} = 'domain';
                    246:     }
                    247:     foreach my $roletype (@roletypes) {
1.1       raeburn   248:         # set up the text for this domain
1.2       raeburn   249:         $select_menus{$roletype}->{'text'}= $lt{$roletype};
1.97.2.5  raeburn   250:         my $crstype;
                    251:         if ($roletype eq 'community') {
                    252:             $crstype = 'Community';
                    253:         }
1.1       raeburn   254:         # we want a choice of 'default' as the default in the second menu
1.2       raeburn   255:         if ($env{'form.roletype'} ne '') {
                    256:             $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
                    257:         } else { 
                    258:             $select_menus{$roletype}->{'default'} = 'Any';
                    259:         }
1.1       raeburn   260:         # Now build up the other items in the second menu
1.2       raeburn   261:         my @roles;
                    262:         if ($roletype eq 'domain') {
                    263:             @roles = &domain_roles();
1.13      raeburn   264:         } elsif ($roletype eq 'author') {
1.2       raeburn   265:             @roles = &construction_space_roles();
                    266:         } else {
1.17      raeburn   267:             my $custom = 1;
1.97.2.4  raeburn   268:             @roles = &course_roles('domain',undef,$custom,$roletype);
1.1       raeburn   269:         }
1.2       raeburn   270:         my $order = ['Any',@roles];
                    271:         $select_menus{$roletype}->{'order'} = $order; 
                    272:         foreach my $role (@roles) {
1.5       raeburn   273:             if ($role eq 'cr') {
                    274:                 $select_menus{$roletype}->{'select2'}->{$role} =
                    275:                               &mt('Custom role');
                    276:             } else {
                    277:                 $select_menus{$roletype}->{'select2'}->{$role} = 
1.97.2.5  raeburn   278:                               &Apache::lonnet::plaintext($role,$crstype);
1.5       raeburn   279:             }
1.2       raeburn   280:         }
                    281:         $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
1.1       raeburn   282:     }
1.2       raeburn   283:     my $result = &Apache::loncommon::linked_select_forms
                    284:         ('studentform',('&nbsp;'x3).&mt('Role: '),$env{'form.roletype'},
1.97.2.4  raeburn   285:          'roletype','showrole',\%select_menus,
                    286:          ['domain','author','course','community']);
1.1       raeburn   287:     return $result;
                    288: }
                    289: 
                    290: ###############################################################
                    291: ###############################################################
                    292: sub hidden_input {
                    293:     my ($name,$value) = @_;
                    294:     return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
                    295: }
                    296: 
                    297: sub print_upload_manager_header {
1.97.2.6  raeburn   298:     my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
1.1       raeburn   299:     my $javascript;
                    300:     #
                    301:     if (! exists($env{'form.upfile_associate'})) {
                    302:         $env{'form.upfile_associate'} = 'forward';
                    303:     }
                    304:     if ($env{'form.associate'} eq 'Reverse Association') {
                    305:         if ( $env{'form.upfile_associate'} ne 'reverse' ) {
                    306:             $env{'form.upfile_associate'} = 'reverse';
                    307:         } else {
                    308:             $env{'form.upfile_associate'} = 'forward';
                    309:         }
                    310:     }
                    311:     if ($env{'form.upfile_associate'} eq 'reverse') {
                    312:         $javascript=&upload_manager_javascript_reverse_associate();
                    313:     } else {
                    314:         $javascript=&upload_manager_javascript_forward_associate();
                    315:     }
                    316:     #
                    317:     # Deal with restored settings
                    318:     my $password_choice = '';
                    319:     if (exists($env{'form.ipwd_choice'}) &&
                    320:         $env{'form.ipwd_choice'} ne '') {
                    321:         # If a column was specified for password, assume it is for an
                    322:         # internal password.  This is a bug waiting to be filed (could be
                    323:         # local or krb auth instead of internal) but I do not have the
                    324:         # time to mess around with this now.
                    325:         $password_choice = 'int';
                    326:     }
                    327:     #
1.22      raeburn   328:     my $groupslist;
                    329:     if ($context eq 'course') {
                    330:         $groupslist = &get_groupslist();
                    331:     }
1.1       raeburn   332:     my $javascript_validations =
1.22      raeburn   333:         &javascript_validations('upload',$krbdefdom,$password_choice,undef,
                    334:                                 $env{'request.role.domain'},$context,
1.97.2.6  raeburn   335:                                 $groupslist,$crstype);
1.91      bisitz    336:     my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.95      bisitz    337:     $r->print('<p>'
                    338:              .&mt('Total number of records found in file: [_1]'
                    339:                  ,'<b>'.$distotal.'</b>')
                    340:              ."</p>\n");
1.1       raeburn   341:     $r->print('<div class="LC_left_float"><h3>'.
                    342:               &mt('Identify fields in uploaded list')."</h3>\n");
                    343:     $r->print(&mt('Enter as many fields as you can.<br /> The system will inform you and bring you back to this page, <br /> if the data selected are insufficient to add users.')."<br />\n");
                    344:     $r->print(&hidden_input('action','upload').
                    345:               &hidden_input('state','got_file').
                    346:               &hidden_input('associate','').
                    347:               &hidden_input('datatoken',$datatoken).
                    348:               &hidden_input('fileupload',$env{'form.fileupload'}).
                    349:               &hidden_input('upfiletype',$env{'form.upfiletype'}).
                    350:               &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
1.86      bisitz    351:     $r->print('<br /><label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
1.73      bisitz    352:               &mt('Ignore First Line').'</label><br />');
1.59      bisitz    353:     $r->print('<br /><input type="button" value="'.&mt('Reverse Association').'" '.
                    354:               'name="Reverse Association" '.
1.96      bisitz    355:               'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
1.1       raeburn   356:     $r->print("<br /><br />\n".
                    357:               '<script type="text/javascript" language="Javascript">'."\n".
1.96      bisitz    358:               '// <![CDATA['."\n".
                    359:               $javascript."\n".$javascript_validations."\n".
                    360:               '// ]]>'."\n".
                    361:               '</script>');
1.1       raeburn   362: }
                    363: 
                    364: ###############################################################
                    365: ###############################################################
                    366: sub javascript_validations {
1.22      raeburn   367:     my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
1.97.2.6  raeburn   368:         $context,$groupslist,$crstype)=@_;
1.22      raeburn   369:     my %param = (
                    370:                   kerb_def_dom => $krbdefdom,
                    371:                   curr_authtype => $curr_authtype,
                    372:                 );
1.37      raeburn   373:     if ($mode eq 'upload') {
1.22      raeburn   374:         $param{'formname'} = 'studentform';
1.1       raeburn   375:     } elsif ($mode eq 'createcourse') {
1.22      raeburn   376:         $param{'formname'} = 'ccrs';
1.1       raeburn   377:     } elsif ($mode eq 'modifycourse') {
1.22      raeburn   378:         $param{'formname'} = 'cmod';
                    379:         $param{'mode'} = 'modifycourse',
                    380:         $param{'curr_autharg'} = $curr_authfield;
                    381:     }
                    382: 
                    383:     my ($setsection_call,$setsections_js);
                    384:     my $finish = "  vf.submit();\n";
                    385:     if ($mode eq 'upload') {
                    386:         if (($context eq 'course') || ($context eq 'domain')) {
                    387:             if ($context eq 'course') {
                    388:                 if ($env{'request.course.sec'} eq '') {
1.97.2.11  raeburn   389:                     $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
1.22      raeburn   390:                     $setsections_js =
                    391:                         &setsections_javascript($param{'formname'},$groupslist,
1.97.2.6  raeburn   392:                                                 $mode,'',$crstype);
1.22      raeburn   393:                 } else {
                    394:                     $setsection_call = "'ok'";
                    395:                 }
                    396:             } elsif ($context eq 'domain') {
                    397:                 $setsection_call = 'setCourse()';
1.37      raeburn   398:                 $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context);
1.22      raeburn   399:             }
                    400:             $finish = "  var checkSec = $setsection_call\n".
                    401:                       "  if (checkSec == 'ok') {\n".
                    402:                       "      vf.submit();\n".
                    403:                       "   }\n";
                    404:         }
1.1       raeburn   405:     }
1.22      raeburn   406:     my $authheader = &Apache::loncommon::authform_header(%param);
1.1       raeburn   407: 
                    408:     my %alert = &Apache::lonlocal::texthash
                    409:         (username => 'You need to specify the username field.',
                    410:          authen   => 'You must choose an authentication type.',
                    411:          krb      => 'You need to specify the Kerberos domain.',
                    412:          ipass    => 'You need to specify the initial password.',
                    413:          name     => 'The optional name field was not specified.',
1.93      bisitz    414:          snum     => 'The optional student/employee ID field was not specified.',
1.1       raeburn   415:          section  => 'The optional section field was not specified.',
1.75      schafran  416:          email    => 'The optional e-mail address field was not specified.',
1.1       raeburn   417:          role     => 'The optional role field was not specified.',
1.57      raeburn   418:          domain   => 'The optional domain field was not specified.',
1.1       raeburn   419:          continue => 'Continue adding users?',
                    420:          );
1.84      raeburn   421:     if (($mode eq 'upload') && ($context eq 'domain')) {
                    422:         $alert{'inststatus'} = &mt('The optional affiliation field was not specified'); 
                    423:     }
1.37      raeburn   424:     my $function_name = <<"END";
1.22      raeburn   425: $setsections_js
                    426: 
1.84      raeburn   427: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus) {
1.1       raeburn   428: END
                    429:     my ($authnum,%can_assign) =  &Apache::loncommon::get_assignable_auth($domain);
                    430:     my $auth_checks;
                    431:     if ($mode eq 'createcourse') {
                    432:         $auth_checks .= (<<END);
                    433:     if (vf.autoadds[0].checked == true) {
                    434:         if (current.radiovalue == null || current.radiovalue == 'nochange') {
                    435:             alert('$alert{'authen'}');
                    436:             return;
                    437:         }
                    438:     }
                    439: END
                    440:     } else {
                    441:         $auth_checks .= (<<END);
                    442:     var foundatype=0;
                    443:     if (founduname==0) {
                    444:         alert('$alert{'username'}');
                    445:         return;
                    446:     }
                    447: 
                    448: END
                    449:         if ($authnum > 1) {
                    450:             $auth_checks .= (<<END);
                    451:     if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
                    452:         // They did not check any of the login radiobuttons.
                    453:         alert('$alert{'authen'}');
                    454:         return;
                    455:     }
                    456: END
                    457:         }
                    458:     }
                    459:     if ($mode eq 'createcourse') {
                    460:         $auth_checks .= "
                    461:     if ( (vf.autoadds[0].checked == true) &&
                    462:          (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
                    463: ";
                    464:     } elsif ($mode eq 'modifycourse') {
                    465:         $auth_checks .= "
                    466:     if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
                    467: ";
                    468:     }
                    469:     if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
                    470:         $auth_checks .= (<<END);
                    471:         var alertmsg = '';
                    472:         switch (current.radiovalue) {
                    473:             case 'krb':
                    474:                 alertmsg = '$alert{'krb'}';
                    475:                 break;
                    476:             default:
                    477:                 alertmsg = '';
                    478:         }
                    479:         if (alertmsg != '') {
                    480:             alert(alertmsg);
                    481:             return;
                    482:         }
                    483:     }
                    484: END
                    485:     } else {
                    486:         $auth_checks .= (<<END);
                    487:     foundatype=1;
                    488:     if (current.argfield == null || current.argfield == '') {
                    489:         var alertmsg = '';
1.38      raeburn   490:         switch (current.radiovalue) {
1.1       raeburn   491:             case 'krb':
                    492:                 alertmsg = '$alert{'krb'}';
                    493:                 break;
                    494:             case 'loc':
                    495:             case 'fsys':
                    496:                 alertmsg = '$alert{'ipass'}';
                    497:                 break;
                    498:             case 'fsys':
                    499:                 alertmsg = '';
                    500:                 break;
                    501:             default:
                    502:                 alertmsg = '';
                    503:         }
                    504:         if (alertmsg != '') {
                    505:             alert(alertmsg);
                    506:             return;
                    507:         }
                    508:     }
                    509: END
                    510:     }
                    511:     my $section_checks;
                    512:     my $optional_checks = '';
                    513:     if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
                    514:         $optional_checks = (<<END);
                    515:     vf.submit();
                    516: }
                    517: END
                    518:     } else {
                    519:         $section_checks = &section_check_js();
                    520:         $optional_checks = (<<END);
                    521:     var message='';
                    522:     if (foundname==0) {
                    523:         message='$alert{'name'}';
                    524:     }
                    525:     if (foundid==0) {
                    526:         if (message!='') {
                    527:             message+='\\n';
                    528:         }
                    529:         message+='$alert{'snum'}';
                    530:     }
                    531:     if (foundsec==0) {
                    532:         if (message!='') {
                    533:             message+='\\n';
                    534:         }
                    535:     }
                    536:     if (foundemail==0) {
                    537:         if (message!='') {
                    538:             message+='\\n';
                    539:         }
                    540:         message+='$alert{'email'}';
                    541:     }
1.57      raeburn   542:     if (foundrole==0) {
                    543:         if (message!='') {
                    544:             message+='\\n';
                    545:         }
                    546:         message+='$alert{'role'}';
                    547:     }
                    548:     if (founddomain==0) {
                    549:         if (message!='') {
                    550:             message+='\\n';
                    551:         }
                    552:         message+='$alert{'domain'}';
                    553:     }
1.84      raeburn   554: END
                    555:         if (($mode eq 'upload') && ($context eq 'domain')) {
                    556:             $optional_checks .= (<<END);
                    557: 
                    558:     if (foundinststatus==0) {
                    559:         if (message!='') {
                    560:             message+='\\n';
                    561:         }
                    562:         message+='$alert{'inststatus'}';
                    563:     }
                    564: END
                    565:         }
                    566:         $optional_checks .= (<<END);
                    567: 
1.1       raeburn   568:     if (message!='') {
                    569:         message+= '\\n$alert{'continue'}';
                    570:         if (confirm(message)) {
                    571:             vf.state.value='enrolling';
1.22      raeburn   572:             $finish
1.1       raeburn   573:         }
                    574:     } else {
                    575:         vf.state.value='enrolling';
1.22      raeburn   576:         $finish
1.1       raeburn   577:     }
                    578: }
                    579: END
                    580:     }
1.37      raeburn   581:     my $result = $function_name.$auth_checks.$optional_checks."\n".
                    582:                  $section_checks.$authheader;
1.1       raeburn   583:     return $result;
                    584: }
                    585: ###############################################################
                    586: ###############################################################
                    587: sub upload_manager_javascript_forward_associate {
                    588:     return(<<ENDPICK);
                    589: function verify(vf,sec_caller) {
                    590:     var founduname=0;
                    591:     var foundpwd=0;
                    592:     var foundname=0;
                    593:     var foundid=0;
                    594:     var foundsec=0;
                    595:     var foundemail=0;
                    596:     var foundrole=0;
1.57      raeburn   597:     var founddomain=0;
1.84      raeburn   598:     var foundinststatus=0;
1.1       raeburn   599:     var tw;
                    600:     for (i=0;i<=vf.nfields.value;i++) {
                    601:         tw=eval('vf.f'+i+'.selectedIndex');
                    602:         if (tw==1) { founduname=1; }
                    603:         if ((tw>=2) && (tw<=6)) { foundname=1; }
                    604:         if (tw==7) { foundid=1; }
                    605:         if (tw==8) { foundsec=1; }
                    606:         if (tw==9) { foundpwd=1; }
                    607:         if (tw==10) { foundemail=1; }
                    608:         if (tw==11) { foundrole=1; }
1.57      raeburn   609:         if (tw==12) { founddomain=1; }
1.84      raeburn   610:         if (tw==13) { foundinststatus=1; }
1.1       raeburn   611:     }
1.84      raeburn   612:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
1.1       raeburn   613: }
                    614: 
                    615: //
                    616: // vf = this.form
                    617: // tf = column number
                    618: //
                    619: // values of nw
                    620: //
                    621: // 0 = none
                    622: // 1 = username
                    623: // 2 = names (lastname, firstnames)
                    624: // 3 = fname (firstname)
                    625: // 4 = mname (middlename)
                    626: // 5 = lname (lastname)
                    627: // 6 = gen   (generation)
                    628: // 7 = id
                    629: // 8 = section
                    630: // 9 = ipwd  (password)
                    631: // 10 = email address
                    632: // 11 = role
1.57      raeburn   633: // 12 = domain
1.84      raeburn   634: // 13 = inststatus
1.1       raeburn   635: 
                    636: function flip(vf,tf) {
                    637:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    638:    var i;
                    639:    // make sure no other columns are labeled the same as this one
                    640:    for (i=0;i<=vf.nfields.value;i++) {
                    641:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                    642:           eval('vf.f'+i+'.selectedIndex=0;')
                    643:       }
                    644:    }
                    645:    // If we set this to 'lastname, firstnames', clear out all the ones
                    646:    // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
                    647:    if (nw==2) {
                    648:       for (i=0;i<=vf.nfields.value;i++) {
                    649:          if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
                    650:              (eval('vf.f'+i+'.selectedIndex')<=6)) {
                    651:              eval('vf.f'+i+'.selectedIndex=0;')
                    652:          }
                    653:       }
                    654:    }
                    655:    // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
                    656:    // clear out any that are set to 'lastname, firstnames' (2)
                    657:    if ((nw>=3) && (nw<=6)) {
                    658:       for (i=0;i<=vf.nfields.value;i++) {
                    659:          if (eval('vf.f'+i+'.selectedIndex')==2) {
                    660:              eval('vf.f'+i+'.selectedIndex=0;')
                    661:          }
                    662:       }
                    663:    }
                    664:    // If we set the password, make the password form below correspond to
                    665:    // the new value.
                    666:    if (nw==9) {
                    667:        changed_radio('int',document.studentform);
                    668:        set_auth_radio_buttons('int',document.studentform);
                    669:        vf.intarg.value='';
                    670:        vf.krbarg.value='';
                    671:        vf.locarg.value='';
                    672:    }
                    673: }
                    674: 
                    675: function clearpwd(vf) {
                    676:     var i;
                    677:     for (i=0;i<=vf.nfields.value;i++) {
                    678:         if (eval('vf.f'+i+'.selectedIndex')==9) {
                    679:             eval('vf.f'+i+'.selectedIndex=0;')
                    680:         }
                    681:     }
                    682: }
                    683: 
                    684: ENDPICK
                    685: }
                    686: 
                    687: ###############################################################
                    688: ###############################################################
                    689: sub upload_manager_javascript_reverse_associate {
                    690:     return(<<ENDPICK);
                    691: function verify(vf,sec_caller) {
                    692:     var founduname=0;
                    693:     var foundpwd=0;
                    694:     var foundname=0;
                    695:     var foundid=0;
                    696:     var foundsec=0;
                    697:     var foundrole=0;
1.57      raeburn   698:     var founddomain=0;
1.84      raeburn   699:     var foundinststatus=0;
1.1       raeburn   700:     var tw;
                    701:     for (i=0;i<=vf.nfields.value;i++) {
                    702:         tw=eval('vf.f'+i+'.selectedIndex');
                    703:         if (i==0 && tw!=0) { founduname=1; }
                    704:         if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
                    705:         if (i==6 && tw!=0) { foundid=1; }
                    706:         if (i==7 && tw!=0) { foundsec=1; }
                    707:         if (i==8 && tw!=0) { foundpwd=1; }
                    708:         if (i==9 && tw!=0) { foundrole=1; }
1.57      raeburn   709:         if (i==10 && tw!=0) { founddomain=1; }
1.84      raeburn   710:         if (i==13 && tw!=0) { foundinstatus=1; }
1.1       raeburn   711:     }
1.84      raeburn   712:     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole,founddomain,foundinststatus);
1.1       raeburn   713: }
                    714: 
                    715: function flip(vf,tf) {
                    716:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    717:    var i;
                    718:    // picked the all one name field, reset the other name ones to blank
                    719:    if (tf==1 && nw!=0) {
                    720:       for (i=2;i<=5;i++) {
                    721:          eval('vf.f'+i+'.selectedIndex=0;')
                    722:       }
                    723:    }
                    724:    //picked one of the piecewise name fields, reset the all in
                    725:    //one field to blank
                    726:    if ((tf>=2) && (tf<=5) && (nw!=0)) {
                    727:       eval('vf.f1.selectedIndex=0;')
                    728:    }
                    729:    // intial password specified, pick internal authentication
                    730:    if (tf==8 && nw!=0) {
                    731:        changed_radio('int',document.studentform);
                    732:        set_auth_radio_buttons('int',document.studentform);
                    733:        vf.krbarg.value='';
                    734:        vf.intarg.value='';
                    735:        vf.locarg.value='';
                    736:    }
                    737: }
                    738: 
                    739: function clearpwd(vf) {
                    740:     var i;
                    741:     if (eval('vf.f8.selectedIndex')!=0) {
                    742:         eval('vf.f8.selectedIndex=0;')
                    743:     }
                    744: }
                    745: ENDPICK
                    746: }
                    747: 
                    748: ###############################################################
                    749: ###############################################################
                    750: sub print_upload_manager_footer {
1.97.2.4  raeburn   751:     my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype) = @_;
1.22      raeburn   752:     my $form = 'document.studentform';
                    753:     my $formname = 'studentform';
1.1       raeburn   754:     my ($krbdef,$krbdefdom) =
                    755:         &Apache::loncommon::get_kerberos_defaults($defdom);
1.22      raeburn   756:     my %param = ( formname => $form,
1.1       raeburn   757:                   kerb_def_dom => $krbdefdom,
                    758:                   kerb_def_auth => $krbdef
                    759:                   );
                    760:     if (exists($env{'form.ipwd_choice'}) &&
                    761:         defined($env{'form.ipwd_choice'}) &&
                    762:         $env{'form.ipwd_choice'} ne '') {
                    763:         $param{'curr_authtype'} = 'int';
                    764:     }
                    765:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    766:     my $intform = &Apache::loncommon::authform_internal(%param);
                    767:     my $locform = &Apache::loncommon::authform_local(%param);
1.22      raeburn   768:     my $date_table = &date_setting_table(undef,undef,$context,undef,
1.97.2.4  raeburn   769:                                          $formname,$permission,$crstype);
1.95      bisitz    770: 
1.1       raeburn   771:     my $Str = "\n".'<div class="LC_left_float">';
                    772:     $Str .= &hidden_input('nfields',$i);
                    773:     $Str .= &hidden_input('keyfields',$keyfields);
1.95      bisitz    774: 
                    775:     $Str .= '<h3>'.&mt('Options').'</h3>'
                    776:            .&Apache::lonhtmlcommon::start_pick_box();
                    777: 
                    778:     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
1.1       raeburn   779:     if ($context eq 'domain') {
1.95      bisitz    780:         $Str .= '<p>'
                    781:                .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
                    782:                    ,$defdom)
                    783:                .'&nbsp;<span class="LC_nobreak"><label>'
                    784:                .'<input type="radio" name="changeauth" value="No" checked="checked" />'
                    785:                .&mt('No').'</label>'
                    786:                .'&nbsp;&nbsp;<label>'
                    787:                .'<input type="radio" name="changeauth" value="Yes" />'
                    788:                .&mt('Yes').'</label>'
                    789:                .'</span></p>'; 
1.1       raeburn   790:     } else {
1.95      bisitz    791:         $Str .= '<p class="LC_info">'."\n".
                    792:             &mt('This will not take effect if the user already exists.').
1.1       raeburn   793:             &Apache::loncommon::help_open_topic('Auth_Options').
                    794:             "</p>\n";
                    795:     }
1.97      raeburn   796:     $Str .= &set_login($defdom,$krbform,$intform,$locform);
1.95      bisitz    797: 
1.1       raeburn   798:     my ($home_server_pick,$numlib) =
                    799:         &Apache::loncommon::home_server_form_item($defdom,'lcserver',
                    800:                                                   'default','hide');
                    801:     if ($numlib > 1) {
1.97      raeburn   802:         $Str .= &Apache::lonhtmlcommon::row_closure()
                    803:                .&Apache::lonhtmlcommon::row_title(
1.95      bisitz    804:                     &mt('LON-CAPA Home Server for New Users'))
                    805:                .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
                    806:                .$home_server_pick
                    807:                .&Apache::lonhtmlcommon::row_closure();
                    808:     } else {
1.97      raeburn   809:         $Str .= $home_server_pick.
                    810:                 &Apache::lonhtmlcommon::row_closure();
1.95      bisitz    811:     }
                    812: 
                    813:     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
                    814:            .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
                    815:            .&Apache::lonhtmlcommon::row_closure();
                    816: 
                    817:     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
                    818:            ."<p>\n".$date_table."</p>\n"
                    819:            .&Apache::lonhtmlcommon::row_closure();
                    820: 
1.1       raeburn   821:     if ($context eq 'domain') {
1.95      bisitz    822:         $Str .= &Apache::lonhtmlcommon::row_title(
                    823:                     &mt('Settings for assigning roles'))
                    824:                .&mt('Pick the action to take on roles for these users:').'<br />'
                    825:                .'<span class="LC_nobreak"><label>'
                    826:                .'<input type="radio" name="roleaction" value="norole" checked="checked" />'
                    827:                .'&nbsp;'.&mt('No role changes').'</label>'
                    828:                .'&nbsp;&nbsp;&nbsp;<label>'
                    829:                .'<input type="radio" name="roleaction" value="domain" />'
                    830:                .'&nbsp;'.&mt('Add a domain role').'</label>'
                    831:                .'&nbsp;&nbsp;&nbsp;<label>'
                    832:                .'<input type="radio" name="roleaction" value="course" />'
1.97.2.6  raeburn   833:                .'&nbsp;'.&mt('Add a course/community role').'</label>'
1.95      bisitz    834:                .'</span>';
                    835:     } elsif ($context eq 'author') {
                    836:         $Str .= &Apache::lonhtmlcommon::row_title(
                    837:                     &mt('Default role'))
                    838:                .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
1.1       raeburn   839:     } elsif ($context eq 'course') {
1.95      bisitz    840:         $Str .= &Apache::lonhtmlcommon::row_title(
                    841:                     &mt('Default role and section'))
                    842:                .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
                    843:     } else {
                    844:         $Str .= &Apache::lonhtmlcommon::row_title(
                    845:                     &mt('Default role and/or section(s)'))
                    846:                .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
1.1       raeburn   847:     }
1.22      raeburn   848:     if (($context eq 'domain') || ($context eq 'author')) {
1.95      bisitz    849:         $Str .= '<br />';
1.22      raeburn   850:         my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
                    851:         if ($context eq 'domain') {
1.95      bisitz    852:             $Str .= '<p>'
                    853:                    .'<b>'.&mt('Domain Level').'</b><br />'
                    854:                    .$options
                    855:                    .'</p><p>'
                    856:                    .'<b>'.&mt('Course Level').'</b>'
                    857:                    .'</p>'
                    858:                    .$cb_script.$coursepick
                    859:                    .&Apache::lonhtmlcommon::row_closure();
1.22      raeburn   860:         } elsif ($context eq 'author') {
1.95      bisitz    861:             $Str .= $options
                    862:                    .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.22      raeburn   863:         }
1.1       raeburn   864:     } else {
1.22      raeburn   865:         my ($cnum,$cdom) = &get_course_identity();
                    866:         my $rowtitle = &mt('section');
                    867:         my $secbox = &section_picker($cdom,$cnum,'Any',$rowtitle,
1.97.2.4  raeburn   868:                                      $permission,$context,'upload',$crstype);
1.95      bisitz    869:         $Str .= $secbox
                    870:                .&Apache::lonhtmlcommon::row_closure();
1.97.2.4  raeburn   871:         my %lt;
                    872:         if ($crstype eq 'Community') {
                    873:             %lt = &Apache::lonlocal::texthash (
                    874:                     disp => 'Display members with current/future access who are not in the uploaded file',
                    875:                     stus => 'Members selected from this list can be dropped.'
                    876:             );
                    877:         } else {
                    878:             %lt = &Apache::lonlocal::texthash (
                    879:                     disp => 'Display students with current/future access who are not in the uploaded file',
                    880:                     stus => 'Students selected from this list can be dropped.'
                    881:             );
                    882:         }
1.95      bisitz    883:         $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
1.97.2.4  raeburn   884:                .'<label><input type="checkbox" name="fullup" value="yes" />'
                    885:                .' '.$lt{'disp'}
1.95      bisitz    886:                .'</label><br />'
1.97.2.4  raeburn   887:                .$lt{'stus'}
1.95      bisitz    888:                .&Apache::lonhtmlcommon::row_closure();
1.1       raeburn   889:     }
1.5       raeburn   890:     if ($context eq 'course' || $context eq 'domain') {
                    891:         $Str .= &forceid_change($context);
                    892:     }
1.95      bisitz    893: 
                    894:     $Str .= &Apache::lonhtmlcommon::end_pick_box();
1.73      bisitz    895:     $Str .= '</div>';
1.95      bisitz    896: 
                    897:     # Footer
                    898:     $Str .= '<div class="LC_clear_float_footer">'
                    899:            .'<hr />';
1.1       raeburn   900:     if ($context eq 'course') {
1.95      bisitz    901:         $Str .= '<p class="LC_info">'
1.97.2.6  raeburn   902:                .&mt('Note: This operation may be time consuming when adding several users.')
1.95      bisitz    903:                .'</p>';
1.73      bisitz    904:     }
1.95      bisitz    905:     $Str .= '<p><input type="button"'
1.96      bisitz    906:            .' onclick="javascript:verify(this.form,this.form.csec)"'
                    907:            .' value="'.&mt('Update Users').'" />'
1.95      bisitz    908:            .'</p>'."\n"
1.73      bisitz    909:            .'</div>';
1.1       raeburn   910:     $r->print($Str);
                    911:     return;
                    912: }
                    913: 
1.5       raeburn   914: sub forceid_change {
                    915:     my ($context) = @_;
                    916:     my $output = 
1.95      bisitz    917:         &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
                    918:        .'<label><input type="checkbox" name="forceid" value="yes" />'
                    919:        .&mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs')
                    920:        .'</label><br />'."\n"
                    921:        .&mt('(only do if you know what you are doing.)')."\n";
1.5       raeburn   922:     if ($context eq 'domain') {
1.25      raeburn   923:         $output .= '<br /><label><input type="checkbox" name="recurseid"'.
1.86      bisitz    924:                    ' value="yes" />'. 
1.93      bisitz    925:   &mt('Update student/employee ID in courses in which user is active/future student,[_1](if forcing change).','<br />').
1.25      raeburn   926:                    '</label>'."\n";
1.5       raeburn   927:     }
1.95      bisitz    928:     $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
1.5       raeburn   929:     return $output;
                    930: }
                    931: 
1.1       raeburn   932: ###############################################################
                    933: ###############################################################
                    934: sub print_upload_manager_form {
1.97.2.4  raeburn   935:     my ($r,$context,$permission,$crstype) = @_;
1.1       raeburn   936:     my $firstLine;
                    937:     my $datatoken;
                    938:     if (!$env{'form.datatoken'}) {
                    939:         $datatoken=&Apache::loncommon::upfile_store($r);
                    940:     } else {
                    941:         $datatoken=$env{'form.datatoken'};
                    942:         &Apache::loncommon::load_tmp_file($r);
                    943:     }
                    944:     my @records=&Apache::loncommon::upfile_record_sep();
                    945:     if($env{'form.noFirstLine'}){
                    946:         $firstLine=shift(@records);
                    947:     }
                    948:     my $total=$#records;
                    949:     my $distotal=$total+1;
                    950:     my $today=time;
                    951:     my $halfyear=$today+15552000;
                    952:     #
                    953:     # Restore memorized settings
                    954:     my $col_setting_names =  { 'username_choice' => 'scalar', # column settings
                    955:                                'names_choice' => 'scalar',
                    956:                                'fname_choice' => 'scalar',
                    957:                                'mname_choice' => 'scalar',
                    958:                                'lname_choice' => 'scalar',
                    959:                                'gen_choice' => 'scalar',
                    960:                                'id_choice' => 'scalar',
                    961:                                'sec_choice' => 'scalar',
                    962:                                'ipwd_choice' => 'scalar',
                    963:                                'email_choice' => 'scalar',
                    964:                                'role_choice' => 'scalar',
1.57      raeburn   965:                                'domain_choice' => 'scalar',
1.84      raeburn   966:                                'inststatus_choice' => 'scalar',
1.1       raeburn   967:                              };
                    968:     my $defdom = $env{'request.role.domain'};
                    969:     if ($context eq 'course') {
                    970:         &Apache::loncommon::restore_course_settings('enrollment_upload',
                    971:                                                     $col_setting_names);
                    972:     } else {
                    973:         &Apache::loncommon::restore_settings($context,'user_upload',
                    974:                                              $col_setting_names);
                    975:     }
                    976:     #
                    977:     # Determine kerberos parameters as appropriate
                    978:     my ($krbdef,$krbdefdom) =
                    979:         &Apache::loncommon::get_kerberos_defaults($defdom);
                    980:     #
1.22      raeburn   981:     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
1.97.2.6  raeburn   982:                                  $permission,$crstype);
1.1       raeburn   983:     my $i;
                    984:     my $keyfields;
                    985:     if ($total>=0) {
                    986:         my @field=
                    987:             (['username',&mt('Username'),     $env{'form.username_choice'}],
                    988:              ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
                    989:              ['fname',&mt('First Name'),      $env{'form.fname_choice'}],
                    990:              ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
                    991:              ['lname',&mt('Last Name'),       $env{'form.lname_choice'}],
                    992:              ['gen',  &mt('Generation'),      $env{'form.gen_choice'}],
1.61      bisitz    993:              ['id',   &mt('Student/Employee ID'),$env{'form.id_choice'}],
1.1       raeburn   994:              ['sec',  &mt('Section'),          $env{'form.sec_choice'}],
                    995:              ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
                    996:              ['email',&mt('E-mail Address'),   $env{'form.email_choice'}],
1.57      raeburn   997:              ['role',&mt('Role'),             $env{'form.role_choice'}],
1.84      raeburn   998:              ['domain',&mt('Domain'),         $env{'form.domain_choice'}],
                    999:              ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
1.1       raeburn  1000:         if ($env{'form.upfile_associate'} eq 'reverse') {
                   1001:             &Apache::loncommon::csv_print_samples($r,\@records);
                   1002:             $i=&Apache::loncommon::csv_print_select_table($r,\@records,
                   1003:                                                           \@field);
                   1004:             foreach (@field) {
                   1005:                 $keyfields.=$_->[0].',';
                   1006:             }
                   1007:             chop($keyfields);
                   1008:         } else {
                   1009:             unshift(@field,['none','']);
                   1010:             $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
                   1011:                                                             \@field);
                   1012:             my %sone=&Apache::loncommon::record_sep($records[0]);
                   1013:             $keyfields=join(',',sort(keys(%sone)));
                   1014:         }
                   1015:     }
                   1016:     $r->print('</div>');
                   1017:     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
1.97.2.4  raeburn  1018:                                  $context,$permission,$crstype);
1.1       raeburn  1019: }
                   1020: 
                   1021: sub setup_date_selectors {
1.22      raeburn  1022:     my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
                   1023:     if ($formname eq '') {
                   1024:         $formname = 'studentform';
                   1025:     }
1.1       raeburn  1026:     if (! defined($starttime)) {
                   1027:         $starttime = time;
                   1028:         unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
                   1029:             if (exists($env{'course.'.$env{'request.course.id'}.
                   1030:                             '.default_enrollment_start_date'})) {
                   1031:                 $starttime = $env{'course.'.$env{'request.course.id'}.
                   1032:                                   '.default_enrollment_start_date'};
                   1033:             }
                   1034:         }
                   1035:     }
                   1036:     if (! defined($endtime)) {
                   1037:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                   1038:         unless ($mode eq 'createcourse') {
                   1039:             if (exists($env{'course.'.$env{'request.course.id'}.
                   1040:                             '.default_enrollment_end_date'})) {
                   1041:                 $endtime = $env{'course.'.$env{'request.course.id'}.
                   1042:                                 '.default_enrollment_end_date'};
                   1043:             }
                   1044:         }
                   1045:     }
1.11      raeburn  1046: 
                   1047:     my $startdateform = 
1.22      raeburn  1048:         &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
1.11      raeburn  1049:             undef,undef,undef,undef,undef,undef,undef,$nolink);
                   1050: 
                   1051:     my $enddateform = 
1.22      raeburn  1052:         &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
1.11      raeburn  1053:             undef,undef,undef,undef,undef,undef,undef,$nolink);
                   1054: 
1.1       raeburn  1055:     if ($mode eq 'create_enrolldates') {
                   1056:         $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
                   1057:                                                             'startenroll',
                   1058:                                                             $starttime);
                   1059:         $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
                   1060:                                                           'endenroll',
                   1061:                                                           $endtime);
                   1062:     }
                   1063:     if ($mode eq 'create_defaultdates') {
                   1064:         $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
                   1065:                                                             'startaccess',
                   1066:                                                             $starttime);
                   1067:         $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
                   1068:                                                           'endaccess',
                   1069:                                                           $endtime);
                   1070:     }
                   1071:     return ($startdateform,$enddateform);
                   1072: }
                   1073: 
                   1074: 
                   1075: sub get_dates_from_form {
1.54      raeburn  1076:     my ($startname,$endname) = @_;
                   1077:     if ($startname eq '') {
                   1078:         $startname = 'startdate';
                   1079:     }
                   1080:     if ($endname eq '') {
                   1081:         $endname = 'enddate';
                   1082:     }
                   1083:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
                   1084:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.1       raeburn  1085:     if ($env{'form.no_end_date'}) {
                   1086:         $enddate = 0;
                   1087:     }
                   1088:     return ($startdate,$enddate);
                   1089: }
                   1090: 
                   1091: sub date_setting_table {
1.97.2.4  raeburn  1092:     my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
1.11      raeburn  1093:     my $nolink;
                   1094:     if ($bulkaction) {
                   1095:         $nolink = 1;
                   1096:     }
                   1097:     my ($startform,$endform) = 
1.22      raeburn  1098:         &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
1.1       raeburn  1099:     my $dateDefault;
                   1100:     if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
                   1101:         $dateDefault = '&nbsp;';
1.13      raeburn  1102:     } elsif ($mode ne 'author' && $mode ne 'domain') {
1.11      raeburn  1103:         if (($bulkaction eq 'reenable') || 
                   1104:             ($bulkaction eq 'activate') || 
1.22      raeburn  1105:             ($bulkaction eq 'chgdates') ||
                   1106:             ($env{'form.action'} eq 'upload')) {
                   1107:             if ($env{'request.course.sec'} eq '') {
                   1108:                 $dateDefault = '<span class="LC_nobreak">'.
1.97.2.4  raeburn  1109:                     '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
                   1110:                 if ($crstype eq 'Community') {
                   1111:                     $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
                   1112:                 } else {
                   1113:                     $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
                   1114:                 }
                   1115:                 $dateDefault .= '</label></span>';
1.22      raeburn  1116:             }
1.11      raeburn  1117:         }
1.1       raeburn  1118:     }
1.11      raeburn  1119:     my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.1       raeburn  1120:     if (defined($endtime) && $endtime == 0) {
1.70      bisitz   1121:         $perpetual .= ' checked="checked"';
1.1       raeburn  1122:     }
1.11      raeburn  1123:     $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
1.1       raeburn  1124:     if ($mode eq 'create_enrolldates') {
                   1125:         $perpetual = '&nbsp;';
                   1126:     }
1.11      raeburn  1127:     my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
                   1128:     $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
                   1129:                                                      'LC_oddrow_value')."\n".
                   1130:                $startform."\n".
                   1131:                &Apache::lonhtmlcommon::row_closure(1).
                   1132:                &Apache::lonhtmlcommon::row_title(&mt('Ending Date'), 
                   1133:                                                      'LC_oddrow_value')."\n".
                   1134:                $endform.'&nbsp;'.$perpetual.
                   1135:                &Apache::lonhtmlcommon::row_closure(1).
1.22      raeburn  1136:                &Apache::lonhtmlcommon::end_pick_box();
1.1       raeburn  1137:     if ($dateDefault) {
                   1138:         $result .=  $dateDefault.'<br />'."\n";
                   1139:     }
                   1140:     return $result;
                   1141: }
                   1142: 
                   1143: sub make_dates_default {
1.97.2.14! raeburn  1144:     my ($startdate,$enddate,$context,$crstype) = @_;
1.1       raeburn  1145:     my $result = '';
                   1146:     if ($context eq 'course') {
1.17      raeburn  1147:         my ($cnum,$cdom) = &get_course_identity();
1.1       raeburn  1148:         my $put_result = &Apache::lonnet::put('environment',
                   1149:                 {'default_enrollment_start_date'=>$startdate,
1.17      raeburn  1150:                  'default_enrollment_end_date'  =>$enddate},$cdom,$cnum);
1.1       raeburn  1151:         if ($put_result eq 'ok') {
1.97.2.4  raeburn  1152:             if ($crstype eq 'Community') {
                   1153:                 $result .= &mt('Set default start and end access dates for community.');
                   1154:             } else {
                   1155:                 $result .= &mt('Set default start and end access dates for course.');
                   1156:             }
                   1157:             $result .= '<br />'."\n";
1.1       raeburn  1158:             #
                   1159:             # Refresh the course environment
                   1160:             &Apache::lonnet::coursedescription($env{'request.course.id'},
                   1161:                                                {'freshen_cache' => 1});
                   1162:         } else {
1.97.2.4  raeburn  1163:             if ($crstype eq 'Community') {
                   1164:                 $result .= &mt('Unable to set default access dates for community');
                   1165:             } else {
                   1166:                 $result .= &mt('Unable to set default access dates for course');
                   1167:             }
                   1168:             $result .= ':'.$put_result.'<br />';
1.1       raeburn  1169:         }
                   1170:     }
                   1171:     return $result;
                   1172: }
                   1173: 
                   1174: sub default_role_selector {
1.97.2.4  raeburn  1175:     my ($context,$checkpriv,$crstype) = @_;
1.1       raeburn  1176:     my %customroles;
                   1177:     my ($options,$coursepick,$cb_jscript);
1.13      raeburn  1178:     if ($context ne 'author') {
1.97.2.7  raeburn  1179:         %customroles = &my_custom_roles($crstype);
1.1       raeburn  1180:     }
                   1181: 
                   1182:     my %lt=&Apache::lonlocal::texthash(
                   1183:                     'rol'  => "Role",
                   1184:                     'grs'  => "Section",
                   1185:                     'exs'  => "Existing sections",
                   1186:                     'new'  => "New section",
                   1187:                   );
                   1188:     $options = '<select name="defaultrole">'."\n".
                   1189:                ' <option value="">'.&mt('Please select').'</option>'."\n"; 
                   1190:     if ($context eq 'course') {
1.97.2.4  raeburn  1191:         $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
1.13      raeburn  1192:     } elsif ($context eq 'author') {
1.2       raeburn  1193:         my @roles = &construction_space_roles($checkpriv);
1.1       raeburn  1194:         foreach my $role (@roles) {
                   1195:            my $plrole=&Apache::lonnet::plaintext($role);
                   1196:            $options .= '  <option value="'.$role.'">'.$plrole.'</option>'."\n";
                   1197:         }
                   1198:     } elsif ($context eq 'domain') {
1.2       raeburn  1199:         my @roles = &domain_roles($checkpriv);
1.1       raeburn  1200:         foreach my $role (@roles) {
                   1201:            my $plrole=&Apache::lonnet::plaintext($role);
                   1202:            $options .= '  <option value="'.$role.'">'.$plrole.'</option>';
                   1203:         }
                   1204:         my $courseform = &Apache::loncommon::selectcourse_link
1.97.2.6  raeburn  1205:             ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
1.1       raeburn  1206:         $cb_jscript = 
1.97.2.6  raeburn  1207:             &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community');
1.1       raeburn  1208:         $coursepick = &Apache::loncommon::start_data_table().
                   1209:                       &Apache::loncommon::start_data_table_header_row().
                   1210:                       '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
                   1211:                       '<th>'.$lt{'grs'}.'</th>'.
                   1212:                       &Apache::loncommon::end_data_table_header_row().
                   1213:                       &Apache::loncommon::start_data_table_row()."\n".
1.97.2.6  raeburn  1214:                       '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
1.1       raeburn  1215:                       '<td><select name="courserole">'."\n".
1.97.2.4  raeburn  1216:                       &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
1.1       raeburn  1217:                       '</select></td><td>'.
                   1218:                       '<table class="LC_createuser">'.
                   1219:                       '<tr class="LC_section_row"><td valign"top">'.
1.22      raeburn  1220:                       $lt{'exs'}.'<br /><select name="currsec">'.
1.1       raeburn  1221:                       ' <option value=""><--'.&mt('Pick course first').
                   1222:                       '</select></td>'.
                   1223:                       '<td>&nbsp;&nbsp;</td>'.
                   1224:                       '<td valign="top">'.$lt{'new'}.'<br />'.
                   1225:                       '<input type="text" name="newsec" value="" size="5" />'.
1.22      raeburn  1226:                       '<input type="hidden" name="groups" value="" />'.
                   1227:                       '<input type="hidden" name="sections" value="" />'.
                   1228:                       '<input type="hidden" name="origdom" value="'.
                   1229:                       $env{'request.role.domain'}.'" />'.
                   1230:                       '<input type="hidden" name="dccourse" value="" />'.
                   1231:                       '<input type="hidden" name="dcdomain" value="" />'.
1.97.2.6  raeburn  1232:                       '<input type="hidden" name="crstype" value="" />'.
1.22      raeburn  1233:                       '</td></tr></table></td>'.
1.1       raeburn  1234:                       &Apache::loncommon::end_data_table_row().
1.22      raeburn  1235:                       &Apache::loncommon::end_data_table()."\n";
1.1       raeburn  1236:     }
                   1237:     $options .= '</select>';
                   1238:     return ($options,$cb_jscript,$coursepick);
                   1239: }
                   1240: 
                   1241: sub default_course_roles {
1.97.2.4  raeburn  1242:     my ($context,$checkpriv,$crstype,%customroles) = @_;
1.1       raeburn  1243:     my $output;
1.17      raeburn  1244:     my $custom = 1;
1.97.2.4  raeburn  1245:     my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
1.1       raeburn  1246:     foreach my $role (@roles) {
1.22      raeburn  1247:         if ($role ne 'cr') {
1.97.2.4  raeburn  1248:             my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.22      raeburn  1249:             $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
                   1250:         }
1.1       raeburn  1251:     }
                   1252:     if (keys(%customroles) > 0) {
1.22      raeburn  1253:         if (grep(/^cr$/,@roles)) {
                   1254:             foreach my $cust (sort(keys(%customroles))) {
                   1255:                 my $custrole='cr_'.$env{'user.domain'}.
                   1256:                              '_'.$env{'user.name'}.'_'.$cust;
                   1257:                 $output .= '  <option value="'.$custrole.'">'.$cust.'</option>';
                   1258:             }
1.1       raeburn  1259:         }
                   1260:     }
                   1261:     return $output;
                   1262: }
                   1263: 
                   1264: sub construction_space_roles {
1.2       raeburn  1265:     my ($checkpriv) = @_;
1.17      raeburn  1266:     my @allroles = &roles_by_context('author');
1.1       raeburn  1267:     my @roles;
1.2       raeburn  1268:     if ($checkpriv) {
                   1269:         foreach my $role (@allroles) {
                   1270:             if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) { 
                   1271:                 push(@roles,$role); 
                   1272:             }
1.1       raeburn  1273:         }
1.2       raeburn  1274:         return @roles;
                   1275:     } else {
                   1276:         return @allroles;
1.1       raeburn  1277:     }
                   1278: }
                   1279: 
                   1280: sub domain_roles {
1.2       raeburn  1281:     my ($checkpriv) = @_;
1.17      raeburn  1282:     my @allroles = &roles_by_context('domain');
1.1       raeburn  1283:     my @roles;
1.2       raeburn  1284:     if ($checkpriv) {
                   1285:         foreach my $role (@allroles) {
                   1286:             if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
                   1287:                 push(@roles,$role);
                   1288:             }
1.1       raeburn  1289:         }
1.2       raeburn  1290:         return @roles;
                   1291:     } else {
                   1292:         return @allroles;
1.1       raeburn  1293:     }
                   1294: }
                   1295: 
                   1296: sub course_roles {
1.97.2.4  raeburn  1297:     my ($context,$checkpriv,$custom,$roletype) = @_;
1.97.2.5  raeburn  1298:     my $crstype;
                   1299:     if ($roletype eq 'community') {
                   1300:         $crstype = 'Community' ;
                   1301:     } else {
                   1302:         $crstype = 'Course';
                   1303:     }
                   1304:     my @allroles = &roles_by_context('course',$custom,$crstype);
1.1       raeburn  1305:     my @roles;
                   1306:     if ($context eq 'domain') {
                   1307:         @roles = @allroles;
                   1308:     } elsif ($context eq 'course') {
                   1309:         if ($env{'request.course.id'}) {
1.2       raeburn  1310:             if ($checkpriv) { 
                   1311:                 foreach my $role (@allroles) {
                   1312:                     if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
                   1313:                         push(@roles,$role);
                   1314:                     } else {
1.97.2.4  raeburn  1315:                         if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
1.22      raeburn  1316:                             if (&Apache::lonnet::allowed('c'.$role,
1.2       raeburn  1317:                                              $env{'request.course.id'}.'/'.
1.22      raeburn  1318:                                              $env{'request.course.sec'})) {
1.2       raeburn  1319:                                 push(@roles,$role);
                   1320:                             }
1.1       raeburn  1321:                         }
                   1322:                     }
                   1323:                 }
1.2       raeburn  1324:             } else {
                   1325:                 @roles = @allroles;
1.1       raeburn  1326:             }
                   1327:         }
                   1328:     }
                   1329:     return @roles;
                   1330: }
                   1331: 
                   1332: sub curr_role_permissions {
1.97.2.4  raeburn  1333:     my ($context,$setting,$checkpriv,$type) = @_; 
1.17      raeburn  1334:     my $custom = 1;
1.1       raeburn  1335:     my @roles;
1.13      raeburn  1336:     if ($context eq 'author') {
1.2       raeburn  1337:         @roles = &construction_space_roles($checkpriv);
1.1       raeburn  1338:     } elsif ($context eq 'domain') {
                   1339:         if ($setting eq 'course') {
1.97.2.4  raeburn  1340:             @roles = &course_roles($context,$checkpriv,$custom,$type); 
1.1       raeburn  1341:         } else {
1.2       raeburn  1342:             @roles = &domain_roles($checkpriv);
1.1       raeburn  1343:         }
                   1344:     } elsif ($context eq 'course') {
1.97.2.4  raeburn  1345:         @roles = &course_roles($context,$checkpriv,$custom,$type);
1.1       raeburn  1346:     }
                   1347:     return @roles;
                   1348: }
                   1349: 
                   1350: # ======================================================= Existing Custom Roles
                   1351: 
                   1352: sub my_custom_roles {
1.97.2.7  raeburn  1353:     my ($crstype) = @_;
1.1       raeburn  1354:     my %returnhash=();
                   1355:     my %rolehash=&Apache::lonnet::dump('roles');
1.97.2.7  raeburn  1356:     foreach my $key (keys(%rolehash)) {
1.1       raeburn  1357:         if ($key=~/^rolesdef\_(\w+)$/) {
1.97.2.7  raeburn  1358:             if ($crstype eq 'Community') {
                   1359:                 next if ($rolehash{$key} =~ /bre\&S/); 
                   1360:             }
1.1       raeburn  1361:             $returnhash{$1}=$1;
                   1362:         }
                   1363:     }
                   1364:     return %returnhash;
                   1365: }
                   1366: 
1.2       raeburn  1367: sub print_userlist {
                   1368:     my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
                   1369:         $idlist,$idlist_titles) = @_;
                   1370:     my $format = $env{'form.output'};
1.1       raeburn  1371:     if (! exists($env{'form.sortby'})) {
                   1372:         $env{'form.sortby'} = 'username';
                   1373:     }
1.2       raeburn  1374:     if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
                   1375:         $env{'form.Status'} = 'Active';
1.1       raeburn  1376:     }
                   1377:     my $status_select = &Apache::lonhtmlcommon::StatusOptions
1.2       raeburn  1378:         ($env{'form.Status'});
1.1       raeburn  1379: 
1.2       raeburn  1380:     if ($env{'form.showrole'} eq '') {
1.13      raeburn  1381:         if ($context eq 'course') {
                   1382:             $env{'form.showrole'} = 'st';
                   1383:         } else {
                   1384:             $env{'form.showrole'} = 'Any';            
                   1385:         }
1.2       raeburn  1386:     }
1.1       raeburn  1387:     if (! defined($env{'form.output'}) ||
                   1388:         $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
                   1389:         $env{'form.output'} = 'html';
                   1390:     }
                   1391: 
1.2       raeburn  1392:     my @statuses;
                   1393:     if ($env{'form.Status'} eq 'Any') {
                   1394:         @statuses = ('previous','active','future');
                   1395:     } elsif ($env{'form.Status'} eq 'Expired') {
                   1396:         @statuses = ('previous');
                   1397:     } elsif ($env{'form.Status'} eq 'Active') {
                   1398:         @statuses = ('active');
                   1399:     } elsif ($env{'form.Status'} eq 'Future') {
                   1400:         @statuses = ('future');
                   1401:     }
1.1       raeburn  1402: 
1.2       raeburn  1403: #    if ($context eq 'course') { 
                   1404: #        $r->print(&display_adv_courseroles());
                   1405: #    }
1.1       raeburn  1406:     #
                   1407:     # Interface output
1.2       raeburn  1408:     $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
                   1409:               '<input type="hidden" name="action" value="'.
1.1       raeburn  1410:               $env{'form.action'}.'" />');
                   1411:     $r->print("<p>\n");
                   1412:     if ($env{'form.action'} ne 'modifystudent') {
                   1413:         my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
                   1414:                                            'excel' => "Excel",
                   1415:                                            'html'  => 'HTML');
                   1416:         my $output_selector = '<select size="1" name="output" >';
                   1417:         foreach my $outputformat ('html','csv','excel') {
1.96      bisitz   1418:             my $option = '<option value="'.$outputformat.'"';
1.1       raeburn  1419:             if ($outputformat eq $env{'form.output'}) {
1.96      bisitz   1420:                 $option .= ' selected="selected"';
1.1       raeburn  1421:             }
                   1422:             $option .='>'.$lt{$outputformat}.'</option>';
                   1423:             $output_selector .= "\n".$option;
                   1424:         }
                   1425:         $output_selector .= '</select>';
1.70      bisitz   1426:         $r->print('<label><span class="LC_nobreak">'
                   1427:                  .&mt('Output Format: [_1]',$output_selector)
                   1428:                  .'</span></label>'.('&nbsp;'x3));
                   1429:     }
                   1430:     $r->print('<label><span class="LC_nobreak">'
                   1431:              .&mt('User Status: [_1]',$status_select)
                   1432:              .'</span></label>'.('&nbsp;'x3)."\n");
1.2       raeburn  1433:     my $roleselected = '';
                   1434:     if ($env{'form.showrole'} eq 'Any') {
1.91      bisitz   1435:        $roleselected = ' selected="selected"'; 
1.2       raeburn  1436:     }
1.53      raeburn  1437:     my ($cnum,$cdom);
                   1438:     $r->print(&role_filter($context));
                   1439:     if ($context eq 'course') {
                   1440:         ($cnum,$cdom) = &get_course_identity();
                   1441:         $r->print(&section_group_filter($cnum,$cdom));
1.2       raeburn  1442:     }
1.78      raeburn  1443:     if ($env{'form.phase'} eq '') {
                   1444:         $r->print('<br /><br />'.&list_submit_button(&mt('Display List of Users')).
                   1445:                   "\n</p>\n".
                   1446:                   '<input type="hidden" name="phase" value="" /></form>');
                   1447:         return;
                   1448:     }
1.97.2.4  raeburn  1449:     if (!(($context eq 'domain') && 
                   1450:         (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
1.97.2.12  raeburn  1451:         $r->print(
                   1452:             "\n</p>\n"
                   1453:            .'<p>'
                   1454:            .&list_submit_button(&mt('Update Display'))
                   1455:            ."</p>\n"
                   1456:         );
1.2       raeburn  1457:     }
                   1458:     my ($indexhash,$keylist) = &make_keylist_array();
1.97.2.4  raeburn  1459:     my (%userlist,%userinfo,$clearcoursepick);
                   1460:     if (($context eq 'domain') && 
                   1461:         ($env{'form.roletype'} eq 'course') ||
                   1462:         ($env{'form.roletype'} eq 'community')) {
                   1463:         my ($crstype,$numcodes,$title,$warning);
                   1464:         if ($env{'form.roletype'} eq 'course') {
                   1465:             $crstype = 'Course';
                   1466:             $numcodes = $totcodes;
                   1467:             $title = &mt('Select Courses');
                   1468:             $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
                   1469:         } elsif ($env{'form.roletype'} eq 'community') {
                   1470:             $crstype = 'Community';
                   1471:             $numcodes = 0;
                   1472:             $title = &mt('Select Communities');
                   1473:             $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
                   1474:         }
1.3       raeburn  1475:         my $courseform =
1.97.2.4  raeburn  1476:             &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
                   1477:                             $codetitles,$idlist,$idlist_titles,$crstype);
1.3       raeburn  1478:         $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
                   1479:                   &Apache::lonhtmlcommon::start_pick_box()."\n".
1.97.2.4  raeburn  1480:                   &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
1.3       raeburn  1481:                   $courseform."\n".
                   1482:                   &Apache::lonhtmlcommon::row_closure(1).
                   1483:                   &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1.97.2.4  raeburn  1484:                   '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
                   1485:                   &list_submit_button(&mt('Update Display')).
                   1486:                   "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
                   1487:         $clearcoursepick = 0;
                   1488:         if (($env{'form.origroletype'} ne '') &&
                   1489:             ($env{'form.origroletype'} ne $env{'form.roletype'})) {
                   1490:             $clearcoursepick = 1;
                   1491:         }
                   1492:         if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.11      raeburn  1493:             $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');
                   1494:         }
                   1495:     } else {
                   1496:         $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');
1.3       raeburn  1497:     }
                   1498:     $r->rflush();
1.1       raeburn  1499:     if ($context eq 'course') {
1.46      raeburn  1500:         if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) { 
1.45      raeburn  1501:             my $classlist = &Apache::loncoursedata::get_classlist();
1.66      raeburn  1502:             if (ref($classlist) eq 'HASH') {
                   1503:                 %userlist = %{$classlist};
                   1504:             }
1.45      raeburn  1505:         }
1.43      raeburn  1506:         if ($env{'form.showrole'} ne 'st') {
                   1507:             my $showroles;
                   1508:             if ($env{'form.showrole'} ne 'Any') {
                   1509:                 $showroles = [$env{'form.showrole'}];
1.3       raeburn  1510:             } else {
1.43      raeburn  1511:                 $showroles = undef;
1.1       raeburn  1512:             }
1.43      raeburn  1513:             my $withsec = 1;
                   1514:             my $hidepriv = 1;
                   1515:             my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
                   1516:                               \@statuses,$showroles,undef,$withsec,$hidepriv);
                   1517:             &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
                   1518:                              \%advrolehash,$permission);
1.1       raeburn  1519:         }
1.2       raeburn  1520:     } else {
                   1521:         my (%cstr_roles,%dom_roles);
1.13      raeburn  1522:         if ($context eq 'author') {
1.2       raeburn  1523:             # List co-authors and assistant co-authors
1.17      raeburn  1524:             my @possroles = &roles_by_context($context);
1.2       raeburn  1525:             %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
                   1526:                                               \@statuses,\@possroles);
                   1527:             &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1.11      raeburn  1528:                              \%cstr_roles,$permission);
1.2       raeburn  1529:         } elsif ($context eq 'domain') {
                   1530:             if ($env{'form.roletype'} eq 'domain') {
                   1531:                 %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
                   1532:                 foreach my $key (keys(%dom_roles)) {
                   1533:                     if (ref($dom_roles{$key}) eq 'HASH') {
                   1534:                         &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11      raeburn  1535:                                          \%userinfo,$dom_roles{$key},$permission);
1.2       raeburn  1536:                     }
                   1537:                 }
1.13      raeburn  1538:             } elsif ($env{'form.roletype'} eq 'author') {
1.2       raeburn  1539:                 my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
                   1540:                 my %coauthors;
                   1541:                 foreach my $key (keys(%dom_roles)) {
                   1542:                     if (ref($dom_roles{$key}) eq 'HASH') {
                   1543:                         if ($env{'form.showrole'} eq 'au') {
                   1544:                             &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11      raeburn  1545:                                              \%userinfo,$dom_roles{$key},$permission);
1.2       raeburn  1546:                         } else {
                   1547:                             my @possroles;
                   1548:                             if ($env{'form.showrole'} eq 'Any') {
1.22      raeburn  1549:                                 @possroles = &roles_by_context('author');
1.2       raeburn  1550:                             } else {
                   1551:                                 @possroles = ($env{'form.showrole'}); 
                   1552:                             }
                   1553:                             foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1.22      raeburn  1554:                                 my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1.2       raeburn  1555:                                 my $extent = '/'.$authordom.'/'.$authorname;
                   1556:                                 %{$coauthors{$extent}} =
                   1557:                                     &Apache::lonnet::get_my_roles($authorname,
                   1558:                                        $authordom,undef,\@statuses,\@possroles);
                   1559:                             }
                   1560:                             &gather_userinfo($context,$format,\%userlist,
1.11      raeburn  1561:                                      $indexhash,\%userinfo,\%coauthors,$permission);
1.2       raeburn  1562:                         }
                   1563:                     }
                   1564:                 }
                   1565:             } elsif ($env{'form.roletype'} eq 'course') {
1.97.2.4  raeburn  1566:                 if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
1.2       raeburn  1567:                     my %courses = &process_coursepick();
1.39      raeburn  1568:                     my %allusers;
                   1569:                     my $hidepriv = 1;
1.2       raeburn  1570:                     foreach my $cid (keys(%courses)) {
1.17      raeburn  1571:                         my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1.11      raeburn  1572:                         next if ($cnum eq '' || $cdom eq '');
1.17      raeburn  1573:                         my $custom = 1;
1.2       raeburn  1574:                         my (@roles,@sections,%access,%users,%userdata,
1.6       albertel 1575:                             %statushash);
1.2       raeburn  1576:                         if ($env{'form.showrole'} eq 'Any') {
1.97.2.4  raeburn  1577:                             @roles = &course_roles($context,undef,$custom,
                   1578:                                                    $env{'form.roletype'});
1.2       raeburn  1579:                         } else {
                   1580:                             @roles = ($env{'form.showrole'});
                   1581:                         }
                   1582:                         foreach my $role (@roles) {
                   1583:                             %{$users{$role}} = ();
                   1584:                         }
                   1585:                         foreach my $type (@statuses) {
                   1586:                             $access{$type} = $type;
                   1587:                         }
1.39      raeburn  1588:                         &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1.2       raeburn  1589:                         foreach my $user (keys(%userdata)) {
                   1590:                             next if (ref($userinfo{$user}) eq 'HASH');
                   1591:                             foreach my $item ('fullname','id') {
                   1592:                                 $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
                   1593:                             }
                   1594:                         }
                   1595:                         foreach my $role (keys(%users)) {
                   1596:                             foreach my $user (keys(%{$users{$role}})) {
                   1597:                                 my $uniqid = $user.':'.$role;
                   1598:                                 $allusers{$uniqid}{$cid} = { desc => $cdesc,
                   1599:                                                              secs  => $statushash{$user}{$role},
                   1600:                                                            };
                   1601:                             }
                   1602:                         }
                   1603:                     }
                   1604:                     &gather_userinfo($context,$format,\%userlist,$indexhash,
1.11      raeburn  1605:                                      \%userinfo,\%allusers,$permission);
1.2       raeburn  1606:                 } else {
1.10      raeburn  1607:                     $r->print('<input type="hidden" name="phase" value="'.
                   1608:                               $env{'form.phase'}.'" /></form>');
1.2       raeburn  1609:                     return;
                   1610:                 }
1.1       raeburn  1611:             }
                   1612:         }
1.3       raeburn  1613:     }
                   1614:     if (keys(%userlist) == 0) {
1.13      raeburn  1615:         if ($context eq 'author') {
1.3       raeburn  1616:             $r->print(&mt('There are no co-authors to display.')."\n");
                   1617:         } elsif ($context eq 'domain') {
                   1618:             if ($env{'form.roletype'} eq 'domain') {
                   1619:                 $r->print(&mt('There are no users with domain roles to display.')."\n");
1.13      raeburn  1620:             } elsif ($env{'form.roletype'} eq 'author') {
1.3       raeburn  1621:                 $r->print(&mt('There are no authors or co-authors to display.')."\n");
                   1622:             } elsif ($env{'form.roletype'} eq 'course') {
                   1623:                 $r->print(&mt('There are no course users to display')."\n"); 
1.97.2.4  raeburn  1624:             } elsif ($env{'form.roletype'} eq 'community') {
                   1625:                 $r->print(&mt('There are no community users to display')."\n");
1.2       raeburn  1626:             }
1.3       raeburn  1627:         } elsif ($context eq 'course') {
                   1628:             $r->print(&mt('There are no course users to display.')."\n");
                   1629:         }
                   1630:     } else {
                   1631:         # Print out the available choices
1.4       raeburn  1632:         my $usercount;
1.3       raeburn  1633:         if ($env{'form.action'} eq 'modifystudent') {
1.10      raeburn  1634:             ($usercount) = &show_users_list($r,$context,'view',$permission,
1.4       raeburn  1635:                                  $env{'form.Status'},\%userlist,$keylist);
1.1       raeburn  1636:         } else {
1.4       raeburn  1637:             ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1.10      raeburn  1638:                                $permission,$env{'form.Status'},\%userlist,$keylist);
1.4       raeburn  1639:         }
                   1640:         if (!$usercount) {
1.72      bisitz   1641:             $r->print('<br /><span class="LC_warning">'
                   1642:                      .&mt('There are no users matching the search criteria.')
                   1643:                      .'</span>'
                   1644:             ); 
1.2       raeburn  1645:         }
                   1646:     }
1.10      raeburn  1647:     $r->print('<input type="hidden" name="phase" value="'.
                   1648:               $env{'form.phase'}.'" /></form>');
1.2       raeburn  1649: }
                   1650: 
1.53      raeburn  1651: sub role_filter {
                   1652:     my ($context) = @_;
                   1653:     my $output;
                   1654:     my $roleselected = '';
                   1655:     if ($env{'form.showrole'} eq 'Any') {
1.91      bisitz   1656:        $roleselected = ' selected="selected"';
1.53      raeburn  1657:     }
                   1658:     my ($role_select);
                   1659:     if ($context eq 'domain') {
                   1660:         $role_select = &domain_roles_select();
1.70      bisitz   1661:         $output = '<label><span class="LC_nobreak">'
                   1662:                  .&mt('Role Type: [_1]',$role_select)
                   1663:                  .'</span></label>';
1.53      raeburn  1664:     } else {
                   1665:         $role_select = '<select name="showrole">'."\n".
                   1666:                        '<option value="Any" '.$roleselected.'>'.
                   1667:                        &mt('Any role').'</option>';
1.97.2.4  raeburn  1668:         my ($roletype,$crstype);
                   1669:         if ($context eq 'course') {
                   1670:             $crstype = &Apache::loncommon::course_type();
                   1671:             if ($crstype eq 'Community') {
                   1672:                 $roletype = 'community';
                   1673:             } else {
                   1674:                 $roletype = 'course';
                   1675:             } 
                   1676:         }
                   1677:         my @poss_roles = &curr_role_permissions($context,'','',$roletype);
1.53      raeburn  1678:         foreach my $role (@poss_roles) {
                   1679:             $roleselected = '';
                   1680:             if ($role eq $env{'form.showrole'}) {
1.91      bisitz   1681:                 $roleselected = ' selected="selected"';
1.53      raeburn  1682:             }
                   1683:             my $plrole;
                   1684:             if ($role eq 'cr') {
                   1685:                 $plrole = &mt('Custom role');
                   1686:             } else {
1.97.2.4  raeburn  1687:                 $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.53      raeburn  1688:             }
                   1689:             $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
                   1690:         }
                   1691:         $role_select .= '</select>';
1.70      bisitz   1692:         $output = '<label><span class="LC_nobreak">'
                   1693:                  .&mt('Role: [_1]',$role_select)
                   1694:                  .'</span></label>';
1.53      raeburn  1695:     }
                   1696:     return $output;
                   1697: }
                   1698: 
1.33      raeburn  1699: sub section_group_filter {
                   1700:     my ($cnum,$cdom) = @_;
                   1701:     my @filters;
                   1702:     if ($env{'request.course.sec'} eq '') {
                   1703:         @filters = ('sec');
                   1704:     }
                   1705:     push(@filters,'grp');
                   1706:     my %name = (
                   1707:                  sec => 'secfilter',
                   1708:                  grp => 'grpfilter',
                   1709:                );
                   1710:     my %title = &Apache::lonlocal::texthash (
                   1711:                                               sec  => 'Section(s)',
                   1712:                                               grp  => 'Group(s)',
                   1713:                                               all  => 'all',
                   1714:                                               none => 'none',
                   1715:                                             );
1.47      raeburn  1716:     my $output;
1.33      raeburn  1717:     foreach my $item (@filters) {
1.47      raeburn  1718:         my ($markup,@options); 
1.33      raeburn  1719:         if ($env{'form.'.$name{$item}} eq '') {
                   1720:             $env{'form.'.$name{$item}} = 'all';
                   1721:         }
                   1722:         if ($item eq 'sec') {
1.97.2.6  raeburn  1723:             if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
1.33      raeburn  1724:                 $env{'form.'.$name{$item}} = 'none';
                   1725:             }
                   1726:             my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                   1727:             @options = sort(keys(%sections_count));
                   1728:         } elsif ($item eq 'grp') {
                   1729:             my %curr_groups = &Apache::longroup::coursegroups();
                   1730:             @options = sort(keys(%curr_groups));
                   1731:         }
                   1732:         if (@options > 0) {
                   1733:             my $currsel;
1.97.2.13  raeburn  1734:             $markup = '<select name="'.$name{$item}.'">'."\n";
1.33      raeburn  1735:             foreach my $option ('all','none',@options) { 
                   1736:                 $currsel = '';
                   1737:                 if ($env{'form.'.$name{$item}} eq $option) {
1.96      bisitz   1738:                     $currsel = ' selected="selected"';
1.33      raeburn  1739:                 }
                   1740:                 $markup .= ' <option value="'.$option.'"'.$currsel.'>';
                   1741:                 if (($option eq 'all') || ($option eq 'none')) {
                   1742:                     $markup .= $title{$option};
                   1743:                 } else {
                   1744:                     $markup .= $option;
                   1745:                 }   
                   1746:                 $markup .= '</option>'."\n";
                   1747:             }
                   1748:             $markup .= '</select>'."\n";
1.97.2.12  raeburn  1749:             $output .= ('&nbsp;'x3).'<span class="LC_nobreak">'
                   1750:                       .'<label>'.$title{$item}.': '.$markup.'</label>'
                   1751:                       .'</span> ';
1.33      raeburn  1752:         }
                   1753:     }
                   1754:     return $output;
                   1755: }
                   1756: 
1.2       raeburn  1757: sub list_submit_button {
                   1758:     my ($text) = @_;
1.11      raeburn  1759:     return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1.2       raeburn  1760: }
                   1761: 
                   1762: sub gather_userinfo {
1.11      raeburn  1763:     my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1.52      raeburn  1764:     my $viewablesec;
                   1765:     if ($context eq 'course') {
                   1766:         $viewablesec = &viewable_section($permission);
                   1767:     }
1.2       raeburn  1768:     foreach my $item (keys(%{$rolehash})) {
                   1769:         my %userdata;
1.22      raeburn  1770:         if ($context eq 'author') { 
1.2       raeburn  1771:             ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
                   1772:                 split(/:/,$item);
                   1773:             ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1.24      raeburn  1774:             &build_user_record($context,\%userdata,$userinfo,$indexhash,
                   1775:                                $item,$userlist);
1.22      raeburn  1776:         } elsif ($context eq 'course') {
                   1777:             ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
                   1778:              $userdata{'section'}) = split(/:/,$item,-1);
                   1779:             ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
                   1780:             if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
                   1781:                 next if ($viewablesec ne $userdata{'section'});
                   1782:             }
1.24      raeburn  1783:             &build_user_record($context,\%userdata,$userinfo,$indexhash,
                   1784:                                $item,$userlist);
1.2       raeburn  1785:         } elsif ($context eq 'domain') {
                   1786:             if ($env{'form.roletype'} eq 'domain') {
                   1787:                 ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
                   1788:                     split(/:/,$item);
                   1789:                 ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1.24      raeburn  1790:                 &build_user_record($context,\%userdata,$userinfo,$indexhash,
                   1791:                                    $item,$userlist);
1.13      raeburn  1792:             } elsif ($env{'form.roletype'} eq 'author') {
1.2       raeburn  1793:                 if (ref($rolehash->{$item}) eq 'HASH') {
                   1794:                     $userdata{'extent'} = $item;
                   1795:                     foreach my $key (keys(%{$rolehash->{$item}})) {
                   1796:                         ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =  split(/:/,$key);
                   1797:                         ($userdata{'start'},$userdata{'end'}) = 
                   1798:                             split(/:/,$rolehash->{$item}{$key});
                   1799:                         my $uniqid = $key.':'.$item;
1.25      raeburn  1800:                         &build_user_record($context,\%userdata,$userinfo,
                   1801:                                            $indexhash,$uniqid,$userlist);
1.2       raeburn  1802:                     }
                   1803:                 }
1.97.2.5  raeburn  1804:             } elsif (($env{'form.roletype'} eq 'course') || 
                   1805:                      ($env{'form.roletype'} eq 'community')) {
1.2       raeburn  1806:                 ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
                   1807:                     split(/:/,$item);
                   1808:                 if (ref($rolehash->{$item}) eq 'HASH') {
1.11      raeburn  1809:                     my $numcids = keys(%{$rolehash->{$item}});
1.2       raeburn  1810:                     foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
                   1811:                         if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
                   1812:                             my $spanstart = '';
                   1813:                             my $spanend = '; ';
                   1814:                             my $space = ', ';
                   1815:                             if ($format eq 'html' || $format eq 'view') {
                   1816:                                 $spanstart = '<span class="LC_nobreak">';
1.23      raeburn  1817:                                 # FIXME: actions on courses disabled for now
                   1818: #                                if ($permission->{'cusr'}) {
                   1819: #                                    if ($numcids > 1) {
1.25      raeburn  1820: #                                        $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" />&nbsp;';
1.23      raeburn  1821: #                                    } else {
1.25      raeburn  1822: #                                        $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" />&nbsp;';
1.23      raeburn  1823: #                                    }
                   1824: #                                }
1.2       raeburn  1825:                                 $spanend = '</span><br />';
                   1826:                                 $space = ',&nbsp;';
                   1827:                             }
                   1828:                             $userdata{'extent'} .= $spanstart.
                   1829:                                     $rolehash->{$item}{$cid}{'desc'}.$space;
                   1830:                             if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') { 
                   1831:                                 foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1.25      raeburn  1832:                                     if (($env{'form.Status'} eq 'Any') ||
                   1833:                                         ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
                   1834:                                         $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
                   1835:                                         $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
                   1836:                                     }
1.2       raeburn  1837:                                 }
                   1838:                             }
                   1839:                         }
                   1840:                     }
                   1841:                 }
1.25      raeburn  1842:                 if ($userdata{'status'} ne '') {
                   1843:                     &build_user_record($context,\%userdata,$userinfo,
                   1844:                                        $indexhash,$item,$userlist);
                   1845:                 }
1.2       raeburn  1846:             }
                   1847:         }
                   1848:     }
                   1849:     return;
                   1850: }
                   1851: 
                   1852: sub build_user_record {
1.24      raeburn  1853:     my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1.11      raeburn  1854:     next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1.97.2.5  raeburn  1855:     if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
                   1856:                              && ($env{'form.roletype'} eq 'community')))) {
1.24      raeburn  1857:         &process_date_info($userdata);
                   1858:     }
1.2       raeburn  1859:     my $username = $userdata->{'username'};
                   1860:     my $domain = $userdata->{'domain'};
                   1861:     if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1.24      raeburn  1862:         $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1.2       raeburn  1863:         $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
                   1864:     } else {
                   1865:         &aggregate_user_info($domain,$username,$userinfo);
                   1866:         $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
                   1867:         $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
                   1868:     }
                   1869:     foreach my $key (keys(%{$indexhash})) {
                   1870:         if (defined($userdata->{$key})) {
                   1871:             $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
                   1872:         }
                   1873:     }
                   1874:     return;
                   1875: }
                   1876: 
                   1877: sub courses_selector {
                   1878:     my ($cdom,$formname) = @_;
                   1879:     my %coursecodes = ();
                   1880:     my %codes = ();
                   1881:     my @codetitles = ();
                   1882:     my %cat_titles = ();
                   1883:     my %cat_order = ();
                   1884:     my %idlist = ();
                   1885:     my %idnums = ();
                   1886:     my %idlist_titles = ();
                   1887:     my $caller = 'global';
                   1888:     my $format_reply;
                   1889:     my $jscript = '';
                   1890: 
1.7       albertel 1891:     my $totcodes = 0;
                   1892:     $totcodes =
1.2       raeburn  1893:         &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
                   1894:                                                       $cdom,$totcodes);
                   1895:     if ($totcodes > 0) {
                   1896:         $format_reply =
                   1897:              &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
                   1898:                                 \%codes,\@codetitles,\%cat_titles,\%cat_order);
                   1899:         if ($format_reply eq 'ok') {
                   1900:             my $numtypes = @codetitles;
                   1901:             &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
                   1902:             my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
                   1903:             my $longtitles_str = join('","',@{$longtitles});
                   1904:             my $allidlist = $idlist{$codetitles[0]};
                   1905:             $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
                   1906:             $jscript .= $scripttext;
                   1907:             $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
                   1908:         }
                   1909:     }
                   1910:     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
                   1911: 
                   1912:     my %elements = (
                   1913:                      Year => 'selectbox',
                   1914:                      coursepick => 'radio',
                   1915:                      coursetotal => 'text',
                   1916:                      courselist => 'text',
                   1917:                    );
                   1918:     $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
                   1919:     if ($env{'form.coursepick'} eq 'category') {
                   1920:         $jscript .= qq|
                   1921: function setCourseCat(formname) {
                   1922:     if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
                   1923:         return;
                   1924:     }
                   1925:     courseSet('Year');
                   1926:     for (var j=0; j<formname.Semester.length; j++) {
                   1927:         if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
                   1928:             formname.Semester.options[j].selected = true;
                   1929:         }
                   1930:     }
                   1931:     if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
                   1932:         return;
                   1933:     }
                   1934:     courseSet('Semester');
                   1935:     for (var j=0; j<formname.Department.length; j++) {
                   1936:         if (formname.Department.options[j].value == "$env{'form.Department'}") {            formname.Department.options[j].selected = true;
                   1937:         }
                   1938:     }
                   1939:     if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
                   1940:         return;
                   1941:     }
                   1942:     courseSet('Department');
                   1943:     for (var j=0; j<formname.Number.length; j++) {
                   1944:         if (formname.Number.options[j].value == "$env{'form.Number'}") {
                   1945:             formname.Number.options[j].selected = true;
                   1946:         }
                   1947:     }
                   1948: }
                   1949: |;
                   1950:     }
                   1951:     return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
                   1952:             \%idlist_titles);
                   1953: }
                   1954: 
                   1955: sub course_selector_loadcode {
                   1956:     my ($formname) = @_;
                   1957:     my $loadcode;
                   1958:     if ($env{'form.coursepick'} ne '') {
                   1959:         $loadcode = 'javascript:setFormElements(document.'.$formname.')';
                   1960:         if ($env{'form.coursepick'} eq 'category') {
                   1961:             $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
                   1962:         }
                   1963:     }
                   1964:     return $loadcode;
                   1965: }
                   1966: 
                   1967: sub process_coursepick {
                   1968:     my $coursefilter = $env{'form.coursepick'};
                   1969:     my $cdom = $env{'request.role.domain'};
                   1970:     my %courses;
1.97.2.8  raeburn  1971:     my $crssrch = 'Course';
                   1972:     if ($env{'form.roletype'} eq 'community') {
                   1973:         $crssrch = 'Community';
                   1974:     }
1.2       raeburn  1975:     if ($coursefilter eq 'all') {
                   1976:         %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1.97.2.8  raeburn  1977:                                                  undef,undef,$crssrch);
1.2       raeburn  1978:     } elsif ($coursefilter eq 'category') {
                   1979:         my $instcode = &instcode_from_coursefilter();
                   1980:         %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1.97.2.8  raeburn  1981:                                                  undef,undef,$crssrch);
1.2       raeburn  1982:     } elsif ($coursefilter eq 'specific') {
                   1983:         if ($env{'form.coursetotal'} > 1) {
                   1984:             my @course_ids = split(/&&/,$env{'form.courselist'});
                   1985:             foreach my $cid (@course_ids) {
                   1986:                 $courses{$cid} = '';
1.1       raeburn  1987:             }
1.2       raeburn  1988:         } else {
                   1989:             $courses{$env{'form.courselist'}} = '';
1.1       raeburn  1990:         }
1.2       raeburn  1991:     }
                   1992:     return %courses;
                   1993: }
                   1994: 
                   1995: sub instcode_from_coursefilter {
                   1996:     my $instcode = '';
                   1997:     my @cats = ('Semester','Year','Department','Number');
                   1998:     foreach my $category (@cats) {
                   1999:         if (defined($env{'form.'.$category})) {
                   2000:             unless ($env{'form.'.$category} eq '-1') {
                   2001:                 $instcode .= $env{'form.'.$category};
                   2002:            }
                   2003:         }
                   2004:     }
                   2005:     if ($instcode eq '') {
                   2006:         $instcode = '.';
                   2007:     }
                   2008:     return $instcode;
                   2009: }
                   2010: 
                   2011: sub display_adv_courseroles {
                   2012:     my $output;
                   2013:     #
                   2014:     # List course personnel
                   2015:     my %coursepersonnel = 
                   2016:        &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
                   2017:     #
                   2018:     $output = '<br />'.&Apache::loncommon::start_data_table();
                   2019:     foreach my $role (sort(keys(%coursepersonnel))) {
                   2020:         next if ($role =~ /^\s*$/);
                   2021:         $output .= &Apache::loncommon::start_data_table_row().
                   2022:                   '<td>'.$role.'</td><td>';
                   2023:         foreach my $user (split(',',$coursepersonnel{$role})) {
                   2024:             my ($puname,$pudom)=split(':',$user);
                   2025:             $output .= ' '.&Apache::loncommon::aboutmewrapper(
                   2026:                        &Apache::loncommon::plainname($puname,$pudom),
                   2027:                        $puname,$pudom);
                   2028:         }
                   2029:         $output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   2030:     }
                   2031:     $output .= &Apache::loncommon::end_data_table();
                   2032: }
                   2033: 
                   2034: sub make_keylist_array {
                   2035:     my ($index,$keylist);
                   2036:     $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
                   2037:     $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
                   2038:     $index->{'end'} = &Apache::loncoursedata::CL_END();
                   2039:     $index->{'start'} = &Apache::loncoursedata::CL_START();
                   2040:     $index->{'id'} = &Apache::loncoursedata::CL_ID();
                   2041:     $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
                   2042:     $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
                   2043:     $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
                   2044:     $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
                   2045:     $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
                   2046:     $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
                   2047:     $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
                   2048:     $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
                   2049:     $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1.44      raeburn  2050:     $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1.47      raeburn  2051:     $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
1.2       raeburn  2052:     foreach my $key (keys(%{$index})) {
                   2053:         $keylist->[$index->{$key}] = $key;
                   2054:     }
                   2055:     return ($index,$keylist);
                   2056: }
                   2057: 
                   2058: sub aggregate_user_info {
                   2059:     my ($udom,$uname,$userinfo) = @_;
                   2060:     my %info=&Apache::lonnet::get('environment',
                   2061:                                   ['firstname','middlename',
                   2062:                                    'lastname','generation','id'],
                   2063:                                    $udom,$uname);
                   2064:     my ($tmp) = keys(%info);
                   2065:     my ($fullname,$id);
                   2066:     if ($tmp =~/^(con_lost|error|no_such_host)/i) {
                   2067:         $fullname = 'not available';
                   2068:         $id = 'not available';
                   2069:         &Apache::lonnet::logthis('unable to retrieve environment '.
                   2070:                                  'for '.$uname.':'.$udom);
1.1       raeburn  2071:     } else {
1.2       raeburn  2072:         $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
                   2073:         $id = $info{'id'};
                   2074:     }
                   2075:     $userinfo->{$uname.':'.$udom} = { 
                   2076:                                       fullname => $fullname,
                   2077:                                       id       => $id,
                   2078:                                     };
                   2079:     return;
                   2080: }
1.1       raeburn  2081: 
1.2       raeburn  2082: sub process_date_info {
                   2083:     my ($userdata) = @_;
                   2084:     my $now = time;
1.83      raeburn  2085:     $userdata->{'status'} = 'Active';
1.2       raeburn  2086:     if ($userdata->{'start'} > 0) {
                   2087:         if ($now < $userdata->{'start'}) {
1.83      raeburn  2088:             $userdata->{'status'} = 'Future';
1.2       raeburn  2089:         }
1.1       raeburn  2090:     }
1.2       raeburn  2091:     if ($userdata->{'end'} > 0) {
                   2092:         if ($now > $userdata->{'end'}) {
1.83      raeburn  2093:             $userdata->{'status'} = 'Expired';
1.2       raeburn  2094:         }
                   2095:     }
                   2096:     return;
1.1       raeburn  2097: }
                   2098: 
                   2099: sub show_users_list {
1.55      raeburn  2100:     my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
                   2101:     if ($formname eq '') {
                   2102:         $formname = 'studentform';
                   2103:     }
1.1       raeburn  2104:     #
                   2105:     # Variables for excel output
                   2106:     my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
                   2107:     #
                   2108:     # Variables for csv output
                   2109:     my ($CSVfile,$CSVfilename);
                   2110:     #
                   2111:     my $sortby = $env{'form.sortby'};
1.3       raeburn  2112:     my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2       raeburn  2113:     if ($context eq 'course') {
1.3       raeburn  2114:         push(@sortable,('section','groups','type'));
1.2       raeburn  2115:     } else {
1.3       raeburn  2116:         push(@sortable,'extent');
                   2117:     }
1.55      raeburn  2118:     if ($mode eq 'pickauthor') {
                   2119:         @sortable = ('username','fullname','email','status');
                   2120:     }
1.3       raeburn  2121:     if (!grep(/^\Q$sortby\E$/,@sortable)) {
                   2122:         $sortby = 'username';
1.1       raeburn  2123:     }
1.22      raeburn  2124:     my $setting = $env{'form.roletype'};
1.97.2.4  raeburn  2125:     my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$crstype);
1.1       raeburn  2126:     if ($context eq 'course') {
1.22      raeburn  2127:         $cid = $env{'request.course.id'};
1.97.2.4  raeburn  2128:         $crstype = &Apache::loncommon::course_type();
1.17      raeburn  2129:         ($cnum,$cdom) = &get_course_identity($cid);
1.2       raeburn  2130:         ($classgroups) = &Apache::loncoursedata::get_group_memberships(
                   2131:                                      $userlist,$keylist,$cdom,$cnum);
1.16      raeburn  2132:         if ($mode eq 'autoenroll') {
                   2133:             $env{'form.showrole'} = 'st';
                   2134:         } else {
                   2135:             if (! exists($env{'form.displayphotos'})) {
                   2136:                 $env{'form.displayphotos'} = 'off';
                   2137:             }
                   2138:             $displayphotos = $env{'form.displayphotos'};
                   2139:             if (! exists($env{'form.displayclickers'})) {
                   2140:                 $env{'form.displayclickers'} = 'off';
                   2141:             }
                   2142:             $displayclickers = $env{'form.displayclickers'};
                   2143:             if ($env{'course.'.$cid.'.internal.showphoto'}) {
                   2144:                 $r->print('
1.1       raeburn  2145: <script type="text/javascript">
1.96      bisitz   2146: // <![CDATA[
1.1       raeburn  2147: function photowindow(photolink) {
                   2148:     var title = "Photo_Viewer";
                   2149:     var options = "scrollbars=1,resizable=1,menubar=0";
                   2150:     options += ",width=240,height=240";
                   2151:     stdeditbrowser = open(photolink,title,options,"1");
                   2152:     stdeditbrowser.focus();
                   2153: }
1.96      bisitz   2154: // ]]>
1.1       raeburn  2155: </script>
1.16      raeburn  2156:                ');
                   2157:             }
                   2158:             $r->print(<<END);
1.1       raeburn  2159: <input type="hidden" name="displayphotos" value="$displayphotos" />
                   2160: <input type="hidden" name="displayclickers" value="$displayclickers" />
                   2161: END
1.16      raeburn  2162:         }
1.97.2.5  raeburn  2163:     } elsif ($context eq 'domain') {
                   2164:         if ($setting eq 'community') {
                   2165:             $crstype = 'Community';
1.97.2.8  raeburn  2166:         } elsif ($setting eq 'course') {
1.97.2.5  raeburn  2167:             $crstype = 'Course';
                   2168:         }
1.1       raeburn  2169:     }
1.55      raeburn  2170:     if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.11      raeburn  2171:         my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.40      raeburn  2172:         my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1.56      raeburn  2173:         my $verify_action_js = &bulkaction_javascript($formname);
1.1       raeburn  2174:         $r->print(<<END);
1.10      raeburn  2175: 
                   2176: <script type="text/javascript" language="Javascript">
1.96      bisitz   2177: // <![CDATA[
1.11      raeburn  2178: $check_uncheck_js
                   2179: 
1.56      raeburn  2180: $verify_action_js
1.10      raeburn  2181: 
                   2182: function username_display_launch(username,domain) {
                   2183:     var target;
1.55      raeburn  2184:     for (var i=0; i<document.$formname.usernamelink.length; i++) {
                   2185:         if (document.$formname.usernamelink[i].checked) {
                   2186:             target = document.$formname.usernamelink[i].value;
1.10      raeburn  2187:         }
                   2188:     }
                   2189:     if (target == 'modify') {
1.55      raeburn  2190:         if (document.$formname.userwin.checked == true) {
1.50      raeburn  2191:             var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';
                   2192:             var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
                   2193:             modifywin = window.open(url,'',options,1);
                   2194:             modifywin.focus();
                   2195:             return;
                   2196:         } else {
1.55      raeburn  2197:             document.$formname.srchterm.value=username;
                   2198:             document.$formname.srchdomain.value=domain;
                   2199:             document.$formname.phase.value='get_user_info';
                   2200:             document.$formname.action.value = 'singleuser';
                   2201:             document.$formname.submit();
1.50      raeburn  2202:         }
1.10      raeburn  2203:     }
1.48      raeburn  2204:     if (target == 'aboutme') {
1.55      raeburn  2205:         if (document.$formname.userwin.checked == true) {
1.50      raeburn  2206:             var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
                   2207:             var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
                   2208:             aboutmewin = window.open(url,'',options,1);
                   2209:             aboutmewin.focus();
                   2210:             return;
                   2211:         } else {
                   2212:             document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
                   2213:         }
1.48      raeburn  2214:     }
1.97.2.2  raeburn  2215:     if (target == 'track') {
                   2216:         if (document.$formname.userwin.checked == true) {
                   2217:             var url = '/adm/trackstudent?selected_student='+username+':'+domain+'&only_body=1';
                   2218:             var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
                   2219:             var trackwin = window.open(url,'',options,1);
                   2220:             trackwin.focus();
                   2221:             return;
                   2222:         } else {
                   2223:             document.location.href = '/adm/trackstudent?selected_student='+username+':'+domain;
                   2224:         }
                   2225:     }
1.10      raeburn  2226: }
1.96      bisitz   2227: // ]]>
1.10      raeburn  2228: </script>
1.11      raeburn  2229: $date_sec_selector
1.1       raeburn  2230: <input type="hidden" name="state" value="$env{'form.state'}" />
                   2231: END
                   2232:     }
                   2233:     $r->print(<<END);
                   2234: <input type="hidden" name="sortby" value="$sortby" />
                   2235: END
                   2236: 
                   2237:     my %lt=&Apache::lonlocal::texthash(
                   2238:                        'username'   => "username",
                   2239:                        'domain'     => "domain",
                   2240:                        'id'         => 'ID',
                   2241:                        'fullname'   => "name",
                   2242:                        'section'    => "section",
                   2243:                        'groups'     => "active groups",
                   2244:                        'start'      => "start date",
                   2245:                        'end'        => "end date",
                   2246:                        'status'     => "status",
1.2       raeburn  2247:                        'role'       => "role",
1.1       raeburn  2248:                        'type'       => "enroll type/action",
1.79      schafran 2249:                        'email'      => "e-mail address",
1.1       raeburn  2250:                        'photo'      => "photo",
1.2       raeburn  2251:                        'extent'     => "extent",
1.11      raeburn  2252:                        'pr'         => "Proceed",
                   2253:                        'ca'         => "check all",
                   2254:                        'ua'         => "uncheck all",
                   2255:                        'ac'         => "Action to take for selected users",
1.56      raeburn  2256:                        'link'       => "Behavior of clickable username link for each user",
1.82      weissno  2257:                        'aboutme'    => "Display a user's personal information page",
1.50      raeburn  2258:                        'owin'       => "Open in a new window",
1.10      raeburn  2259:                        'modify'     => "Modify a user's information",
1.97.2.2  raeburn  2260:                        'track'      => "View a user's recent activity",
1.67      droeschl 2261:                        'clicker'    => "Clicker-ID",
1.1       raeburn  2262:                       );
1.2       raeburn  2263:     if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
                   2264:         $lt{'extent'} = &mt('Course(s): description, section(s), status');
1.97.2.5  raeburn  2265:     } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
                   2266:         $lt{'extent'} = &mt('Communities: description, section(s), status');
1.13      raeburn  2267:     } elsif ($context eq 'author') {
1.2       raeburn  2268:         $lt{'extent'} = &mt('Author'); 
                   2269:     }
1.55      raeburn  2270:     my @cols;
                   2271:     if ($mode eq 'pickauthor') {
                   2272:         @cols = ('username','fullname','status','email');
                   2273:     } else {
                   2274:         @cols = ('username','domain','id','fullname');
                   2275:         if ($context eq 'course') {
                   2276:             push(@cols,'section');
                   2277:         }
1.97.2.5  raeburn  2278:         if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
                   2279:                               && ($env{'form.roletype'} eq 'community'))) {
1.55      raeburn  2280:             push(@cols,('start','end'));
                   2281:         }
                   2282:         if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
                   2283:             push(@cols,'role');
                   2284:         }
                   2285:         if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
1.97.2.5  raeburn  2286:                                     $env{'form.roletype'} eq 'course' ||
                   2287:                                     $env{'form.roletype'} eq 'community')) {
1.55      raeburn  2288:             push (@cols,'extent');
                   2289:         }
1.97.2.5  raeburn  2290:         if (($statusmode eq 'Any') &&
                   2291:             (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
                   2292:              || ($env{'form.roletype'} eq 'community'))))) {
1.55      raeburn  2293:             push(@cols,'status');
                   2294:         }
                   2295:         if ($context eq 'course') {
                   2296:             push(@cols,'groups');
                   2297:         }
                   2298:         push(@cols,'email');
1.2       raeburn  2299:     }
1.1       raeburn  2300: 
1.4       raeburn  2301:     my $rolefilter = $env{'form.showrole'};
1.5       raeburn  2302:     if ($env{'form.showrole'} eq 'cr') {
                   2303:         $rolefilter = &mt('custom');  
                   2304:     } elsif ($env{'form.showrole'} ne 'Any') {
1.2       raeburn  2305:         $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
                   2306:     }
1.16      raeburn  2307:     my $results_description;
                   2308:     if ($mode ne 'autoenroll') {
                   2309:         $results_description = &results_header_row($rolefilter,$statusmode,
1.97.2.5  raeburn  2310:                                                    $context,$permission,$mode,$crstype);
                   2311: 
1.56      raeburn  2312:         $r->print('<b>'.$results_description.'</b><br /><br />');
1.16      raeburn  2313:     }
1.26      raeburn  2314:     my ($output,$actionselect,%canchange,%canchangesec);
1.55      raeburn  2315:     if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
                   2316:         if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
1.16      raeburn  2317:             if ($permission->{'cusr'}) {
1.97.2.8  raeburn  2318:                 unless (($context eq 'domain') && 
                   2319:                         (($setting eq 'course') || ($setting eq 'community'))) {
                   2320:                     $actionselect = 
                   2321:                         &select_actions($context,$setting,$statusmode,$formname);
                   2322:                 }
1.16      raeburn  2323:             }
                   2324:             $r->print(<<END);
1.10      raeburn  2325: <input type="hidden" name="srchby"  value="uname" />
                   2326: <input type="hidden" name="srchin"   value="dom" />
                   2327: <input type="hidden" name="srchtype" value="exact" />
                   2328: <input type="hidden" name="srchterm" value="" />
1.11      raeburn  2329: <input type="hidden" name="srchdomain" value="" /> 
1.1       raeburn  2330: END
1.16      raeburn  2331:             if ($actionselect) {
1.41      raeburn  2332:                 $output .= <<"END";
1.97.2.1  raeburn  2333: <div class="LC_left_float"><fieldset><legend><b>$lt{'ac'}</b></legend>
1.56      raeburn  2334: $actionselect
                   2335: <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> &nbsp;
                   2336: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
1.11      raeburn  2337: END
1.26      raeburn  2338:                 my @allroles;
                   2339:                 if ($env{'form.showrole'} eq 'Any') {
                   2340:                     my $custom = 1;
                   2341:                     if ($context eq 'domain') {
1.97.2.4  raeburn  2342:                         @allroles = &roles_by_context($setting,$custom,$crstype);
1.26      raeburn  2343:                     } else {
1.97.2.4  raeburn  2344:                         @allroles = &roles_by_context($context,$custom,$crstype);
1.26      raeburn  2345:                     }
                   2346:                 } else {
                   2347:                     @allroles = ($env{'form.showrole'});
                   2348:                 }
                   2349:                 foreach my $role (@allroles) {
                   2350:                     if ($context eq 'domain') {
                   2351:                         if ($setting eq 'domain') {
                   2352:                             if (&Apache::lonnet::allowed('c'.$role,
                   2353:                                     $env{'request.role.domain'})) {
                   2354:                                 $canchange{$role} = 1;
                   2355:                             }
1.31      raeburn  2356:                         } elsif ($setting eq 'author') {
                   2357:                             if (&Apache::lonnet::allowed('c'.$role,
                   2358:                                     $env{'request.role.domain'})) {
                   2359:                                 $canchange{$role} = 1;
                   2360:                             }
1.26      raeburn  2361:                         }
                   2362:                     } elsif ($context eq 'author') {
                   2363:                         if (&Apache::lonnet::allowed('c'.$role,
                   2364:                             $env{'user.domain'}.'/'.$env{'user.name'})) {
                   2365:                             $canchange{$role} = 1;
                   2366:                         }
                   2367:                     } elsif ($context eq 'course') {
                   2368:                         if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
                   2369:                             $canchange{$role} = 1;
                   2370:                         } elsif ($env{'request.course.sec'} ne '') {
                   2371:                             if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
                   2372:                                 $canchangesec{$role} = $env{'request.course.sec'};
                   2373:                             }
                   2374:                         }
                   2375:                     }
                   2376:                 }
1.16      raeburn  2377:             }
1.97.2.1  raeburn  2378:             $output .= '<div class="LC_left_float"><fieldset><legend><b>'.$lt{'link'}.'</b></legend>'.
1.56      raeburn  2379:                        '<table><tr>';
                   2380:             my @linkdests = ('aboutme');
                   2381:             if ($permission->{'cusr'}) {
                   2382:                 unshift (@linkdests,'modify');
                   2383:             }
1.97.2.2  raeburn  2384:             if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
                   2385:                 &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
                   2386:                                          $env{'request.course.sec'})) {
                   2387:                 push(@linkdests,'track');
                   2388:             }
1.56      raeburn  2389:             $output .= '<td>';
                   2390:             my $usernamelink = $env{'form.usernamelink'};
                   2391:             if ($usernamelink eq '') {
                   2392:                 $usernamelink = 'aboutme';
                   2393:             }
                   2394:             foreach my $item (@linkdests) {
                   2395:                 my $checkedstr = '';
                   2396:                 if ($item eq $usernamelink) {
1.86      bisitz   2397:                     $checkedstr = ' checked="checked"';
1.56      raeburn  2398:                 }
1.86      bisitz   2399:                 $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' />&nbsp;'.$lt{$item}.'</label></span><br />';
1.56      raeburn  2400:             }
                   2401:             my $checkwin;
                   2402:             if ($env{'form.userwin'}) {
1.86      bisitz   2403:                 $checkwin = ' checked="checked"';
1.56      raeburn  2404:             }
1.86      bisitz   2405:             $output .= '</td><td valign="top"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';
1.4       raeburn  2406:         }
1.56      raeburn  2407:         $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".
1.1       raeburn  2408:                   &Apache::loncommon::start_data_table().
1.4       raeburn  2409:                   &Apache::loncommon::start_data_table_header_row();
1.1       raeburn  2410:         if ($mode eq 'autoenroll') {
1.4       raeburn  2411:             $output .= "
1.55      raeburn  2412:  <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
1.4       raeburn  2413:             ";
1.1       raeburn  2414:         } else {
1.97.2.8  raeburn  2415:             $output .= "\n".'<th>&nbsp;</th>'."\n";
1.11      raeburn  2416:             if ($actionselect) {
                   2417:                 $output .= '<th>'.&mt('Select').'</th>'."\n";
                   2418:             }
1.1       raeburn  2419:         }
                   2420:         foreach my $item (@cols) {
1.55      raeburn  2421:             $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
1.1       raeburn  2422:         }
1.2       raeburn  2423:         my %role_types = &role_type_names();
1.16      raeburn  2424:         if ($context eq 'course' && $mode ne 'autoenroll') {
1.4       raeburn  2425:             if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
                   2426:                 # Clicker display on or off?
1.58      bisitz   2427:                 my %clicker_options = (
                   2428:                                         'on' => 'Show',
                   2429:                                         'off' => 'Hide',
                   2430:                                       );
1.4       raeburn  2431:                 my $clickerchg = 'on';
                   2432:                 if ($displayclickers eq 'on') {
                   2433:                     $clickerchg = 'off';
                   2434:                 }
1.58      bisitz   2435:                 $output .= '    <th>'."\n".'     '
                   2436:                         .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'
                   2437:                             ,'<a href="javascript:document.'.$formname.'.displayclickers.value='
                   2438:                              ."'".$clickerchg."'".';document.'.$formname.'.submit();">'
                   2439:                             ,'</a>')
                   2440:                         ."\n".'    </th>'."\n";
1.1       raeburn  2441: 
1.4       raeburn  2442:                 # Photo display on or off?
                   2443:                 if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                   2444:                     my %photo_options = &Apache::lonlocal::texthash(
                   2445:                                                             'on' => 'Show',
                   2446:                                                             'off' => 'Hide',
                   2447:                                                                 );
                   2448:                     my $photochg = 'on';
                   2449:                     if ($displayphotos eq 'on') {
                   2450:                         $photochg = 'off';
                   2451:                     }
                   2452:                     $output .= '    <th>'."\n".'     '.
1.55      raeburn  2453:                 '<a href="javascript:document.'.$formname.'.displayphotos.value='.
                   2454:                       "'".$photochg."'".';document.'.$formname.'.submit();">'.
1.1       raeburn  2455:                       $photo_options{$photochg}.'</a>&nbsp;'.$lt{'photo'}."\n".
1.4       raeburn  2456:                       '    </th>'."\n";
                   2457:                 }
1.1       raeburn  2458:             }
1.4       raeburn  2459:         }
1.16      raeburn  2460:         $output .= &Apache::loncommon::end_data_table_header_row();
1.1       raeburn  2461: # Done with the HTML header line
                   2462:     } elsif ($mode eq 'csv') {
                   2463:         #
                   2464:         # Open a file
                   2465:         $CSVfilename = '/prtspool/'.
1.2       raeburn  2466:                        $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
                   2467:                        time.'_'.rand(1000000000).'.csv';
1.1       raeburn  2468:         unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
                   2469:             $r->log_error("Couldn't open $CSVfilename for output $!");
1.97.2.10  raeburn  2470:             $r->print(
                   2471:                 '<p class="LC_error">'
                   2472:                .&mt('Problems occurred in writing the CSV file.')
                   2473:                .' '.&mt('This error has been logged.')
                   2474:                .' '.&mt('Please alert your LON-CAPA administrator.')
                   2475:                .'</p>'
                   2476:             );
1.1       raeburn  2477:             $CSVfile = undef;
                   2478:         }
                   2479:         #
1.67      droeschl 2480:         push @cols,'clicker';
1.1       raeburn  2481:         # Write headers and data to file
1.2       raeburn  2482:         print $CSVfile '"'.$results_description.'"'."\n"; 
1.1       raeburn  2483:         print $CSVfile '"'.join('","',map {
                   2484:             &Apache::loncommon::csv_translate($lt{$_})
1.67      droeschl 2485:             } (@cols))."\"\n";
1.1       raeburn  2486:     } elsif ($mode eq 'excel') {
1.67      droeschl 2487:         push @cols,'clicker';
1.1       raeburn  2488:         # Create the excel spreadsheet
                   2489:         ($excel_workbook,$excel_filename,$format) =
                   2490:             &Apache::loncommon::create_workbook($r);
                   2491:         return if (! defined($excel_workbook));
                   2492:         $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2       raeburn  2493:         $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1       raeburn  2494:         #
                   2495:         my @colnames = map {$lt{$_}} (@cols);
1.67      droeschl 2496: 
1.1       raeburn  2497:         $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
                   2498:     }
                   2499: 
                   2500: # Done with header lines in all formats
                   2501:     my %index;
                   2502:     my $i;
1.2       raeburn  2503:     foreach my $idx (@$keylist) {
                   2504:         $index{$idx} = $i++;
                   2505:     }
1.4       raeburn  2506:     my $usercount = 0;
1.33      raeburn  2507:     my ($secfilter,$grpfilter);
                   2508:     if ($context eq 'course') {
                   2509:         $secfilter = $env{'form.secfilter'};
                   2510:         $grpfilter = $env{'form.grpfilter'};
                   2511:         if ($secfilter eq '') {
                   2512:             $secfilter = 'all';
                   2513:         }
                   2514:         if ($grpfilter eq '') {
                   2515:             $grpfilter = 'all';
                   2516:         }
                   2517:     }
1.83      raeburn  2518:     my %ltstatus = &Apache::lonlocal::texthash(
                   2519:                                                 Active  => 'Active',
                   2520:                                                 Future  => 'Future',
                   2521:                                                 Expired => 'Expired',
                   2522:                                                );
1.2       raeburn  2523:     # Get groups, role, permanent e-mail so we can sort on them if
                   2524:     # necessary.
                   2525:     foreach my $user (keys(%{$userlist})) {
1.43      raeburn  2526:         if ($user eq '' ) {
                   2527:             delete($userlist->{$user});
                   2528:             next;
                   2529:         }
1.11      raeburn  2530:         if ($context eq 'domain' &&  $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
                   2531:             delete($userlist->{$user});
                   2532:             next;
                   2533:         }
1.2       raeburn  2534:         my ($uname,$udom,$role,$groups,$email);
1.5       raeburn  2535:         if (($statusmode ne 'Any') && 
                   2536:                  ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
                   2537:             delete($userlist->{$user});
                   2538:             next;
                   2539:         }
1.2       raeburn  2540:         if ($context eq 'domain') {
                   2541:             if ($env{'form.roletype'} eq 'domain') {
                   2542:                 ($role,$uname,$udom) = split(/:/,$user);
1.11      raeburn  2543:                 if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
                   2544:                     ($udom eq $env{'request.role.domain'})) {
                   2545:                     delete($userlist->{$user});
                   2546:                     next;
                   2547:                 }
1.13      raeburn  2548:             } elsif ($env{'form.roletype'} eq 'author') {
1.2       raeburn  2549:                 ($uname,$udom,$role) = split(/:/,$user,-1);
1.97.2.5  raeburn  2550:             } elsif (($env{'form.roletype'} eq 'course') || 
                   2551:                      ($env{'form.roletype'} eq 'community')) {
1.2       raeburn  2552:                 ($uname,$udom,$role) = split(/:/,$user);
                   2553:             }
                   2554:         } else {
                   2555:             ($uname,$udom,$role) = split(/:/,$user,-1);
                   2556:             if (($context eq 'course') && $role eq '') {
                   2557:                 $role = 'st';
                   2558:             }
                   2559:         }
                   2560:         $userlist->{$user}->[$index{'role'}] = $role;
                   2561:         if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'}  eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
                   2562:             delete($userlist->{$user});
                   2563:             next;
                   2564:         }
1.33      raeburn  2565:         if ($context eq 'course') {
                   2566:             my @ac_groups;
                   2567:             if (ref($classgroups) eq 'HASH') {
                   2568:                 $groups = $classgroups->{$user};
                   2569:             }
                   2570:             if (ref($groups->{'active'}) eq 'HASH') {
                   2571:                 @ac_groups = keys(%{$groups->{'active'}});
                   2572:                 $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
                   2573:             }
                   2574:             if ($mode ne 'autoenroll') {
                   2575:                 my $section = $userlist->{$user}->[$index{'section'}];
1.43      raeburn  2576:                 if (($env{'request.course.sec'} ne '') && 
                   2577:                     ($section ne $env{'request.course.sec'})) {
                   2578:                     if ($role eq 'st') {
                   2579:                         delete($userlist->{$user});
                   2580:                         next;
                   2581:                     }
                   2582:                 }
1.33      raeburn  2583:                 if ($secfilter eq 'none') {
                   2584:                     if ($section ne '') {
                   2585:                         delete($userlist->{$user});
                   2586:                         next;
                   2587:                     }
                   2588:                 } elsif ($secfilter ne 'all') {
                   2589:                     if ($section ne $secfilter) {
                   2590:                         delete($userlist->{$user});
                   2591:                         next;
                   2592:                     }
                   2593:                 }
                   2594:                 if ($grpfilter eq 'none') {
                   2595:                     if (@ac_groups > 0) {
                   2596:                         delete($userlist->{$user});
                   2597:                         next;
                   2598:                     }
                   2599:                 } elsif ($grpfilter ne 'all') {
                   2600:                     if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
                   2601:                         delete($userlist->{$user});
                   2602:                         next;
                   2603:                     }
                   2604:                 }
1.44      raeburn  2605:                 if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                   2606:                     if (($displayphotos eq 'on') && ($role eq 'st')) {
                   2607:                         $userlist->{$user}->[$index{'photo'}] =
1.47      raeburn  2608:                             &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
                   2609:                         $userlist->{$user}->[$index{'thumbnail'}] =
1.44      raeburn  2610:                             &Apache::lonnet::retrievestudentphoto($udom,$uname,
                   2611:                                                                 'gif','thumbnail');
                   2612:                     }
                   2613:                 }
1.33      raeburn  2614:             }
1.2       raeburn  2615:         }
                   2616:         my %emails   = &Apache::loncommon::getemails($uname,$udom);
                   2617:         if ($emails{'permanentemail'} =~ /\S/) {
                   2618:             $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
                   2619:         }
1.4       raeburn  2620:         $usercount ++;
                   2621:     }
                   2622:     my $autocount = 0;
                   2623:     my $manualcount = 0;
                   2624:     my $lockcount = 0;
                   2625:     my $unlockcount = 0;
                   2626:     if ($usercount) {
                   2627:         $r->print($output);
                   2628:     } else {
                   2629:         if ($mode eq 'autoenroll') {
                   2630:             return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
                   2631:         } else {
                   2632:             return;
                   2633:         }
1.1       raeburn  2634:     }
1.2       raeburn  2635:     #
                   2636:     # Sort the users
1.1       raeburn  2637:     my $index  = $index{$sortby};
                   2638:     my $second = $index{'username'};
                   2639:     my $third  = $index{'domain'};
1.2       raeburn  2640:     my @sorted_users = sort {
                   2641:         lc($userlist->{$a}->[$index])  cmp lc($userlist->{$b}->[$index])
1.1       raeburn  2642:             ||
1.2       raeburn  2643:         lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second])            ||
                   2644:         lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
                   2645:         } (keys(%$userlist));
1.4       raeburn  2646:     my $rowcount = 0;
1.2       raeburn  2647:     foreach my $user (@sorted_users) {
1.4       raeburn  2648:         my %in;
1.2       raeburn  2649:         my $sdata = $userlist->{$user};
1.4       raeburn  2650:         $rowcount ++; 
1.2       raeburn  2651:         foreach my $item (@{$keylist}) {
                   2652:             $in{$item} = $sdata->[$index{$item}];
                   2653:         }
1.67      droeschl 2654:         my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
                   2655:         if ($clickers!~/\w/) { $clickers='-'; }
                   2656:         $in{'clicker'} = $clickers; 
                   2657: 	my $role = $in{'role'};
1.97.2.4  raeburn  2658:         $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); 
1.2       raeburn  2659:         if (! defined($in{'start'}) || $in{'start'} == 0) {
                   2660:             $in{'start'} = &mt('none');
                   2661:         } else {
                   2662:             $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
1.1       raeburn  2663:         }
1.2       raeburn  2664:         if (! defined($in{'end'}) || $in{'end'} == 0) {
                   2665:             $in{'end'} = &mt('none');
1.1       raeburn  2666:         } else {
1.2       raeburn  2667:             $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
1.1       raeburn  2668:         }
1.55      raeburn  2669:         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2       raeburn  2670:             $r->print(&Apache::loncommon::start_data_table_row());
1.11      raeburn  2671:             my $checkval;
1.16      raeburn  2672:             if ($mode eq 'autoenroll') {
                   2673:                 my $cellentry;
                   2674:                 if ($in{'type'} eq 'auto') {
                   2675:                     $cellentry = '<b>'.&mt('auto').'</b>&nbsp;<label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;Change</label>';
                   2676:                     $autocount ++;
                   2677:                 } else {
1.76      bisitz   2678:                     $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;Change</label></span></td></tr><tr><td><span class="LC_nobreak">';
1.16      raeburn  2679:                     $manualcount ++;
                   2680:                     if ($in{'lockedtype'}) {
                   2681:                         $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Unlock').'</label>';
                   2682:                         $unlockcount ++;
                   2683:                     } else {
                   2684:                         $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Lock').'</label>';
                   2685:                         $lockcount ++;
1.11      raeburn  2686:                     }
1.76      bisitz   2687:                     $cellentry .= '</span></td></tr></table>';
1.16      raeburn  2688:                 }
                   2689:                 $r->print("<td>$cellentry</td>\n");
                   2690:             } else {
1.55      raeburn  2691:                 if ($mode ne 'pickauthor') {  
                   2692:                     $r->print("<td>$rowcount</td>\n");
                   2693:                 }
1.16      raeburn  2694:                 if ($actionselect) {
1.26      raeburn  2695:                     my $showcheckbox;
                   2696:                     if ($role =~ /^cr\//) {
                   2697:                         $showcheckbox = $canchange{'cr'};
                   2698:                     } else {
                   2699:                         $showcheckbox = $canchange{$role};
                   2700:                     }
                   2701:                     if (!$showcheckbox) {
                   2702:                         if ($context eq 'course') {
                   2703:                             if ($canchangesec{$role} ne '') {
                   2704:                                 if ($canchangesec{$role} eq $in{'section'}) {
                   2705:                                     $showcheckbox = 1;
                   2706:                                 }
                   2707:                             }
1.16      raeburn  2708:                         }
1.26      raeburn  2709:                     }
                   2710:                     if ($showcheckbox) {
                   2711:                         $checkval = $user; 
                   2712:                         if ($context eq 'course') {
                   2713:                             if ($role eq 'st') {
                   2714:                                 $checkval .= ':st';
                   2715:                             }
                   2716:                             $checkval .= ':'.$in{'section'};
                   2717:                             if ($role eq 'st') {
                   2718:                                 $checkval .= ':'.$in{'type'}.':'.
                   2719:                                              $in{'lockedtype'};
                   2720:                             }
1.16      raeburn  2721:                         }
1.26      raeburn  2722:                         $r->print('<td><input type="checkbox" name="'.
1.86      bisitz   2723:                                   'actionlist" value="'.$checkval.'" /></td>');
1.26      raeburn  2724:                     } else {
                   2725:                         $r->print('<td>&nbsp;</td>');
1.16      raeburn  2726:                     }
1.55      raeburn  2727:                 } elsif ($mode eq 'pickauthor') {
                   2728:                         $r->print('<td><input type="button" name="chooseauthor" onclick="javascript:gochoose('."'$in{'username'}'".');" value="'.&mt('Select').'" /></td>');
1.11      raeburn  2729:                 }
                   2730:             }
1.2       raeburn  2731:             foreach my $item (@cols) {
1.10      raeburn  2732:                 if ($item eq 'username') {
1.48      raeburn  2733:                     $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.16      raeburn  2734:                 } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
1.11      raeburn  2735:                     $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
1.83      raeburn  2736:                 } elsif ($item eq 'status') {
                   2737:                     my $showitem = $in{$item};
                   2738:                     if (defined($ltstatus{$in{$item}})) {
                   2739:                         $showitem = $ltstatus{$in{$item}};
                   2740:                     }
                   2741:                     $r->print('<td>'.$showitem.'</td>'."\n");
1.10      raeburn  2742:                 } else {
                   2743:                     $r->print('<td>'.$in{$item}.'</td>'."\n");
                   2744:                 }
1.2       raeburn  2745:             }
1.16      raeburn  2746:             if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.4       raeburn  2747:                 if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
                   2748:                     if ($displayclickers eq 'on') {
                   2749:                         my $clickers =
1.2       raeburn  2750:                    (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
1.4       raeburn  2751:                         if ($clickers!~/\w/) { $clickers='-'; }
                   2752:                         $r->print('<td>'.$clickers.'</td>');
1.2       raeburn  2753:                     } else {
                   2754:                         $r->print('    <td>&nbsp;</td>  ');
                   2755:                     }
1.4       raeburn  2756:                     if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.44      raeburn  2757:                         if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
1.90      bisitz   2758:                             $r->print('    <td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
1.4       raeburn  2759:                         } else {
                   2760:                             $r->print('    <td>&nbsp;</td>  ');
                   2761:                         }
                   2762:                     }
1.2       raeburn  2763:                 }
                   2764:             }
                   2765:             $r->print(&Apache::loncommon::end_data_table_row());
                   2766:         } elsif ($mode eq 'csv') {
                   2767:             next if (! defined($CSVfile));
                   2768:             # no need to bother with $linkto
                   2769:             if (! defined($in{'start'}) || $in{'start'} == 0) {
                   2770:                 $in{'start'} = &mt('none');
                   2771:             } else {
                   2772:                 $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
                   2773:             }
                   2774:             if (! defined($in{'end'}) || $in{'end'} == 0) {
                   2775:                 $in{'end'} = &mt('none');
                   2776:             } else {
                   2777:                 $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
                   2778:             }
                   2779:             my @line = ();
                   2780:             foreach my $item (@cols) {
                   2781:                 push @line,&Apache::loncommon::csv_translate($in{$item});
                   2782:             }
1.67      droeschl 2783:             print $CSVfile '"'.join('","',@line)."\"\n";
1.2       raeburn  2784:         } elsif ($mode eq 'excel') {
                   2785:             my $col = 0;
                   2786:             foreach my $item (@cols) {
                   2787:                 if ($item eq 'start' || $item eq 'end') {
                   2788:                     if (defined($item) && $item != 0) {
                   2789:                         $excel_sheet->write($row,$col++,
                   2790:                             &Apache::lonstathelpers::calc_serial($in{item}),
                   2791:                                     $format->{'date'});
                   2792:                     } else {
                   2793:                         $excel_sheet->write($row,$col++,'none');
                   2794:                     }
                   2795:                 } else {
                   2796:                     $excel_sheet->write($row,$col++,$in{$item});
                   2797:                 }
                   2798:             }
                   2799:             $row++;
1.1       raeburn  2800:         }
                   2801:     }
1.55      raeburn  2802:     if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
1.2       raeburn  2803:             $r->print(&Apache::loncommon::end_data_table().'<br />');
                   2804:     } elsif ($mode eq 'excel') {
                   2805:         $excel_workbook->close();
1.68      droeschl 2806: 	$r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<p><a href="'.$excel_filename.'">','</a>')."</p>\n");
1.2       raeburn  2807:     } elsif ($mode eq 'csv') {
                   2808:         close($CSVfile);
1.68      droeschl 2809: 	$r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '<p><a href="'.$CSVfilename.'">','</a>')."</p>\n");
1.2       raeburn  2810:         $r->rflush();
                   2811:     }
                   2812:     if ($mode eq 'autoenroll') {
                   2813:         return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4       raeburn  2814:     } else {
                   2815:         return ($usercount);
1.2       raeburn  2816:     }
1.1       raeburn  2817: }
                   2818: 
1.56      raeburn  2819: sub bulkaction_javascript {
                   2820:     my ($formname,$caller) = @_;
                   2821:     my $docstart = 'document';
                   2822:     if ($caller eq 'popup') {
                   2823:         $docstart = 'opener.document';
                   2824:     }
                   2825:     my %lt = &Apache::lonlocal::texthash(
                   2826:               acwi => 'Access will be set to start immediately',
                   2827:               asyo => 'as you did not select an end date in the pop-up window',
                   2828:               accw => 'Access will be set to continue indefinitely',
                   2829:               asyd => 'as you did not select an end date in the pop-up window',
                   2830:               sewi => "Sections will be switched to 'No section'",
                   2831:               ayes => "as you either selected the 'No section' option",
                   2832:               oryo => 'or you did not select a section in the pop-up window',
                   2833:               arol => 'A role with no section will be added',
                   2834:               swbs => 'Sections will be switched to:',
                   2835:               rwba => 'Roles will be added for section(s):',
                   2836:             );
                   2837:     my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
                   2838:     my $noaction = &mt("You need to select an action to take for the user(s) you have selected"); 
                   2839:     my $singconfirm = &mt(' for a single user?');
                   2840:     my $multconfirm = &mt(' for multiple users?');
                   2841:     my $output = <<"ENDJS";
                   2842: function verify_action (field) {
                   2843:     var numchecked = 0;
                   2844:     var singconf = '$singconfirm';
                   2845:     var multconf = '$multconfirm';
                   2846:     if ($docstart.$formname.elements[field].length > 0) {
                   2847:         for (i=0; i<$docstart.$formname.elements[field].length; i++) {
                   2848:             if ($docstart.$formname.elements[field][i].checked == true) {
                   2849:                numchecked ++;
                   2850:             }
                   2851:         }
                   2852:     } else {
                   2853:         if ($docstart.$formname.elements[field].checked == true) {
                   2854:             numchecked ++;
                   2855:         }
                   2856:     }
                   2857:     if (numchecked == 0) {
                   2858:         alert("$alert");
                   2859:         return;
                   2860:     } else {
                   2861:         var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text;
                   2862:         var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value;
                   2863:         if (choice == '') {
                   2864:             alert("$noaction");
                   2865:             return;
                   2866:         } else {
                   2867:             if (numchecked == 1) {
                   2868:                 message += singconf;
                   2869:             } else {
                   2870:                 message += multconf;
                   2871:             }
                   2872: ENDJS
                   2873:     if ($caller ne 'popup') {
                   2874:         $output .= <<"NEWWIN";
                   2875:             if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') {
                   2876:                 opendatebrowser(document.$formname,'$formname','go');
                   2877:                 return;
                   2878: 
                   2879:             } else {
                   2880:                 if (confirm(message)) {
                   2881:                     document.$formname.phase.value = 'bulkchange';
                   2882:                     document.$formname.submit();
                   2883:                     return;
                   2884:                 }
                   2885:             }
                   2886: NEWWIN
                   2887:     } else {
                   2888:         $output .= <<"POPUP";
                   2889:             if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
                   2890:                 var datemsg = '';
                   2891:                 if (($docstart.$formname.startdate_month.value == '') &&
                   2892:                     ($docstart.$formname.startdate_day.value  == '') &&
                   2893:                     ($docstart.$formname.startdate_year.value == '')) {
                   2894:                     datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
                   2895:                 }
                   2896:                 if (($docstart.$formname.enddate_month.value == '') &&
                   2897:                     ($docstart.$formname.enddate_day.value  == '') &&
                   2898:                     ($docstart.$formname.enddate_year.value == '')) {
                   2899:                     datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
                   2900:                 }
                   2901:                 if (datemsg != '') {
                   2902:                     message += "\\n"+datemsg;
                   2903:                 }
                   2904:             }
                   2905:             if (choice == 'chgsec') {
                   2906:                 var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value;
                   2907:                 var retained =  $docstart.$formname.retainsec.value;
                   2908:                 var secshow = $docstart.$formname.newsecs.value;
                   2909:                 if (secshow == '') {
                   2910:                     if (rolefilter == 'st' || retained == 0 || retained == "") {
                   2911:                         message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
                   2912:                     } else {
                   2913:                         message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
                   2914:                     }
                   2915:                 } else {
                   2916:                     if (rolefilter == 'st' || retained == 0 || retained == "") {
                   2917:                         message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
                   2918:                     } else {
                   2919:                         message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
                   2920:                     }
                   2921:                 }
                   2922:             }
                   2923:             if (confirm(message)) {
                   2924:                 $docstart.$formname.phase.value = 'bulkchange';
                   2925:                 $docstart.$formname.submit();
                   2926:                 window.close();
                   2927:             }
                   2928: POPUP
                   2929:     }
                   2930:     $output .= '
                   2931:         }
                   2932:     }
                   2933: }
                   2934: ';
                   2935:     return $output;
                   2936: }
                   2937: 
1.10      raeburn  2938: sub print_username_link {
1.48      raeburn  2939:     my ($mode,$in) = @_;
1.10      raeburn  2940:     my $output;
1.16      raeburn  2941:     if ($mode eq 'autoenroll') {
                   2942:         $output = $in->{'username'};
1.10      raeburn  2943:     } else {
                   2944:         $output = '<a href="javascript:username_display_launch('.
1.97.2.13  raeburn  2945:                   "'$in->{'username'}','$in->{'domain'}'".')">'.
1.10      raeburn  2946:                   $in->{'username'}.'</a>';
                   2947:     }
                   2948:     return $output;
                   2949: }
                   2950: 
1.2       raeburn  2951: sub role_type_names {
                   2952:     my %lt = &Apache::lonlocal::texthash (
1.13      raeburn  2953:                          'domain' => 'Domain Roles',
                   2954:                          'author' => 'Co-Author Roles',
                   2955:                          'course' => 'Course Roles',
1.97.2.4  raeburn  2956:                          'community' => 'Community Roles',
                   2957: 
1.2       raeburn  2958:              );
                   2959:     return %lt;
                   2960: }
                   2961: 
1.11      raeburn  2962: sub select_actions {
1.55      raeburn  2963:     my ($context,$setting,$statusmode,$formname) = @_;
1.11      raeburn  2964:     my %lt = &Apache::lonlocal::texthash(
                   2965:                 revoke   => "Revoke user roles",
                   2966:                 delete   => "Delete user roles",
                   2967:                 reenable => "Re-enable expired user roles",
                   2968:                 activate => "Make future user roles active now",
                   2969:                 chgdates  => "Change starting/ending dates",
                   2970:                 chgsec   => "Change section associated with user roles",
                   2971:     );
                   2972:     my ($output,$options,%choices);
1.23      raeburn  2973:     # FIXME Disable actions for now for roletype=course in domain context
                   2974:     if ($context eq 'domain' && $setting eq 'course') {
                   2975:         return;
                   2976:     }
1.26      raeburn  2977:     if ($context eq 'course') {
                   2978:         if ($env{'form.showrole'} ne 'Any') {
                   2979:              if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
                   2980:                                            $env{'request.course.id'})) {
                   2981:                  if ($env{'request.course.sec'} eq '') {
                   2982:                      return;
                   2983:                  } else {
                   2984:                      if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
                   2985:                          return;
                   2986:                      }
                   2987:                  }
                   2988:             }
                   2989:         }
                   2990:     }
1.11      raeburn  2991:     if ($statusmode eq 'Any') {
                   2992:         $options .= '
                   2993: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
                   2994:         $choices{'dates'} = 1;
                   2995:     } else {
                   2996:         if ($statusmode eq 'Future') {
                   2997:             $options .= '
                   2998: <option value="activate">'.$lt{'activate'}.'</option>';
                   2999:             $choices{'dates'} = 1;
                   3000:         } elsif ($statusmode eq 'Expired') {
                   3001:             $options .= '
                   3002: <option value="reenable">'.$lt{'reenable'}.'</option>';
                   3003:             $choices{'dates'} = 1;
                   3004:         }
1.13      raeburn  3005:         if ($statusmode eq 'Active' || $statusmode eq 'Future') {
                   3006:             $options .= '
                   3007: <option value="chgdates">'.$lt{'chgdates'}.'</option>
                   3008: <option value="revoke">'.$lt{'revoke'}.'</option>';
                   3009:             $choices{'dates'} = 1;
                   3010:         }
1.11      raeburn  3011:     }
                   3012:     if ($context eq 'domain') {
                   3013:         $options .= '
                   3014: <option value="delete">'.$lt{'delete'}.'</option>';
                   3015:     }
                   3016:     if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26      raeburn  3017:         if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11      raeburn  3018:             $options .= '
                   3019: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
                   3020:             $choices{'sections'} = 1;
                   3021:         }
                   3022:     }
                   3023:     if ($options) {
1.56      raeburn  3024:         $output = '<select name="bulkaction">'."\n".
1.11      raeburn  3025:                   '<option value="" selected="selected">'.
                   3026:                   &mt('Please select').'</option>'."\n".$options."\n".'</select>';
                   3027:         if ($choices{'dates'}) {
                   3028:             $output .= 
                   3029:                 '<input type="hidden" name="startdate_month" value="" />'."\n".
                   3030:                 '<input type="hidden" name="startdate_day" value="" />'."\n".
                   3031:                 '<input type="hidden" name="startdate_year" value="" />'."\n".
                   3032:                 '<input type="hidden" name="startdate_hour" value="" />'."\n".
                   3033:                 '<input type="hidden" name="startdate_minute" value="" />'."\n".
                   3034:                 '<input type="hidden" name="startdate_second" value="" />'."\n".
                   3035:                 '<input type="hidden" name="enddate_month" value="" />'."\n".
                   3036:                 '<input type="hidden" name="enddate_day" value="" />'."\n".
                   3037:                 '<input type="hidden" name="enddate_year" value="" />'."\n".
                   3038:                 '<input type="hidden" name="enddate_hour" value="" />'."\n".
                   3039:                 '<input type="hidden" name="enddate_minute" value="" />'."\n".
1.56      raeburn  3040:                 '<input type="hidden" name="enddate_second" value="" />'."\n".
                   3041:                 '<input type="hidden" name="no_end_date" value="" />'."\n";
1.11      raeburn  3042:             if ($context eq 'course') {
                   3043:                 $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
                   3044:             }
                   3045:         }
                   3046:         if ($choices{'sections'}) {
1.91      bisitz   3047:             $output .= '<input type="hidden" name="retainsec" value="" />'."\n".
                   3048:                        '<input type="hidden" name="newsecs" value="" />'."\n";
1.11      raeburn  3049:         }
                   3050:     }
                   3051:     return $output;
                   3052: }
                   3053: 
                   3054: sub date_section_javascript {
                   3055:     my ($context,$setting) = @_;
1.49      raeburn  3056:     my $title = 'Date_And_Section_Selector';
1.41      raeburn  3057:     my %nopopup = &Apache::lonlocal::texthash (
                   3058:         revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
                   3059:         delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
                   3060:         none   => "Choose an action to take for selected users",
                   3061:     );  
1.96      bisitz   3062:     my $output = <<"ENDONE";
                   3063: <script type="text/javascript">
                   3064: // <![CDATA[
1.41      raeburn  3065:     function opendatebrowser(callingform,formname,calledby) {
1.11      raeburn  3066:         var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
                   3067:         var url = '/adm/createuser?';
                   3068:         var type = '';
                   3069:         var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
                   3070: ENDONE
                   3071:     if ($context eq 'domain') {
                   3072:         $output .= '
                   3073:         type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
                   3074: ';
                   3075:     }
                   3076:     my $width= '700';
                   3077:     my $height = '400';
                   3078:     $output .= <<"ENDTWO";
                   3079:         url += 'action=dateselect&callingform=' + formname + 
                   3080:                '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
                   3081:         var title = '$title';
                   3082:         var options = 'scrollbars=1,resizable=1,menubar=0';
                   3083:         options += ',width=$width,height=$height';
                   3084:         stdeditbrowser = open(url,title,options,'1');
                   3085:         stdeditbrowser.focus();
                   3086:     }
1.96      bisitz   3087: // ]]>
1.11      raeburn  3088: </script>
                   3089: ENDTWO
                   3090:     return $output;
                   3091: }
                   3092: 
                   3093: sub date_section_selector {
1.97.2.4  raeburn  3094:     my ($context,$permission,$crstype) = @_;
1.11      raeburn  3095:     my $callingform = $env{'form.callingform'};
                   3096:     my $formname = 'dateselect';  
                   3097:     my $groupslist = &get_groupslist();
                   3098:     my $sec_js = &setsections_javascript($formname,$groupslist);
                   3099:     my $output = <<"END";
                   3100: <script type="text/javascript">
1.96      bisitz   3101: // <![CDATA[
1.11      raeburn  3102: 
                   3103: $sec_js
                   3104: 
                   3105: function saveselections(formname) {
                   3106: 
                   3107: END
                   3108:     if ($env{'form.bulkaction'} eq 'chgsec') {
                   3109:         $output .= <<"END";
1.40      raeburn  3110:         if (formname.retainsec.length > 1) {  
                   3111:             for (var i=0; i<formname.retainsec.length; i++) {
                   3112:                 if (formname.retainsec[i].checked == true) {
                   3113:                     opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
                   3114:                 }
                   3115:             }
                   3116:         } else {
                   3117:             opener.document.$callingform.retainsec.value = formname.retainsec.value;
                   3118:         }
1.97.2.6  raeburn  3119:         setSections(formname,'$crstype');
1.11      raeburn  3120:         if (seccheck == 'ok') {
                   3121:             opener.document.$callingform.newsecs.value = formname.sections.value;
                   3122:         }
                   3123: END
                   3124:     } else {
                   3125:         if ($context eq 'course') {
                   3126:             if (($env{'form.bulkaction'} eq 'reenable') || 
                   3127:                 ($env{'form.bulkaction'} eq 'activate') || 
                   3128:                 ($env{'form.bulkaction'} eq 'chgdates')) {
1.26      raeburn  3129:                 if ($env{'request.course.sec'} eq '') {
                   3130:                     $output .= <<"END";
1.11      raeburn  3131:  
                   3132:         if (formname.makedatesdefault.checked == true) {
                   3133:             opener.document.$callingform.makedatesdefault.value = 1;
                   3134:         }
                   3135:         else {
                   3136:             opener.document.$callingform.makedatesdefault.value = 0;
                   3137:         }
                   3138: 
                   3139: END
1.26      raeburn  3140:                 }
1.11      raeburn  3141:             }
                   3142:         }
                   3143:         $output .= <<"END";
                   3144:     opener.document.$callingform.startdate_month.value =  formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
                   3145:     opener.document.$callingform.startdate_day.value =  formname.startdate_day.value;
                   3146:     opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
                   3147:     opener.document.$callingform.startdate_hour.value =  formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
                   3148:     opener.document.$callingform.startdate_minute.value =  formname.startdate_minute.value;
                   3149:     opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
                   3150:     opener.document.$callingform.enddate_month.value =  formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
                   3151:     opener.document.$callingform.enddate_day.value =  formname.enddate_day.value;
                   3152:     opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
                   3153:     opener.document.$callingform.enddate_hour.value =  formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
                   3154:     opener.document.$callingform.enddate_minute.value =  formname.enddate_minute.value;
                   3155:     opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
1.56      raeburn  3156:     if (formname.no_end_date.checked) {
                   3157:         opener.document.$callingform.no_end_date.value = '1';
                   3158:     } else {
                   3159:         opener.document.$callingform.no_end_date.value = '0';
                   3160:     }
1.11      raeburn  3161: END
                   3162:     }
1.56      raeburn  3163:     my $verify_action_js = &bulkaction_javascript($callingform,'popup');
                   3164:     $output .= <<"ENDJS";
                   3165:     verify_action('actionlist');
1.11      raeburn  3166: }
1.56      raeburn  3167: 
                   3168: $verify_action_js
                   3169: 
1.96      bisitz   3170: // ]]>
1.11      raeburn  3171: </script>
1.56      raeburn  3172: ENDJS
1.11      raeburn  3173:     my %lt = &Apache::lonlocal::texthash (
                   3174:                  chac => 'Access dates to apply for selected users',
                   3175:                  chse => 'Changes in section affiliation to apply to selected users',
                   3176:                  fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
                   3177:                  forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
                   3178:                  reta => "Retain each user's current section affiliations?", 
1.97.2.6  raeburn  3179:                  dnap => '(Does not apply to student roles).',
1.11      raeburn  3180:             );
                   3181:     my ($date_items,$headertext);
                   3182:     if ($env{'form.bulkaction'} eq 'chgsec') {
                   3183:         $headertext = $lt{'chse'};
                   3184:     } else {
                   3185:         $headertext = $lt{'chac'};
                   3186:         my $starttime;
                   3187:         if (($env{'form.bulkaction'} eq 'activate') || 
                   3188:             ($env{'form.bulkaction'} eq 'reenable')) {
                   3189:             $starttime = time;
                   3190:         }
                   3191:         $date_items = &date_setting_table($starttime,undef,$context,
1.21      raeburn  3192:                                           $env{'form.bulkaction'},$formname,
1.97.2.4  raeburn  3193:                                           $permission,$crstype);
1.11      raeburn  3194:     }
                   3195:     $output .= '<h3>'.$headertext.'</h3>'.
                   3196:                '<form name="'.$formname.'" method="post">'."\n".
                   3197:                 $date_items;
                   3198:     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17      raeburn  3199:         my ($cnum,$cdom) = &get_course_identity();
1.97.2.6  raeburn  3200:         my $crstype = &Apache::loncommon::course_type();
                   3201:         if ($crstype eq 'Community') {
                   3202:             $lt{'fors'} = &mt('For member roles changing the section, will result in a section switch as members may only be in one section of a community at a time.');
                   3203:             $lt{'forn'} = &mt('For a role in a community that is not a member role, a user may have roles in more than one section of a community at a time.');
                   3204:             $lt{'dnap'} = &mt('(Does not apply to member roles).'); 
                   3205:         }
1.11      raeburn  3206:         my $info;
                   3207:         if ($env{'form.showrole'} eq 'st') {
                   3208:             $output .= '<p>'.$lt{'fors'}.'</p>'; 
1.26      raeburn  3209:         } elsif ($env{'form.showrole'} eq 'Any') {
1.11      raeburn  3210:             $output .= '<p>'.$lt{'fors'}.'</p>'.
                   3211:                        '<p>'.$lt{'forn'}.'&nbsp;';
                   3212:             $info = $lt{'reta'};
                   3213:         } else {
                   3214:             $output .= '<p>'.$lt{'forn'}.'&nbsp;';
                   3215:             $info = $lt{'reta'};
                   3216:         }
                   3217:         if ($info) {
                   3218:             $info .= '<span class="LC_nobreak">'.
                   3219:                      '<label><input type="radio" name="retainsec" value="1" '.
                   3220:                      'checked="checked" />'.&mt('Yes').'</label>&nbsp;&nbsp;'.
                   3221:                      '<label><input type="radio" name="retainsec" value="0" />'.
                   3222:                      &mt('No').'</label></span>';
                   3223:             if ($env{'form.showrole'} eq 'Any') {
                   3224:                 $info .= '<br />'.$lt{'dnap'};
                   3225:             }
                   3226:             $info .= '</p>';
                   3227:         } else {
                   3228:             $info = '<input type="hidden" name="retainsec" value="0" />'; 
                   3229:         }
1.21      raeburn  3230:         my $rowtitle = &mt('New section to assign');
1.97.2.4  raeburn  3231:         my $secbox = &section_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context,'',$crstype);
1.11      raeburn  3232:         $output .= $info.$secbox;
                   3233:     }
                   3234:     $output .= '<p>'.
1.81      schafran 3235: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
1.11      raeburn  3236: '</form>';
                   3237:     return $output;
                   3238: }
                   3239: 
1.17      raeburn  3240: sub section_picker {
1.97.2.4  raeburn  3241:     my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
1.17      raeburn  3242:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                   3243:     my $sections_select .= &course_sections(\%sections_count,$role);
                   3244:     my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
                   3245:     if ($mode eq 'upload') {
                   3246:         my ($options,$cb_script,$coursepick) =
1.97.2.4  raeburn  3247:             &default_role_selector($context,1,$crstype);
1.59      bisitz   3248:         $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
1.17      raeburn  3249:                    $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
                   3250:     }
                   3251:     $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
                   3252:     if ($env{'request.course.sec'} eq '') {
                   3253:         $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
                   3254:                    '<td align="center">'.&mt('Existing sections')."\n".
                   3255:                    '<br />'.$sections_select.'</td><td align="center">'.
                   3256:                    &mt('New section').'<br />'."\n".
                   3257:                    '<input type="text" name="newsec" size="15" />'."\n".
                   3258:                    '<input type="hidden" name="sections" value="" />'."\n".
                   3259:                    '</td></tr></table>'."\n";
                   3260:     } else {
                   3261:        $secbox .= '<input type="hidden" name="sections" value="'.
                   3262:                    $env{'request.course.sec'}.'" />'.
                   3263:                    $env{'request.course.sec'};
                   3264:     }
                   3265:     $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
                   3266:                &Apache::lonhtmlcommon::end_pick_box().'</p>';
                   3267:     return $secbox;
                   3268: }
                   3269: 
1.2       raeburn  3270: sub results_header_row {
1.97.2.5  raeburn  3271:     my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
1.5       raeburn  3272:     my ($description,$showfilter);
                   3273:     if ($rolefilter ne 'Any') {
                   3274:         $showfilter = $rolefilter;
                   3275:     }
1.2       raeburn  3276:     if ($context eq 'course') {
1.24      raeburn  3277:         if ($mode eq 'csv' || $mode eq 'excel') {
1.97.2.5  raeburn  3278:             if ($crstype eq 'Community') {
                   3279:                 $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
                   3280:             } else {
                   3281:                 $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
                   3282:             }
1.24      raeburn  3283:         }
1.2       raeburn  3284:         if ($statusmode eq 'Expired') {
1.97.2.5  raeburn  3285:             if ($crstype eq 'Community') {
                   3286:                 $description .= &mt('Users in community with expired [_1] roles',$showfilter);
                   3287:             } else {
                   3288:                 $description .= &mt('Users in course with expired [_1] roles',$showfilter);
                   3289:             }
1.11      raeburn  3290:         } elsif ($statusmode eq 'Future') {
1.97.2.5  raeburn  3291:             if ($crstype eq 'Community') {
                   3292:                 $description .= &mt('Users in community with future [_1] roles',$showfilter);
                   3293:             } else {
                   3294:                 $description .= &mt('Users in course with future [_1] roles',$showfilter);
                   3295:             }
1.2       raeburn  3296:         } elsif ($statusmode eq 'Active') {
1.97.2.5  raeburn  3297:             if ($crstype eq 'Community') {
                   3298:                 $description .= &mt('Users in community with active [_1] roles',$showfilter);
                   3299:             } else {
                   3300:                 $description .= &mt('Users in course with active [_1] roles',$showfilter);
                   3301:             }
1.2       raeburn  3302:         } else {
                   3303:             if ($rolefilter eq 'Any') {
1.97.2.5  raeburn  3304:                 if ($crstype eq 'Community') {
                   3305:                     $description .= &mt('All users in community');
                   3306:                 } else {
                   3307:                     $description .= &mt('All users in course');
                   3308:                 }
1.2       raeburn  3309:             } else {
1.97.2.5  raeburn  3310:                 if ($crstype eq 'Community') {
                   3311:                     $description .= &mt('All users in community with [_1] roles',$rolefilter);
                   3312:                 } else {
                   3313:                     $description .= &mt('All users in course with [_1] roles',$rolefilter);
                   3314:                 }
1.2       raeburn  3315:             }
                   3316:         }
1.33      raeburn  3317:         my $constraint;
1.26      raeburn  3318:         my $viewablesec = &viewable_section($permission);
                   3319:         if ($viewablesec ne '') {
1.15      raeburn  3320:             if ($env{'form.showrole'} eq 'st') {
1.33      raeburn  3321:                 $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.97.2.6  raeburn  3322:             } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
1.33      raeburn  3323:                 $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
                   3324:             }
                   3325:             if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
                   3326:                 if ($env{'form.grpfilter'} eq 'none') {
                   3327:                     $constraint .= &mt(' and not in any group');
                   3328:                 } else {
                   3329:                     $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
                   3330:                 }
                   3331:             }
                   3332:         } else {
                   3333:             if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
                   3334:                 if ($env{'form.secfilter'} eq 'none') {
                   3335:                     $constraint = &mt('only users affiliated with no section');
                   3336:                 } else {
                   3337:                     $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
                   3338:                 }
                   3339:             }
                   3340:             if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
                   3341:                 if ($env{'form.grpfilter'} eq 'none') {
                   3342:                     if ($constraint eq '') {
                   3343:                         $constraint = &mt('only users not in any group');
                   3344:                     } else {
                   3345:                         $constraint .= &mt(' and also not in any group'); 
                   3346:                     }
                   3347:                 } else {
                   3348:                     if ($constraint eq '') {
                   3349:                         $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
                   3350:                     } else {
                   3351:                         $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
                   3352:                     }
                   3353:                 }
1.15      raeburn  3354:             }
                   3355:         }
1.33      raeburn  3356:         if ($constraint ne '') {
                   3357:             $description .= ' ('.$constraint.')';
                   3358:         } 
1.13      raeburn  3359:     } elsif ($context eq 'author') {
1.14      raeburn  3360:         $description = 
1.73      bisitz   3361:             &mt('Author space for [_1]'
                   3362:                 ,'<span class="LC_cusr_emph">'
                   3363:                 .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})
                   3364:                 .'</span>')
                   3365:             .':&nbsp;&nbsp;';
1.2       raeburn  3366:         if ($statusmode eq 'Expired') {
1.5       raeburn  3367:             $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2       raeburn  3368:         } elsif ($statusmode eq 'Future') {
1.5       raeburn  3369:             $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2       raeburn  3370:         } elsif ($statusmode eq 'Active') {
1.5       raeburn  3371:             $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2       raeburn  3372:         } else {
                   3373:             if ($rolefilter eq 'Any') {
1.5       raeburn  3374:                 $description .= &mt('All co-authors');
1.2       raeburn  3375:             } else {
                   3376:                 $description .= &mt('All co-authors with [_1] roles',$rolefilter);
                   3377:             }
                   3378:         }
                   3379:     } elsif ($context eq 'domain') {
                   3380:         my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.73      bisitz   3381:         $description = &mt('Domain - [_1]:',$domdesc).' ';
1.2       raeburn  3382:         if ($env{'form.roletype'} eq 'domain') {
                   3383:             if ($statusmode eq 'Expired') {
1.5       raeburn  3384:                 $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2       raeburn  3385:             } elsif ($statusmode eq 'Future') {
1.5       raeburn  3386:                 $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2       raeburn  3387:             } elsif ($statusmode eq 'Active') {
1.5       raeburn  3388:                 $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2       raeburn  3389:             } else {
                   3390:                 if ($rolefilter eq 'Any') {
1.5       raeburn  3391:                     $description .= &mt('All users in domain');
1.2       raeburn  3392:                 } else {
                   3393:                     $description .= &mt('All users in domain with [_1] roles',$rolefilter);
                   3394:                 }
                   3395:             }
1.13      raeburn  3396:         } elsif ($env{'form.roletype'} eq 'author') {
1.2       raeburn  3397:             if ($statusmode eq 'Expired') {
1.5       raeburn  3398:                 $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2       raeburn  3399:             } elsif ($statusmode eq 'Future') {
1.5       raeburn  3400:                 $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2       raeburn  3401:             } elsif ($statusmode eq 'Active') {
1.5       raeburn  3402:                $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2       raeburn  3403:             } else {
                   3404:                 if ($rolefilter eq 'Any') {
1.5       raeburn  3405:                     $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2       raeburn  3406:                 } else {
                   3407:                     $description .= &mt('All co-authors in domain  with [_1] roles',$rolefilter);
                   3408:                 }
                   3409:             }
1.97.2.5  raeburn  3410:         } elsif (($env{'form.roletype'} eq 'course') || 
                   3411:                  ($env{'form.roletype'} eq 'community')) {
                   3412: 
1.2       raeburn  3413:             my $coursefilter = $env{'form.coursepick'};
1.97.2.5  raeburn  3414:             if ($env{'form.roletype'} eq 'course') {
                   3415:                 if ($coursefilter eq 'category') {
                   3416:                     my $instcode = &instcode_from_coursefilter();
                   3417:                     if ($instcode eq '.') {
                   3418:                         $description .= &mt('All courses in domain').' - ';
                   3419:                     } else {
                   3420:                         $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
                   3421:                     }
                   3422:                 } elsif ($coursefilter eq 'selected') {
                   3423:                     $description .= &mt('Selected courses in domain').' - ';
                   3424:                 } elsif ($coursefilter eq 'all') {
1.2       raeburn  3425:                     $description .= &mt('All courses in domain').' - ';
                   3426:                 }
1.97.2.5  raeburn  3427:             } elsif ($env{'form.roletype'} eq 'community') {
                   3428:                 if ($coursefilter eq 'selected') {
                   3429:                     $description .= &mt('Selected communities in domain').' - ';
                   3430:                 } elsif ($coursefilter eq 'all') {
                   3431:                     $description .= &mt('All communities in domain').' - ';
                   3432:                 }
1.2       raeburn  3433:             }
                   3434:             if ($statusmode eq 'Expired') {
1.5       raeburn  3435:                 $description .= &mt('users with expired [_1] roles',$showfilter);
1.2       raeburn  3436:             } elsif ($statusmode eq 'Future') {
1.5       raeburn  3437:                 $description .= &mt('users with future [_1] roles',$showfilter);
1.2       raeburn  3438:             } elsif ($statusmode eq 'Active') {
1.5       raeburn  3439:                 $description .= &mt('users with active [_1] roles',$showfilter);
1.2       raeburn  3440:             } else {
                   3441:                 if ($rolefilter eq 'Any') {
                   3442:                     $description .= &mt('all users');
                   3443:                 } else {
                   3444:                     $description .= &mt('users with [_1] roles',$rolefilter);
                   3445:                 }
                   3446:             }
                   3447:         }
                   3448:     }
                   3449:     return $description;
                   3450: }
1.22      raeburn  3451: 
                   3452: sub viewable_section {
                   3453:     my ($permission) = @_;
                   3454:     my $viewablesec;
                   3455:     if (ref($permission) eq 'HASH') {
                   3456:         if (exists($permission->{'view_section'})) {
                   3457:             $viewablesec = $permission->{'view_section'};
                   3458:         } elsif (exists($permission->{'cusr_section'})) {
                   3459:             $viewablesec = $permission->{'cusr_section'};
                   3460:         }
                   3461:     }
                   3462:     return $viewablesec;
                   3463: }
                   3464: 
1.2       raeburn  3465:     
1.1       raeburn  3466: #################################################
                   3467: #################################################
                   3468: sub show_drop_list {
1.97.2.4  raeburn  3469:     my ($r,$classlist,$nosort,$permission,$crstype) = @_;
1.29      raeburn  3470:     my $cid = $env{'request.course.id'};
1.17      raeburn  3471:     my ($cnum,$cdom) = &get_course_identity($cid);
1.1       raeburn  3472:     if (! exists($env{'form.sortby'})) {
                   3473:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   3474:                                                 ['sortby']);
                   3475:     }
                   3476:     my $sortby = $env{'form.sortby'};
                   3477:     if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
                   3478:         $sortby = 'username';
                   3479:     }
                   3480:     my $action = "drop";
1.17      raeburn  3481:     my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1       raeburn  3482:     $r->print(<<END);
                   3483: <input type="hidden" name="sortby" value="$sortby" />
                   3484: <input type="hidden" name="action" value="$action" />
                   3485: <input type="hidden" name="state"  value="done" />
1.17      raeburn  3486: <script type="text/javascript" language="Javascript">
1.96      bisitz   3487: // <![CDATA[
1.17      raeburn  3488: $check_uncheck_js
1.96      bisitz   3489: // ]]>
1.1       raeburn  3490: </script>
                   3491: <p>
1.86      bisitz   3492: <input type="hidden" name="phase" value="four" />
1.1       raeburn  3493: END
1.30      raeburn  3494:     my ($indexhash,$keylist) = &make_keylist_array();
                   3495:     my $studentcount = 0;
                   3496:     if (ref($classlist) eq 'HASH') {
                   3497:         foreach my $student (keys(%{$classlist})) {
                   3498:             my $sdata = $classlist->{$student}; 
                   3499:             my $status = $sdata->[$indexhash->{'status'}];
                   3500:             my $section = $sdata->[$indexhash->{'section'}];
                   3501:             if ($status ne 'Active') {
                   3502:                 delete($classlist->{$student});
                   3503:                 next;
                   3504:             }
                   3505:             if ($env{'request.course.sec'} ne '') {
                   3506:                 if ($section ne $env{'request.course.sec'}) {
                   3507:                     delete($classlist->{$student});
                   3508:                     next;
                   3509:                 }
                   3510:             }
                   3511:             $studentcount ++;
                   3512:         }
                   3513:     }
                   3514:     if (!$studentcount) {
1.97.2.4  raeburn  3515:         if ($crstype eq 'Community') {
                   3516:             $r->print(&mt('There are no members to drop.'));
                   3517:         } else {
                   3518:             $r->print(&mt('There are no students to drop.'));
                   3519:         }
1.30      raeburn  3520:         return;
                   3521:     }
                   3522:     my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
                   3523:                                               $classlist,$keylist,$cdom,$cnum);
                   3524:     my %lt=&Apache::lonlocal::texthash('usrn'   => "username",
                   3525:                                        'dom'    => "domain",
                   3526:                                        'sn'     => "student name",
1.97.2.4  raeburn  3527:                                        'mn'     => "member name",
1.30      raeburn  3528:                                        'sec'    => "section",
                   3529:                                        'start'  => "start date",
                   3530:                                        'end'    => "end date",
                   3531:                                        'groups' => "active groups",
                   3532:                                       );
1.97.2.4  raeburn  3533:     my $nametitle = $lt{'sn'};
                   3534:     if ($crstype eq 'Community') {
                   3535:         $nametitle = $lt{'mn'};
                   3536:     }
1.1       raeburn  3537:     if ($nosort) {
1.17      raeburn  3538:         $r->print(&Apache::loncommon::start_data_table().
                   3539:                   &Apache::loncommon::start_data_table_header_row());
1.1       raeburn  3540:         $r->print(<<END);
                   3541:     <th>&nbsp;</th>
                   3542:     <th>$lt{'usrn'}</th>
                   3543:     <th>$lt{'dom'}</th>
                   3544:     <th>ID</th>
1.97.2.4  raeburn  3545:     <th>$nametitle</th>
1.1       raeburn  3546:     <th>$lt{'sec'}</th>
                   3547:     <th>$lt{'start'}</th>
                   3548:     <th>$lt{'end'}</th>
                   3549:     <th>$lt{'groups'}</th>
                   3550: END
1.17      raeburn  3551:         $r->print(&Apache::loncommon::end_data_table_header_row());
1.1       raeburn  3552:     } else  {
1.17      raeburn  3553:         $r->print(&Apache::loncommon::start_data_table().
                   3554:                   &Apache::loncommon::start_data_table_header_row());
1.1       raeburn  3555:         $r->print(<<END);
1.17      raeburn  3556:     <th>&nbsp;</th>
1.1       raeburn  3557:     <th>
1.17      raeburn  3558:        <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1       raeburn  3559:     </th><th>
1.17      raeburn  3560:        <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1       raeburn  3561:     </th><th>
1.17      raeburn  3562:        <a href="/adm/createuser?action=$action&sortby=id">ID</a>
1.1       raeburn  3563:     </th><th>
1.97.2.4  raeburn  3564:        <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
1.1       raeburn  3565:     </th><th>
1.17      raeburn  3566:        <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1       raeburn  3567:     </th><th>
1.17      raeburn  3568:        <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1       raeburn  3569:     </th><th>
1.17      raeburn  3570:        <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1       raeburn  3571:     </th><th>
1.17      raeburn  3572:        <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1       raeburn  3573:     </th>
                   3574: END
1.17      raeburn  3575:         $r->print(&Apache::loncommon::end_data_table_header_row());
1.1       raeburn  3576:     }
                   3577:     #
                   3578:     # Sort the students
1.30      raeburn  3579:     my $index  = $indexhash->{$sortby};
                   3580:     my $second = $indexhash->{'username'};
                   3581:     my $third  = $indexhash->{'domain'};
1.1       raeburn  3582:     my @Sorted_Students = sort {
                   3583:         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
                   3584:             ||
                   3585:         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
                   3586:             ||
                   3587:         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30      raeburn  3588:         } (keys(%{$classlist}));
1.1       raeburn  3589:     foreach my $student (@Sorted_Students) {
                   3590:         my $error;
                   3591:         my $sdata = $classlist->{$student};
1.30      raeburn  3592:         my $username = $sdata->[$indexhash->{'username'}];
                   3593:         my $domain   = $sdata->[$indexhash->{'domain'}];
                   3594:         my $section  = $sdata->[$indexhash->{'section'}];
                   3595:         my $name     = $sdata->[$indexhash->{'fullname'}];
                   3596:         my $id       = $sdata->[$indexhash->{'id'}];
                   3597:         my $start    = $sdata->[$indexhash->{'start'}];
                   3598:         my $end      = $sdata->[$indexhash->{'end'}];
1.1       raeburn  3599:         my $groups = $classgroups->{$student};
                   3600:         my $active_groups;
                   3601:         if (ref($groups->{active}) eq 'HASH') {
                   3602:             $active_groups = join(', ',keys(%{$groups->{'active'}}));
                   3603:         }
                   3604:         if (! defined($start) || $start == 0) {
                   3605:             $start = &mt('none');
                   3606:         } else {
                   3607:             $start = &Apache::lonlocal::locallocaltime($start);
                   3608:         }
                   3609:         if (! defined($end) || $end == 0) {
                   3610:             $end = &mt('none');
                   3611:         } else {
                   3612:             $end = &Apache::lonlocal::locallocaltime($end);
                   3613:         }
1.17      raeburn  3614:         my $studentkey = $student.':'.$section;
1.30      raeburn  3615:         my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1       raeburn  3616:         #
                   3617:         $r->print(&Apache::loncommon::start_data_table_row());
                   3618:         $r->print(<<"END");
1.86      bisitz   3619:     <td><input type="checkbox" name="droplist" value="$studentkey" /></td>
1.1       raeburn  3620:     <td>$username</td>
                   3621:     <td>$domain</td>
                   3622:     <td>$id</td>
                   3623:     <td>$name</td>
                   3624:     <td>$section</td>
1.29      raeburn  3625:     <td>$start $startitem</td>
1.1       raeburn  3626:     <td>$end</td>
                   3627:     <td>$active_groups</td>
                   3628: END
                   3629:         $r->print(&Apache::loncommon::end_data_table_row());
                   3630:     }
                   3631:     $r->print(&Apache::loncommon::end_data_table().'<br />');
                   3632:     %lt=&Apache::lonlocal::texthash(
1.29      raeburn  3633:                        'dp'   => "Drop Students",
1.97.2.4  raeburn  3634:                        'dm'   => "Drop Members",
1.1       raeburn  3635:                        'ca'   => "check all",
                   3636:                        'ua'   => "uncheck all",
                   3637:                                        );
1.97.2.4  raeburn  3638:     my $btn = $lt{'dp'};
                   3639:     if ($crstype eq 'Community') {
                   3640:         $btn = $lt{'dm'}; 
                   3641:     }
1.1       raeburn  3642:     $r->print(<<"END");
1.89      bisitz   3643: </p>
                   3644: <p>
1.86      bisitz   3645: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" /> &nbsp;
                   3646: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
1.89      bisitz   3647: </p>
                   3648: <p>
1.97.2.4  raeburn  3649: <input type="submit" value="$btn" />
1.89      bisitz   3650: </p>
1.1       raeburn  3651: END
                   3652:     return;
                   3653: }
                   3654: 
                   3655: #
                   3656: # Print out the initial form to get the file containing a list of users
                   3657: #
                   3658: sub print_first_users_upload_form {
                   3659:     my ($r,$context) = @_;
                   3660:     my $str;
1.86      bisitz   3661:     $str  = '<input type="hidden" name="phase" value="two" />';
1.1       raeburn  3662:     $str .= '<input type="hidden" name="action" value="upload" />';
1.97.2.4  raeburn  3663:     $str .= '<input type="hidden" name="state"  value="got_file" />';
                   3664: 
1.95      bisitz   3665: 
1.85      bisitz   3666:     $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
1.95      bisitz   3667: 
                   3668:     # Excel and CSV Help
1.97.2.9  raeburn  3669:     $str .= '<div class="LC_left_float">'
1.95      bisitz   3670:            .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
                   3671:                 &mt("How do I create a users list from a spreadsheet"))
1.97.2.9  raeburn  3672:            .'</div><div class="LC_left_float">'."\n"
1.95      bisitz   3673:            .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
                   3674:                 &mt("How do I create a CSV file from a spreadsheet"))
1.97.2.9  raeburn  3675:            .'</div><br clear="all" />'."\n";
1.95      bisitz   3676:     $str .= &Apache::lonhtmlcommon::start_pick_box()
                   3677:            .&Apache::lonhtmlcommon::row_title(&mt('File'))
                   3678:            .&Apache::loncommon::upfile_select_html()
                   3679:            .&Apache::lonhtmlcommon::row_closure()
                   3680:            .&Apache::lonhtmlcommon::row_title(
                   3681:                 '<label for="noFirstLine">'
                   3682:                .&mt('Ignore First Line')
                   3683:                .'</label>')
                   3684:            .'<input type="checkbox" name="noFirstLine" id="noFirstLine" />'
                   3685:            .&Apache::lonhtmlcommon::row_closure(1)
                   3686:            .&Apache::lonhtmlcommon::end_pick_box();
                   3687: 
                   3688:     $str .= '<p>'
                   3689:            .'<input type="submit" name="fileupload" value="'.&mt('Next').'" />'
                   3690:            .'</p>';
                   3691: 
1.1       raeburn  3692:     $r->print($str);
                   3693:     return;
                   3694: }
                   3695: 
                   3696: # ================================================= Drop/Add from uploaded file
                   3697: sub upfile_drop_add {
1.21      raeburn  3698:     my ($r,$context,$permission) = @_;
1.1       raeburn  3699:     &Apache::loncommon::load_tmp_file($r);
                   3700:     my @userdata=&Apache::loncommon::upfile_record_sep();
                   3701:     if($env{'form.noFirstLine'}){shift(@userdata);}
                   3702:     my @keyfields = split(/\,/,$env{'form.keyfields'});
                   3703:     my %fields=();
                   3704:     for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
                   3705:         if ($env{'form.upfile_associate'} eq 'reverse') {
                   3706:             if ($env{'form.f'.$i} ne 'none') {
                   3707:                 $fields{$keyfields[$i]}=$env{'form.f'.$i};
                   3708:             }
                   3709:         } else {
                   3710:             $fields{$env{'form.f'.$i}}=$keyfields[$i];
                   3711:         }
                   3712:     }
1.29      raeburn  3713:     if ($env{'form.fullup'} ne 'yes') {
                   3714:         $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
                   3715:                   '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
                   3716:     }
1.1       raeburn  3717:     #
                   3718:     # Store the field choices away
                   3719:     foreach my $field (qw/username names
1.57      raeburn  3720:                        fname mname lname gen id sec ipwd email role domain/) {
1.1       raeburn  3721:         $env{'form.'.$field.'_choice'}=$fields{$field};
                   3722:     }
                   3723:     &Apache::loncommon::store_course_settings('enrollment_upload',
                   3724:                                               { 'username_choice' => 'scalar',
                   3725:                                                 'names_choice' => 'scalar',
                   3726:                                                 'fname_choice' => 'scalar',
                   3727:                                                 'mname_choice' => 'scalar',
                   3728:                                                 'lname_choice' => 'scalar',
                   3729:                                                 'gen_choice' => 'scalar',
                   3730:                                                 'id_choice' => 'scalar',
                   3731:                                                 'sec_choice' => 'scalar',
                   3732:                                                 'ipwd_choice' => 'scalar',
                   3733:                                                 'email_choice' => 'scalar',
1.57      raeburn  3734:                                                 'role_choice'  => 'scalar',
1.84      raeburn  3735:                                                 'domain_choice' => 'scalar',
                   3736:                                                 'inststatus_choice' => 'scalar'});
1.1       raeburn  3737:     #
1.97.2.4  raeburn  3738:     my ($cid,$crstype,$setting);
                   3739:     if ($context eq 'domain') {
                   3740:         $setting = $env{'form.roleaction'};
                   3741:     }
                   3742:     if ($env{'request.course.id'} ne '') {
                   3743:         $cid = $env{'request.course.id'};
                   3744:         $crstype = &Apache::loncommon::course_type();
                   3745:     } elsif ($setting eq 'course') {
                   3746:         if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
                   3747:             $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
                   3748:             $crstype = &Apache::loncommon::course_type($cid);
                   3749:         }
                   3750:     }
1.1       raeburn  3751:     my ($startdate,$enddate) = &get_dates_from_form();
                   3752:     if ($env{'form.makedatesdefault'}) {
1.97.2.14! raeburn  3753:         $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1       raeburn  3754:     }
                   3755:     # Determine domain and desired host (home server)
1.57      raeburn  3756:     my $defdom=$env{'request.role.domain'};
                   3757:     my $domain;
                   3758:     if ($env{'form.defaultdomain'} ne '') {
                   3759:         $domain = $env{'form.defaultdomain'};
                   3760:     } else {
                   3761:         $domain = $defdom;
                   3762:     }
1.1       raeburn  3763:     my $desiredhost = $env{'form.lcserver'};
                   3764:     if (lc($desiredhost) eq 'default') {
                   3765:         $desiredhost = undef;
                   3766:     } else {
1.57      raeburn  3767:         my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1       raeburn  3768:         if (! exists($home_servers{$desiredhost})) {
                   3769:             $r->print('<span class="LC_error">'.&mt('Error').
                   3770:                       &mt('Invalid home server specified').'</span>');
                   3771:             $r->print(&Apache::loncommon::end_page());
                   3772:             return;
                   3773:         }
                   3774:     }
                   3775:     # Determine authentication mechanism
                   3776:     my $changeauth;
                   3777:     if ($context eq 'domain') {
                   3778:         $changeauth = $env{'form.changeauth'};
                   3779:     }
                   3780:     my $amode  = '';
                   3781:     my $genpwd = '';
                   3782:     if ($env{'form.login'} eq 'krb') {
                   3783:         $amode='krb';
                   3784:         $amode.=$env{'form.krbver'};
                   3785:         $genpwd=$env{'form.krbarg'};
                   3786:     } elsif ($env{'form.login'} eq 'int') {
                   3787:         $amode='internal';
                   3788:         if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
                   3789:             $genpwd=$env{'form.intarg'};
                   3790:         }
                   3791:     } elsif ($env{'form.login'} eq 'loc') {
                   3792:         $amode='localauth';
                   3793:         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
                   3794:             $genpwd=$env{'form.locarg'};
                   3795:         }
                   3796:     }
                   3797:     if ($amode =~ /^krb/) {
                   3798:         if (! defined($genpwd) || $genpwd eq '') {
                   3799:             $r->print('<span class="Error">'.
                   3800:                       &mt('Unable to enroll users').' '.
                   3801:                       &mt('No Kerberos domain was specified.').'</span></p>');
                   3802:             $amode = ''; # This causes the loop below to be skipped
                   3803:         }
                   3804:     }
1.97.2.4  raeburn  3805:     my ($defaultsec,$defaultrole);
1.1       raeburn  3806:     if ($context eq 'domain') {
                   3807:         if ($setting eq 'domain') {
                   3808:             $defaultrole = $env{'form.defaultrole'};
                   3809:         } elsif ($setting eq 'course') {
                   3810:             $defaultrole = $env{'form.courserole'};
1.27      raeburn  3811:             $defaultsec = $env{'form.sections'};
1.97.2.4  raeburn  3812:         }
1.13      raeburn  3813:     } elsif ($context eq 'author') {
1.1       raeburn  3814:         $defaultrole = $env{'form.defaultrole'};
1.27      raeburn  3815:     } elsif ($context eq 'course') {
                   3816:         $defaultrole = $env{'form.defaultrole'};
                   3817:         $defaultsec = $env{'form.sections'};
1.1       raeburn  3818:     }
1.27      raeburn  3819:     # Check to see if user information can be changed
                   3820:     my @userinfo = ('firstname','middlename','lastname','generation',
                   3821:                     'permanentemail','id');
                   3822:     my %canmodify;
                   3823:     if (&Apache::lonnet::allowed('mau',$domain)) {
1.84      raeburn  3824:         push(@userinfo,'inststatus');
1.27      raeburn  3825:         foreach my $field (@userinfo) {
                   3826:             $canmodify{$field} = 1;
                   3827:         }
                   3828:     }
                   3829:     my (%userlist,%modifiable_fields,@poss_roles);
                   3830:     my $secidx = &Apache::loncoursedata::CL_SECTION();
1.97.2.5  raeburn  3831:     my @courseroles = &roles_by_context('course',1,$crstype);
1.27      raeburn  3832:     if (!&Apache::lonnet::allowed('mau',$domain)) {
                   3833:         if ($context eq 'course' || $context eq 'author') {
1.97.2.4  raeburn  3834:             @poss_roles =  &curr_role_permissions($context,'','',$crstype);
1.27      raeburn  3835:             my @statuses = ('active','future');
                   3836:             my ($indexhash,$keylist) = &make_keylist_array();
                   3837:             my %info;
                   3838:             foreach my $role (@poss_roles) {
                   3839:                 %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
                   3840:                                                         \@userinfo,[$role]);
                   3841:             }
                   3842:             if ($context eq 'course') {
                   3843:                 my ($cnum,$cdom) = &get_course_identity();
                   3844:                 my $roster = &Apache::loncoursedata::get_classlist();
1.66      raeburn  3845:                 if (ref($roster) eq 'HASH') {
                   3846:                     %userlist = %{$roster};
                   3847:                 }
1.27      raeburn  3848:                 my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
                   3849:                                                          \@statuses,\@poss_roles);
                   3850:                 &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
                   3851:                                 \%advrolehash,$permission);
                   3852:             } elsif ($context eq 'author') {
                   3853:                 my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
                   3854:                                                   \@statuses,\@poss_roles);
                   3855:                 &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
                   3856:                              \%cstr_roles,$permission);
                   3857: 
                   3858:             }
                   3859:         }
1.1       raeburn  3860:     }
                   3861:     if ( $domain eq &LONCAPA::clean_domain($domain)
                   3862:         && ($amode ne '')) {
                   3863:         #######################################
                   3864:         ##         Add/Modify Users          ##
                   3865:         #######################################
                   3866:         if ($context eq 'course') {
                   3867:             $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13      raeburn  3868:         } elsif ($context eq 'author') {
1.1       raeburn  3869:             $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
                   3870:         } else {
                   3871:             $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
                   3872:         }
1.87      bisitz   3873:         $r->rflush;
                   3874: 
1.1       raeburn  3875:         my %counts = (
                   3876:                        user => 0,
                   3877:                        auth => 0,
                   3878:                        role => 0,
                   3879:                      );
                   3880:         my $flushc=0;
                   3881:         my %student=();
1.42      raeburn  3882:         my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1       raeburn  3883:         my %userchg;
1.27      raeburn  3884:         if ($context eq 'course' || $setting eq 'course') {
                   3885:             if ($context eq 'course') {
                   3886:                 # Get information about course groups
                   3887:                 %curr_groups = &Apache::longroup::coursegroups();
                   3888:             } elsif ($setting eq 'course') {
                   3889:                 if ($cid) {
                   3890:                     %curr_groups =
                   3891:                         &Apache::longroup::coursegroups($env{'form.dcdomain'},
                   3892:                                                         $env{'form.dccourse'});
                   3893:                 }
                   3894:             }
                   3895:             # determine section number
                   3896:             if ($defaultsec =~ /,/) {
                   3897:                 push(@sections,split(/,/,$defaultsec));
                   3898:             } else {
                   3899:                 push(@sections,$defaultsec);
                   3900:             }
                   3901:             # remove non alphanumeric values from section
                   3902:             foreach my $item (@sections) {
                   3903:                 $item =~ s/\W//g;
                   3904:                 if ($item eq "none" || $item eq 'all') {
                   3905:                     $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
                   3906:                 } elsif ($item ne ''  && exists($curr_groups{$item})) {
                   3907:                     $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
                   3908:                 } elsif ($item ne '') {
                   3909:                     push(@cleansec,$item);
                   3910:                 }
                   3911:             }
                   3912:             if ($defaultwarn) {
                   3913:                 $r->print($defaultwarn.'<br />');
                   3914:             }
                   3915:             if ($groupwarn) {
                   3916:                 $r->print($groupwarn.'<br />');
                   3917:             }
1.1       raeburn  3918:         }
1.5       raeburn  3919:         my (%curr_rules,%got_rules,%alerts);
1.97.2.7  raeburn  3920:         my %customroles = &my_custom_roles($crstype);
1.97.2.4  raeburn  3921:         my @permitted_roles = 
                   3922:             &roles_on_upload($context,$setting,$crstype,%customroles); 
1.1       raeburn  3923:         # Get new users list
1.27      raeburn  3924:         foreach my $line (@userdata) {
1.42      raeburn  3925:             my @secs;
1.27      raeburn  3926:             my %entries=&Apache::loncommon::record_sep($line);
1.1       raeburn  3927:             # Determine user name
                   3928:             unless (($entries{$fields{'username'}} eq '') ||
                   3929:                     (!defined($entries{$fields{'username'}}))) {
                   3930:                 my ($fname, $mname, $lname,$gen) = ('','','','');
                   3931:                 if (defined($fields{'names'})) {
                   3932:                     ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
                   3933:                                             /([^\,]+)\,\s*(\w+)\s*(.*)$/);
                   3934:                 } else {
                   3935:                     if (defined($fields{'fname'})) {
                   3936:                         $fname=$entries{$fields{'fname'}};
                   3937:                     }
                   3938:                     if (defined($fields{'mname'})) {
                   3939:                         $mname=$entries{$fields{'mname'}};
                   3940:                     }
                   3941:                     if (defined($fields{'lname'})) {
                   3942:                         $lname=$entries{$fields{'lname'}};
                   3943:                     }
                   3944:                     if (defined($fields{'gen'})) {
                   3945:                         $gen=$entries{$fields{'gen'}};
                   3946:                     }
                   3947:                 }
                   3948:                 if ($entries{$fields{'username'}}
                   3949:                     ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
                   3950:                     $r->print('<br />'.
1.74      bisitz   3951:       &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
1.77      raeburn  3952:           '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen));
1.27      raeburn  3953:                     next;
1.1       raeburn  3954:                 } else {
1.71      droeschl 3955:                     if ($entries{$fields{'domain'}} 
1.57      raeburn  3956:                         ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
                   3957:                         $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.
1.77      raeburn  3958:                                   '</b>: '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
1.57      raeburn  3959:                         next;
                   3960:                     }
1.5       raeburn  3961:                     my $username = $entries{$fields{'username'}};
1.57      raeburn  3962:                     my $userdomain = $entries{$fields{'domain'}};
                   3963:                     if ($userdomain eq '') {
                   3964:                         $userdomain = $domain;
                   3965:                     }
1.27      raeburn  3966:                     if (defined($fields{'sec'})) {
                   3967:                         if (defined($entries{$fields{'sec'}})) {
1.42      raeburn  3968:                             $entries{$fields{'sec'}} =~ s/\W//g;
1.27      raeburn  3969:                             my $item = $entries{$fields{'sec'}};
                   3970:                             if ($item eq "none" || $item eq 'all') {
1.74      bisitz   3971:                                 $r->print('<br />'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.','<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item));
1.27      raeburn  3972:                                 next;
                   3973:                             } elsif (exists($curr_groups{$item})) {
1.74      bisitz   3974:                                 $r->print('<br />'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.','<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$item).' '.&mt('Section names and group names must be distinct.'));
1.27      raeburn  3975:                                 next;
                   3976:                             } else {
                   3977:                                 push(@secs,$item);
                   3978:                             }
                   3979:                         }
                   3980:                     }
                   3981:                     if ($env{'request.course.sec'} ne '') {
                   3982:                         @secs = ($env{'request.course.sec'});
1.57      raeburn  3983:                         if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
                   3984:                             my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27      raeburn  3985:                             if ($currsec ne $env{'request.course.sec'}) {
1.74      bisitz   3986:                                 $r->print('<br />'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".','<b>'.$username.'</b>',$fname,$mname,$lname,$gen,$secs[0]).'<br />');
1.27      raeburn  3987:                                 if ($currsec eq '') {
                   3988:                                     $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
                   3989: 
                   3990:                                 } else {
                   3991:                                     $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
                   3992:                                 }
                   3993:                                 $r->print('<br />'.&mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$secs[0]).'<br />');
                   3994:                                 next;
1.1       raeburn  3995:                             }
                   3996:                         }
1.27      raeburn  3997:                     } elsif ($context eq 'course' || $setting eq 'course') {
                   3998:                         if (@secs == 0) {
                   3999:                             @secs = @cleansec;
1.1       raeburn  4000:                         }
                   4001:                     }
                   4002:                     # determine id number
                   4003:                     my $id='';
                   4004:                     if (defined($fields{'id'})) {
                   4005:                         if (defined($entries{$fields{'id'}})) {
                   4006:                             $id=$entries{$fields{'id'}};
                   4007:                         }
                   4008:                         $id=~tr/A-Z/a-z/;
                   4009:                     }
                   4010:                     # determine email address
                   4011:                     my $email='';
                   4012:                     if (defined($fields{'email'})) {
                   4013:                         if (defined($entries{$fields{'email'}})) {
                   4014:                             $email=$entries{$fields{'email'}};
1.84      raeburn  4015:                             unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
                   4016:                         }
                   4017:                     }
                   4018:                     # determine affiliation
                   4019:                     my $inststatus='';
                   4020:                     if (defined($fields{'inststatus'})) {
                   4021:                         if (defined($entries{$fields{'inststatus'}})) {
                   4022:                             $inststatus=$entries{$fields{'inststatus'}};
                   4023:                         }
1.1       raeburn  4024:                     }
                   4025:                     # determine user password
                   4026:                     my $password = $genpwd;
                   4027:                     if (defined($fields{'ipwd'})) {
                   4028:                         if ($entries{$fields{'ipwd'}}) {
                   4029:                             $password=$entries{$fields{'ipwd'}};
                   4030:                         }
                   4031:                     }
                   4032:                     # determine user role
                   4033:                     my $role = '';
                   4034:                     if (defined($fields{'role'})) {
                   4035:                         if ($entries{$fields{'role'}}) {
1.42      raeburn  4036:                             $entries{$fields{'role'}}  =~ s/(\s+$|^\s+)//g;
                   4037:                             if ($entries{$fields{'role'}} ne '') {
                   4038:                                 if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
                   4039:                                     $role = $entries{$fields{'role'}};
1.27      raeburn  4040:                                 }
                   4041:                             }
                   4042:                             if ($role eq '') {
                   4043:                                 my $rolestr = join(', ',@permitted_roles);
1.74      bisitz   4044:                                 $r->print('<br />'
                   4045:                                          .&mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
                   4046:                                              ,'<b>'.$entries{$fields{'username'}}.'</b>'
                   4047:                                              ,$entries{$fields{'role'}})
                   4048:                                          .'<br />'
                   4049:                                          .&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n"
                   4050:                                 );
1.1       raeburn  4051:                                 next;
                   4052:                             }
                   4053:                         }
                   4054:                     }
                   4055:                     if ($role eq '') {
                   4056:                         $role = $defaultrole;
                   4057:                     }
                   4058:                     # Clean up whitespace
1.57      raeburn  4059:                     foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
1.1       raeburn  4060:                         $$_ =~ s/(\s+$|^\s+)//g;
                   4061:                     }
1.5       raeburn  4062:                     # check against rules
                   4063:                     my $checkid = 0;
                   4064:                     my $newuser = 0;
                   4065:                     my (%rulematch,%inst_results,%idinst_results);
1.57      raeburn  4066:                     my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5       raeburn  4067:                     if ($uhome eq 'no_host') {
1.57      raeburn  4068:                         next if ($userdomain ne $domain);
1.5       raeburn  4069:                         $checkid = 1;
                   4070:                         $newuser = 1;
                   4071:                         my $checkhash;
                   4072:                         my $checks = { 'username' => 1 };
                   4073:                         $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
                   4074:                         &Apache::loncommon::user_rule_check($checkhash,$checks,
                   4075:                             \%alerts,\%rulematch,\%inst_results,\%curr_rules,
                   4076:                             \%got_rules);
                   4077:                         if (ref($alerts{'username'}) eq 'HASH') {
                   4078:                             if (ref($alerts{'username'}{$domain}) eq 'HASH') {
                   4079:                                 next if ($alerts{'username'}{$domain}{$username});
                   4080:                             }
                   4081:                         }
1.13      raeburn  4082:                     } else {
1.27      raeburn  4083:                         if ($context eq 'course' || $context eq 'author') {
1.57      raeburn  4084:                             if ($userdomain eq $domain ) {
                   4085:                                 if ($role eq '') {
                   4086:                                     my @checkroles;
                   4087:                                     foreach my $role (@poss_roles) {
                   4088:                                         my $endkey;
                   4089:                                         if ($role ne 'st') {
                   4090:                                             $endkey = ':'.$role;
                   4091:                                         }
                   4092:                                         if (exists($userlist{$username.':'.$userdomain.$endkey})) {
                   4093:                                             if (!grep(/^\Q$role\E$/,@checkroles)) {
                   4094:                                                 push(@checkroles,$role);
                   4095:                                             }
                   4096:                                         }
1.27      raeburn  4097:                                     }
1.57      raeburn  4098:                                     if (@checkroles > 0) {
                   4099:                                         %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27      raeburn  4100:                                     }
1.57      raeburn  4101:                                 } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
                   4102:                                     %canmodify = %{$modifiable_fields{$role}};
1.27      raeburn  4103:                                 }
                   4104:                             }
1.57      raeburn  4105:                             my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84      raeburn  4106:                             for (my $i=0; $i<@newinfo; $i++) {
1.57      raeburn  4107:                                 if (${$newinfo[$i]} ne '') {
                   4108:                                     if (!$canmodify{$userinfo[$i]}) {
                   4109:                                         ${$newinfo[$i]} = '';
                   4110:                                     }
1.27      raeburn  4111:                                 }
                   4112:                             }
                   4113:                         }
1.5       raeburn  4114:                     }
                   4115:                     if ($id ne '') {
                   4116:                         if (!$newuser) {
1.57      raeburn  4117:                             my %idhash = &Apache::lonnet::idrget($userdomain,($username));
1.5       raeburn  4118:                             if ($idhash{$username} ne $id) {
                   4119:                                 $checkid = 1;
                   4120:                             }
                   4121:                         }
                   4122:                         if ($checkid) {
                   4123:                             my $checkhash;
                   4124:                             my $checks = { 'id' => 1 };
1.57      raeburn  4125:                             $checkhash->{$username.':'.$userdomain} = { 'newuser' => $newuser,
1.5       raeburn  4126:                                                                     'id'  => $id };
                   4127:                             &Apache::loncommon::user_rule_check($checkhash,$checks,
                   4128:                                 \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
                   4129:                                 \%got_rules);
                   4130:                             if (ref($alerts{'id'}) eq 'HASH') {
1.57      raeburn  4131:                                 if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
                   4132:                                     next if ($alerts{'id'}{$userdomain}{$id});
1.5       raeburn  4133:                                 }
                   4134:                             }
                   4135:                         }
                   4136:                     }
1.1       raeburn  4137:                     if ($password || $env{'form.login'} eq 'loc') {
1.27      raeburn  4138:                         my $multiple = 0;
                   4139:                         my ($userresult,$authresult,$roleresult,$idresult);
                   4140:                         my (%userres,%authres,%roleres,%idres);
1.42      raeburn  4141:                         my $singlesec = '';
1.1       raeburn  4142:                         if ($role eq 'st') {
1.27      raeburn  4143:                             my $sec;
1.42      raeburn  4144:                             if (@secs > 0) {
                   4145:                                 $sec = $secs[0];
1.27      raeburn  4146:                             }
1.57      raeburn  4147:                             &modifystudent($userdomain,$username,$cid,$sec,
1.52      raeburn  4148:                                            $desiredhost,$context);
1.42      raeburn  4149:                             $roleresult =
                   4150:                                 &Apache::lonnet::modifystudent
1.57      raeburn  4151:                                     ($userdomain,$username,$id,$amode,$password,
1.42      raeburn  4152:                                      $fname,$mname,$lname,$gen,$sec,$enddate,
                   4153:                                      $startdate,$env{'form.forceid'},
1.52      raeburn  4154:                                      $desiredhost,$email,'manual','',$cid,
1.84      raeburn  4155:                                      '',$context,$inststatus);
1.42      raeburn  4156:                             $userresult = $roleresult;
1.1       raeburn  4157:                         } else {
1.42      raeburn  4158:                             if ($role ne '') { 
                   4159:                                 if ($context eq 'course' || $setting eq 'course') {
                   4160:                                     if ($customroles{$role}) {
                   4161:                                         $role = 'cr_'.$env{'user.domain'}.'_'.
                   4162:                                                 $env{'user.name'}.'_'.$role;
                   4163:                                     }
1.97.2.6  raeburn  4164:                                     if (($role ne 'cc') && ($role ne 'co')) {
1.42      raeburn  4165:                                         if (@secs > 1) {
                   4166:                                             $multiple = 1;
                   4167:                                             foreach my $sec (@secs) {
                   4168:                                                 ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
                   4169:                                                 &modifyuserrole($context,$setting,
1.57      raeburn  4170:                                                     $changeauth,$cid,$userdomain,$username,
1.42      raeburn  4171:                                                     $id,$amode,$password,$fname,
                   4172:                                                     $mname,$lname,$gen,$sec,
                   4173:                                                     $env{'form.forceid'},$desiredhost,
                   4174:                                                     $email,$role,$enddate,
1.84      raeburn  4175:                                                     $startdate,$checkid,$inststatus);
1.42      raeburn  4176:                                             }
                   4177:                                         } elsif (@secs > 0) {
                   4178:                                             $singlesec = $secs[0];
                   4179:                                         }
1.27      raeburn  4180:                                     }
                   4181:                                 }
                   4182:                             }
                   4183:                             if (!$multiple) {
1.28      raeburn  4184:                                 ($userresult,$authresult,$roleresult,$idresult) = 
1.27      raeburn  4185:                                     &modifyuserrole($context,$setting,
1.57      raeburn  4186:                                                     $changeauth,$cid,$userdomain,$username, 
1.42      raeburn  4187:                                                     $id,$amode,$password,$fname,
                   4188:                                                     $mname,$lname,$gen,$singlesec,
                   4189:                                                     $env{'form.forceid'},$desiredhost,
1.84      raeburn  4190:                                                     $email,$role,$enddate,$startdate,
                   4191:                                                     $checkid,$inststatus);
1.27      raeburn  4192:                             }
                   4193:                         }
                   4194:                         if ($multiple) {
                   4195:                             foreach my $sec (sort(keys(%userres))) {
1.42      raeburn  4196:                                 $flushc =
1.27      raeburn  4197:                                 &user_change_result($r,$userres{$sec},$authres{$sec},
                   4198:                                                     $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57      raeburn  4199:                                                     $username,$userdomain,\%userchg);
1.27      raeburn  4200: 
                   4201:                             }
                   4202:                         } else {
                   4203:                             $flushc = 
                   4204:                                 &user_change_result($r,$userresult,$authresult,
1.28      raeburn  4205:                                                     $roleresult,$idresult,\%counts,$flushc,
1.57      raeburn  4206:                                                     $username,$userdomain,\%userchg);
1.1       raeburn  4207:                         }
                   4208:                     } else {
                   4209:                         if ($context eq 'course') {
                   4210:                             $r->print('<br />'. 
1.74      bisitz   4211:       &mt('[_1]: Unable to enroll. No password specified.','<b>'.$username.'</b>')
1.1       raeburn  4212:                                      );
1.13      raeburn  4213:                         } elsif ($context eq 'author') {
1.1       raeburn  4214:                             $r->print('<br />'.
1.74      bisitz   4215:       &mt('[_1]: Unable to add co-author. No password specified.','<b>'.$username.'</b>')
1.1       raeburn  4216:                                      );
                   4217:                         } else {
                   4218:                             $r->print('<br />'.
1.74      bisitz   4219:       &mt('[_1]: Unable to add user. No password specified.','<b>'.$username.'</b>')
1.1       raeburn  4220:                                      );
                   4221:                         }
                   4222:                     }
                   4223:                 }
                   4224:             }
                   4225:         } # end of foreach (@userdata)
                   4226:         # Flush the course logs so reverse user roles immediately updated
1.5       raeburn  4227:         &Apache::lonnet::flushcourselogs();
1.29      raeburn  4228:         $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1       raeburn  4229:                   "</p>\n");
                   4230:         if ($counts{'role'} > 0) {
                   4231:             $r->print("<p>\n".
1.29      raeburn  4232:                       &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."</p>\n");
                   4233:         } else {
                   4234:             $r->print('<p>'.&mt('No roles added').'</p>');
1.1       raeburn  4235:         }
                   4236:         if ($counts{'auth'} > 0) {
                   4237:             $r->print("<p>\n".
                   4238:                       &mt('Authentication changed for [_1] existing users.',
                   4239:                           $counts{'auth'})."</p>\n");
                   4240:         }
1.13      raeburn  4241:         $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.1       raeburn  4242:         #####################################
1.29      raeburn  4243:         # Display list of students to drop  #
1.1       raeburn  4244:         #####################################
                   4245:         if ($env{'form.fullup'} eq 'yes') {
1.29      raeburn  4246:             $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1       raeburn  4247:             #  Get current classlist
1.30      raeburn  4248:             my $classlist = &Apache::loncoursedata::get_classlist();
1.1       raeburn  4249:             if (! defined($classlist)) {
1.29      raeburn  4250:                 $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
                   4251:                           '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
                   4252:                           &mt('There are no students with current/future access to the course.').
                   4253:                           '</form>'."\n");
1.66      raeburn  4254:             } elsif (ref($classlist) eq 'HASH') {
1.1       raeburn  4255:                 # Remove the students we just added from the list of students.
1.30      raeburn  4256:                 foreach my $line (@userdata) {
                   4257:                     my %entries=&Apache::loncommon::record_sep($line);
1.1       raeburn  4258:                     unless (($entries{$fields{'username'}} eq '') ||
                   4259:                             (!defined($entries{$fields{'username'}}))) {
                   4260:                         delete($classlist->{$entries{$fields{'username'}}.
                   4261:                                                 ':'.$domain});
                   4262:                     }
                   4263:                 }
                   4264:                 # Print out list of dropped students.
1.30      raeburn  4265:                 &show_drop_list($r,$classlist,'nosort',$permission);
1.1       raeburn  4266:             }
                   4267:         }
                   4268:     } # end of unless
1.29      raeburn  4269:     if ($env{'form.fullup'} ne 'yes') {
                   4270:         $r->print('</form>');
                   4271:     }
1.1       raeburn  4272: }
                   4273: 
1.13      raeburn  4274: sub print_namespacing_alerts {
                   4275:     my ($domain,$alerts,$curr_rules) = @_;
                   4276:     my $output;
                   4277:     if (ref($alerts) eq 'HASH') {
                   4278:         if (keys(%{$alerts}) > 0) {
                   4279:             if (ref($alerts->{'username'}) eq 'HASH') {
                   4280:                 foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
                   4281:                     my $count;
                   4282:                     if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
                   4283:                         $count = keys(%{$alerts->{'username'}{$dom}});
                   4284:                     }
                   4285:                     my $domdesc = &Apache::lonnet::domain($domain,'description');
                   4286:                     if (ref($curr_rules->{$dom}) eq 'HASH') {
                   4287:                         $output .= &Apache::loncommon::instrule_disallow_msg(
                   4288:                                         'username',$domdesc,$count,'upload');
                   4289:                     }
                   4290:                     $output .= &Apache::loncommon::user_rule_formats($dom,
                   4291:                                    $domdesc,$curr_rules->{$dom}{'username'},
                   4292:                                    'username');
                   4293:                 }
                   4294:             }
                   4295:             if (ref($alerts->{'id'}) eq 'HASH') {
                   4296:                 foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
                   4297:                     my $count;
                   4298:                     if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
                   4299:                         $count = keys(%{$alerts->{'id'}{$dom}});
                   4300:                     }
                   4301:                     my $domdesc = &Apache::lonnet::domain($domain,'description');
                   4302:                     if (ref($curr_rules->{$dom}) eq 'HASH') {
                   4303:                         $output .= &Apache::loncommon::instrule_disallow_msg(
                   4304:                                               'id',$domdesc,$count,'upload');
                   4305:                     }
                   4306:                     $output .= &Apache::loncommon::user_rule_formats($dom,
                   4307:                                     $domdesc,$curr_rules->{$dom}{'id'},'id');
                   4308:                 }
                   4309:             }
                   4310:         }
                   4311:     }
                   4312: }
                   4313: 
1.1       raeburn  4314: sub user_change_result {
1.29      raeburn  4315:     my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57      raeburn  4316:         $username,$userdomain,$userchg) = @_;
1.1       raeburn  4317:     my $okresult = 0;
                   4318:     if ($userresult ne 'ok') {
                   4319:         if ($userresult =~ /^error:(.+)$/) {
                   4320:             my $error = $1;
                   4321:             $r->print('<br />'.
1.74      bisitz   4322:                   &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1       raeburn  4323:         }
                   4324:     } else {
                   4325:         $counts->{'user'} ++;
                   4326:         $okresult = 1;
                   4327:     }
                   4328:     if ($authresult ne 'ok') {
                   4329:         if ($authresult =~ /^error:(.+)$/) {
                   4330:             my $error = $1;
                   4331:             $r->print('<br />'.
1.74      bisitz   4332:                   &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1       raeburn  4333:         } 
                   4334:     } else {
                   4335:         $counts->{'auth'} ++;
                   4336:         $okresult = 1;
                   4337:     }
                   4338:     if ($roleresult ne 'ok') {
                   4339:         if ($roleresult =~ /^error:(.+)$/) {
                   4340:             my $error = $1;
                   4341:             $r->print('<br />'.
1.74      bisitz   4342:                   &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1       raeburn  4343:         }
                   4344:     } else {
                   4345:         $counts->{'role'} ++;
                   4346:         $okresult = 1;
                   4347:     }
                   4348:     if ($okresult) {
                   4349:         $flushc++;
1.57      raeburn  4350:         $userchg->{$username.':'.$userdomain}=1;
1.1       raeburn  4351:         $r->print('. ');
                   4352:         if ($flushc>15) {
                   4353:             $r->rflush;
                   4354:             $flushc=0;
                   4355:         }
                   4356:     }
1.29      raeburn  4357:     if ($idresult) {
                   4358:         $r->print($idresult);
                   4359:     }
1.1       raeburn  4360:     return $flushc;
                   4361: }
                   4362: 
                   4363: # ========================================================= Menu Phase Two Drop
1.17      raeburn  4364: sub print_drop_menu {
1.97.2.4  raeburn  4365:     my ($r,$context,$permission,$crstype) = @_;
                   4366:     my $heading;
                   4367:     if ($crstype eq 'Community') {
                   4368:         $heading = &mt("Drop Members");
                   4369:     } else {
                   4370:         $heading = &mt("Drop Students");
                   4371:     }
                   4372:     $r->print('<h3>'.$heading.'</h3>'."\n".
1.17      raeburn  4373:               '<form name="studentform" method="post">'."\n");
1.30      raeburn  4374:     my $classlist = &Apache::loncoursedata::get_classlist();
1.1       raeburn  4375:     if (! defined($classlist)) {
1.97.2.4  raeburn  4376:         if ($crstype eq 'Community') {
                   4377:             $r->print(&mt('There are no members currently enrolled.')."\n");
                   4378:         } else {
                   4379:             $r->print(&mt('There are no students currently enrolled.')."\n");
                   4380:         }
1.30      raeburn  4381:     } else {
1.97.2.4  raeburn  4382:         &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
1.1       raeburn  4383:     }
1.17      raeburn  4384:     $r->print('</form>'. &Apache::loncommon::end_page());
1.1       raeburn  4385:     return;
                   4386: }
                   4387: 
                   4388: # ================================================================== Phase four
                   4389: 
1.11      raeburn  4390: sub update_user_list {
                   4391:     my ($r,$context,$setting,$choice) = @_;
                   4392:     my $now = time;
1.1       raeburn  4393:     my $count=0;
1.97.2.4  raeburn  4394:     my $crstype;
                   4395:     if ($context eq 'course') {
                   4396:         $crstype = &Apache::loncommon::course_type();
                   4397:     }
1.11      raeburn  4398:     my @changelist;
1.29      raeburn  4399:     if ($choice eq 'drop') {
                   4400:         @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
                   4401:     } else {
1.11      raeburn  4402:         @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
                   4403:     }
                   4404:     my %result_text = ( ok    => { 'revoke'   => 'Revoked',
                   4405:                                    'delete'   => 'Deleted',
                   4406:                                    'reenable' => 'Re-enabled',
1.17      raeburn  4407:                                    'activate' => 'Activated',
                   4408:                                    'chgdates' => 'Changed Access Dates for',
                   4409:                                    'chgsec'   => 'Changed section for',
                   4410:                                    'drop'     => 'Dropped',
1.11      raeburn  4411:                                  },
                   4412:                         error => {'revoke'    => 'revoking',
                   4413:                                   'delete'    => 'deleting',
                   4414:                                   'reenable'  => 're-enabling',
                   4415:                                   'activate'  => 'activating',
1.17      raeburn  4416:                                   'chgdates'  => 'changing access dates for',
                   4417:                                   'chgsec'    => 'changing section for',
                   4418:                                   'drop'      => 'dropping',
1.11      raeburn  4419:                                  },
                   4420:                       );
                   4421:     my ($startdate,$enddate);
                   4422:     if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
                   4423:         ($startdate,$enddate) = &get_dates_from_form();
                   4424:     }
                   4425:     foreach my $item (@changelist) {
                   4426:         my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
                   4427:             $scopestem);
1.17      raeburn  4428:         if ($choice eq 'drop') {
                   4429:             ($uname,$udom,$sec) = split(/:/,$item,-1);
                   4430:             $role = 'st';
                   4431:             $cid = $env{'request.course.id'};
                   4432:             $scopestem = '/'.$cid;
                   4433:             $scopestem =~s/\_/\//g;
                   4434:             if ($sec eq '') {
                   4435:                 $scope = $scopestem;
                   4436:             } else {
                   4437:                 $scope = $scopestem.'/'.$sec;
                   4438:             }
                   4439:         } elsif ($context eq 'course') {
1.11      raeburn  4440:             ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
                   4441:             $cid = $env{'request.course.id'};
                   4442:             $scopestem = '/'.$cid;
                   4443:             $scopestem =~s/\_/\//g;
                   4444:             if ($sec eq '') {
                   4445:                 $scope = $scopestem;
                   4446:             } else {
                   4447:                 $scope = $scopestem.'/'.$sec;
                   4448:             }
1.13      raeburn  4449:         } elsif ($context eq 'author') {
1.11      raeburn  4450:             ($uname,$udom,$role) = split(/\:/,$item,-1);
                   4451:             $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
                   4452:         } elsif ($context eq 'domain') {
                   4453:             if ($setting eq 'domain') {
                   4454:                 ($role,$uname,$udom) = split(/\:/,$item,-1);
                   4455:                 $scope = '/'.$env{'request.role.domain'}.'/';
1.13      raeburn  4456:             } elsif ($setting eq 'author') { 
1.11      raeburn  4457:                 ($uname,$udom,$role,$scope) = split(/\:/,$item);
                   4458:             } elsif ($setting eq 'course') {
                   4459:                 ($uname,$udom,$role,$cid,$sec,$type,$locktype) = 
                   4460:                     split(/\:/,$item);
                   4461:                 $scope = '/'.$cid;
                   4462:                 $scope =~s/\_/\//g;
                   4463:                 if ($sec ne '') {
                   4464:                     $scope .= '/'.$sec;
                   4465:                 }
                   4466:             }
                   4467:         }
1.97.2.4  raeburn  4468:         my $plrole = &Apache::lonnet::plaintext($role,$crstype);
1.11      raeburn  4469:         my $start = $env{'form.'.$item.'_start'};
                   4470:         my $end = $env{'form.'.$item.'_end'};
1.17      raeburn  4471:         if ($choice eq 'drop') {
                   4472:             # drop students
                   4473:             $end = $now;
                   4474:             $type = 'manual';
                   4475:             $result =
1.52      raeburn  4476:                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17      raeburn  4477:         } elsif ($choice eq 'revoke') {
                   4478:             # revoke or delete user role
1.11      raeburn  4479:             $end = $now; 
                   4480:             if ($role eq 'st') {
                   4481:                 $result = 
1.52      raeburn  4482:                     &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11      raeburn  4483:             } else {
                   4484:                 $result = 
1.52      raeburn  4485:                     &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
                   4486:                                                 '','',$context);
1.11      raeburn  4487:             }
                   4488:         } elsif ($choice eq 'delete') {
                   4489:             if ($role eq 'st') {
1.52      raeburn  4490:                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
1.29      raeburn  4491:             }
                   4492:             $result =
                   4493:                 &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52      raeburn  4494:                                             $start,1,'',$context);
1.11      raeburn  4495:         } else {
                   4496:             #reenable, activate, change access dates or change section
                   4497:             if ($choice ne 'chgsec') {
                   4498:                 $start = $startdate; 
                   4499:                 $end = $enddate;
                   4500:             }
                   4501:             if ($choice eq 'reenable') {
                   4502:                 if ($role eq 'st') {
1.52      raeburn  4503:                     $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11      raeburn  4504:                 } else {
                   4505:                     $result = 
                   4506:                         &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52      raeburn  4507:                                                     $now,'','',$context);
1.11      raeburn  4508:                 }
                   4509:             } elsif ($choice eq 'activate') {
                   4510:                 if ($role eq 'st') {
1.52      raeburn  4511:                     $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11      raeburn  4512:                 } else {
                   4513:                     $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52      raeburn  4514:                                             $now,'','',$context);
1.11      raeburn  4515:                 }
                   4516:             } elsif ($choice eq 'chgdates') {
                   4517:                 if ($role eq 'st') {
1.52      raeburn  4518:                     $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11      raeburn  4519:                 } else {
                   4520:                     $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52      raeburn  4521:                                                 $start,'','',$context);
1.11      raeburn  4522:                 }
                   4523:             } elsif ($choice eq 'chgsec') {
                   4524:                 my (@newsecs,$revresult,$nochg,@retained);
1.97.2.6  raeburn  4525:                 if (($role ne 'cc') && ($role ne 'co')) {
1.11      raeburn  4526:                     @newsecs = split(/,/,$env{'form.newsecs'});
                   4527:                 }
                   4528:                 # remove existing section if not to be retained.   
                   4529:                 if (!$env{'form.retainsec'}) {
                   4530:                     if ($sec eq '') {
                   4531:                         if (@newsecs == 0) {
                   4532:                             $result = &mt('No change in section assignment (none)');
                   4533:                             $nochg = 1;
1.40      raeburn  4534:                         } else {
                   4535:                             $revresult =
                   4536:                                 &Apache::lonnet::revokerole($udom,$uname,
1.52      raeburn  4537:                                                             $scope,$role,
                   4538:                                                             '','',$context);
1.40      raeburn  4539:                         } 
1.11      raeburn  4540:                     } else {
1.28      raeburn  4541:                         if (@newsecs > 0) {
                   4542:                             if (grep(/^\Q$sec\E$/,@newsecs)) {
                   4543:                                 push(@retained,$sec);
                   4544:                             } else {
                   4545:                                 $revresult =
                   4546:                                     &Apache::lonnet::revokerole($udom,$uname,
1.52      raeburn  4547:                                                                 $scope,$role,
                   4548:                                                                 '','',$context);
1.28      raeburn  4549:                             }
                   4550:                         } else {
1.11      raeburn  4551:                             $revresult =
1.28      raeburn  4552:                                 &Apache::lonnet::revokerole($udom,$uname,
1.52      raeburn  4553:                                                             $scope,$role,
                   4554:                                                             '','',$context);
1.11      raeburn  4555:                         }
                   4556:                     }
                   4557:                 } else {
1.28      raeburn  4558:                     if ($sec eq '') {
                   4559:                         $nochg = 1;
                   4560:                     } else { 
                   4561:                         push(@retained,$sec);
                   4562:                     }
1.11      raeburn  4563:                 }
                   4564:                 # add new sections
                   4565:                 if (@newsecs == 0) {
                   4566:                     if (!$nochg) {
1.28      raeburn  4567:                         if ($role eq 'st') {
                   4568:                             $result = 
1.52      raeburn  4569:                                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
1.28      raeburn  4570:                         } else {
                   4571:                             my $newscope = $scopestem;
1.52      raeburn  4572:                             $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11      raeburn  4573:                         }
                   4574:                     }
                   4575:                 } else {
                   4576:                     foreach my $newsec (@newsecs) { 
                   4577:                         if (!grep(/^\Q$newsec\E$/,@retained)) {
                   4578:                             if ($role eq 'st') {
1.52      raeburn  4579:                                 $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
1.11      raeburn  4580:                             } else {
                   4581:                                 my $newscope = $scopestem;
                   4582:                                 if ($newsec ne '') {
                   4583:                                    $newscope .= '/'.$newsec;
                   4584:                                 }
                   4585:                                 $result = &Apache::lonnet::assignrole($udom,$uname,
                   4586:                                                         $newscope,$role,$end,$start);
                   4587:                             }
                   4588:                         }
                   4589:                     }
                   4590:                 }
                   4591:             }
                   4592:         }
1.17      raeburn  4593:         my $extent = $scope;
                   4594:         if ($choice eq 'drop' || $context eq 'course') {
                   4595:             my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
                   4596:             if ($cdesc) {
                   4597:                 $extent = $cdesc;
                   4598:             }
                   4599:         }
1.1       raeburn  4600:         if ($result eq 'ok' || $result eq 'ok:') {
1.11      raeburn  4601:             $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
1.17      raeburn  4602:                           $plrole,$extent,$uname.':'.$udom).'<br />');
1.1       raeburn  4603:             $count++;
                   4604:         } else {
                   4605:             $r->print(
1.29      raeburn  4606:                 &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
1.17      raeburn  4607:                     $plrole,$extent,$uname.':'.$udom,$result).'<br />');
1.11      raeburn  4608:         }
                   4609:     }
1.32      raeburn  4610:     $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33      raeburn  4611:     if ($choice eq 'drop') {
                   4612:         $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
                   4613:                   '<input type="hidden" name="Status" value="Active" />'."\n".
                   4614:                   '<input type="hidden" name="showrole" value="st" />'."\n");
                   4615:     } else {
                   4616:         foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
                   4617:             if ($env{'form.'.$item} ne '') {
                   4618:                 $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
                   4619:                           '" />'."\n");
                   4620:             }
1.32      raeburn  4621:         }
                   4622:     }
1.29      raeburn  4623:     $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
1.11      raeburn  4624:     if ($count > 0) {
1.17      raeburn  4625:         if ($choice eq 'revoke' || $choice eq 'drop') {
1.74      bisitz   4626:             $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11      raeburn  4627:         }
                   4628:         # Flush the course logs so reverse user roles immediately updated
                   4629:         &Apache::lonnet::flushcourselogs();
                   4630:     }
                   4631:     if ($env{'form.makedatesdefault'}) {
                   4632:         if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.97.2.4  raeburn  4633:             $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
1.1       raeburn  4634:         }
                   4635:     }
1.33      raeburn  4636:     my $linktext = &mt('Display User Lists');
                   4637:     if ($choice eq 'drop') {
                   4638:         $linktext = &mt('Display current class roster');
                   4639:     }
                   4640:     $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
1.1       raeburn  4641: }
                   4642: 
1.8       raeburn  4643: sub classlist_drop {
1.29      raeburn  4644:     my ($scope,$uname,$udom,$now) = @_;
1.8       raeburn  4645:     my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29      raeburn  4646:     if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8       raeburn  4647:         if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63      raeburn  4648:             my %user;
                   4649:             my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8       raeburn  4650:             return &mt('Drop from classlist: [_1]',
                   4651:                        '<b>'.$result.'</b>').'<br />';
                   4652:         }
                   4653:     }
                   4654: }
                   4655: 
                   4656: sub active_student_roles {
                   4657:     my ($cnum,$cdom,$uname,$udom) = @_;
                   4658:     my %roles =
                   4659:         &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   4660:                                       ['future','active'],['st']);
                   4661:     return exists($roles{"$cnum:$cdom:st"});
                   4662: }
                   4663: 
1.1       raeburn  4664: sub section_check_js {
1.8       raeburn  4665:     my $groupslist= &get_groupslist();
1.1       raeburn  4666:     return <<"END";
                   4667: function validate(caller) {
1.9       raeburn  4668:     var groups = new Array($groupslist);
1.1       raeburn  4669:     var secname = caller.value;
                   4670:     if ((secname == 'all') || (secname == 'none')) {
                   4671:         alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
                   4672:         return 'error';
                   4673:     }
                   4674:     if (secname != '') {
                   4675:         for (var k=0; k<groups.length; k++) {
                   4676:             if (secname == groups[k]) {
                   4677:                 alert("'"+secname+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
                   4678:                 return 'error';
                   4679:             }
                   4680:         }
                   4681:     }
                   4682:     return 'ok';
                   4683: }
                   4684: END
                   4685: }
                   4686: 
                   4687: sub set_login {
                   4688:     my ($dom,$authformkrb,$authformint,$authformloc) = @_;
                   4689:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   4690:     my $response;
                   4691:     my ($authnum,%can_assign) =
                   4692:         &Apache::loncommon::get_assignable_auth($dom);
                   4693:     if ($authnum) {
                   4694:         $response = &Apache::loncommon::start_data_table();
                   4695:         if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
                   4696:             $response .= &Apache::loncommon::start_data_table_row().
                   4697:                          '<td>'.$authformkrb.'</td>'.
                   4698:                          &Apache::loncommon::end_data_table_row()."\n";
                   4699:         }
                   4700:         if ($can_assign{'int'}) {
                   4701:             $response .= &Apache::loncommon::start_data_table_row().
                   4702:                          '<td>'.$authformint.'</td>'.
                   4703:                          &Apache::loncommon::end_data_table_row()."\n"
                   4704:         }
                   4705:         if ($can_assign{'loc'}) {
                   4706:             $response .= &Apache::loncommon::start_data_table_row().
                   4707:                          '<td>'.$authformloc.'</td>'.
                   4708:                          &Apache::loncommon::end_data_table_row()."\n";
                   4709:         }
                   4710:         $response .= &Apache::loncommon::end_data_table();
                   4711:     }
                   4712:     return $response;
                   4713: }
                   4714: 
1.8       raeburn  4715: sub course_sections {
1.51      raeburn  4716:     my ($sections_count,$role,$current_sec) = @_;
1.8       raeburn  4717:     my $output = '';
                   4718:     my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.29      raeburn  4719:     my $numsec = scalar(@sections);
1.92      bisitz   4720:     my $is_selected = ' selected="selected"';
1.29      raeburn  4721:     if ($numsec <= 1) {
1.8       raeburn  4722:         $output = '<select name="currsec_'.$role.'" >'."\n".
1.51      raeburn  4723:                   '  <option value="">'.&mt('Select').'</option>'."\n";
                   4724:         if ($current_sec eq 'none') {
                   4725:             $output .=       
                   4726:                   '  <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
                   4727:         } else {
                   4728:             $output .=
1.29      raeburn  4729:                   '  <option value="">'.&mt('No section').'</option>'."\n";
1.51      raeburn  4730:         }
1.29      raeburn  4731:         if ($numsec == 1) {
1.51      raeburn  4732:             if ($current_sec eq $sections[0]) {
                   4733:                 $output .=
                   4734:                   '  <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
                   4735:             } else {
                   4736:                 $output .=  
1.8       raeburn  4737:                   '  <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51      raeburn  4738:             }
1.29      raeburn  4739:         }
1.8       raeburn  4740:     } else {
                   4741:         $output = '<select name="currsec_'.$role.'" ';
                   4742:         my $multiple = 4;
                   4743:         if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29      raeburn  4744:         if ($role eq 'st') {
                   4745:             $output .= '>'."\n".
1.51      raeburn  4746:                        '  <option value="">'.&mt('Select').'</option>'."\n";
                   4747:             if ($current_sec eq 'none') {
                   4748:                 $output .= 
                   4749:                        '  <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
                   4750:             } else {
                   4751:                 $output .=
1.29      raeburn  4752:                        '  <option value="">'.&mt('No section')."</option>\n";
1.51      raeburn  4753:             }
1.29      raeburn  4754:         } else {
                   4755:             $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
                   4756:         }
1.8       raeburn  4757:         foreach my $sec (@sections) {
1.51      raeburn  4758:             if ($current_sec eq $sec) {
                   4759:                 $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
                   4760:             } else {
                   4761:                 $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
                   4762:             }
1.8       raeburn  4763:         }
                   4764:     }
                   4765:     $output .= '</select>';
                   4766:     return $output;
                   4767: }
                   4768: 
                   4769: sub get_groupslist {
                   4770:     my $groupslist;
                   4771:     my %curr_groups = &Apache::longroup::coursegroups();
                   4772:     if (%curr_groups) {
                   4773:         $groupslist = join('","',sort(keys(%curr_groups)));
                   4774:         $groupslist = '"'.$groupslist.'"';
                   4775:     }
1.11      raeburn  4776:     return $groupslist; 
1.8       raeburn  4777: }
                   4778: 
                   4779: sub setsections_javascript {
1.97.2.6  raeburn  4780:     my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
1.28      raeburn  4781:     my ($checkincluded,$finish,$rolecode,$setsection_js);
                   4782:     if ($mode eq 'upload') {
                   4783:         $checkincluded = 'formname.name == "'.$formname.'"';
                   4784:         $finish = "return 'ok';";
                   4785:         $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
                   4786:     } elsif ($formname eq 'cu') {
1.8       raeburn  4787:         $checkincluded = 'formname.elements[i-1].checked == true';
1.37      raeburn  4788:         if ($checkauth) {
                   4789:             $finish = "var authcheck = auth_check();\n".
                   4790:                       "   if (authcheck == 'ok') {\n".
                   4791:                       "       formname.submit();\n".
                   4792:                       "   }\n";
                   4793:         } else {
                   4794:             $finish = 'formname.submit()';
                   4795:         }
1.28      raeburn  4796:         $rolecode = "var match = str.split('_');
                   4797:                 var role = match[3];\n";
                   4798:     } elsif ($formname eq 'enrollstudent') {
                   4799:         $checkincluded = 'formname.name == "'.$formname.'"';
1.37      raeburn  4800:         if ($checkauth) {
                   4801:             $finish = "var authcheck = auth_check();\n".
                   4802:                       "   if (authcheck == 'ok') {\n".
                   4803:                       "       formname.submit();\n".
                   4804:                       "   }\n";
                   4805:         } else {
                   4806:             $finish = 'formname.submit()';
                   4807:         }
1.28      raeburn  4808:         $rolecode = "var match = str.split('_');
                   4809:                 var role = match[1];\n";
1.8       raeburn  4810:     } else {
1.28      raeburn  4811:         $checkincluded = 'formname.name == "'.$formname.'"'; 
1.8       raeburn  4812:         $finish = "seccheck = 'ok';";
1.28      raeburn  4813:         $rolecode = "var match = str.split('_');
                   4814:                 var role = match[1];\n";
1.11      raeburn  4815:         $setsection_js = "var seccheck = 'alert';"; 
1.8       raeburn  4816:     }
                   4817:     my %alerts = &Apache::lonlocal::texthash(
                   4818:                     secd => 'Section designations do not apply to Course Coordinator roles.',
1.97.2.6  raeburn  4819:                     sedn => 'Section designations do not apply to Coordinator roles.',
1.8       raeburn  4820:                     accr => 'A course coordinator role will be added with access to all sections.',
1.97.2.6  raeburn  4821:                     acor => 'A coordinator role will be added with access to all sections',
1.8       raeburn  4822:                     inea => 'In each course, each user may only have one student role at a time.',
1.97.2.6  raeburn  4823:                     inec => 'In each community, each user may only have one member role at a time.',
1.8       raeburn  4824:                     youh => 'You had selected ',
                   4825:                     secs => 'sections.',
                   4826:                     plmo => 'Please modify your selections so they include no more than one section.',
                   4827:                     mayn => 'may not be used as the name for a section, as it is a reserved word.',
                   4828:                     plch => 'Please choose a different section name.',
                   4829:                     mnot => 'may not be used as a section name, as it is the name of a course group.',
                   4830:                     secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.97.2.13  raeburn  4831:                     nonw => 'Section names may only contain letters or numbers.',
1.11      raeburn  4832:                  );                
1.8       raeburn  4833:     $setsection_js .= <<"ENDSECCODE";
                   4834: 
1.97.2.6  raeburn  4835: function setSections(formname,crstype) {
1.8       raeburn  4836:     var re1 = /^currsec_/;
1.97.2.13  raeburn  4837:     var re2 =/\\W/;
1.8       raeburn  4838:     var groups = new Array($groupslist);
                   4839:     for (var i=0;i<formname.elements.length;i++) {
                   4840:         var str = formname.elements[i].name;
                   4841:         var checkcurr = str.match(re1);
                   4842:         if (checkcurr != null) {
                   4843:             if ($checkincluded) {
1.28      raeburn  4844:                 $rolecode
1.97.2.6  raeburn  4845:                 if (role == 'cc' || role == 'co') {
                   4846:                     if (role == 'cc') {
                   4847:                         alert("$alerts{'secd'}\\n$alerts{'accr'}");
                   4848:                     } else {
                   4849:                         alert("$alerts{'sedn'}\\n$alerts{'acor'}");
                   4850:                     }
                   4851:                 } else {
1.8       raeburn  4852:                     var sections = '';
                   4853:                     var numsec = 0;
                   4854:                     var sections;
                   4855:                     for (var j=0; j<formname.elements[i].length; j++) {
                   4856:                         if (formname.elements[i].options[j].selected == true ) {
                   4857:                             if (formname.elements[i].options[j].value != "") {
                   4858:                                 if (numsec == 0) {
                   4859:                                     if (formname.elements[i].options[j].value != "") {
                   4860:                                         sections = formname.elements[i].options[j].value;
                   4861:                                         numsec ++;
                   4862:                                     }
                   4863:                                 }
                   4864:                                 else {
                   4865:                                     sections = sections + "," +  formname.elements[i].options[j].value
                   4866:                                     numsec ++;
                   4867:                                 }
                   4868:                             }
                   4869:                         }
                   4870:                     }
                   4871:                     if (numsec > 0) {
                   4872:                         if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
                   4873:                             sections = sections + "," +  formname.elements[i+1].value;
                   4874:                         }
                   4875:                     }
                   4876:                     else {
                   4877:                         sections = formname.elements[i+1].value;
                   4878:                     }
                   4879:                     var newsecs = formname.elements[i+1].value;
                   4880:                     var numsplit;
1.97.2.13  raeburn  4881:                     var validsecs = new Array();
                   4882:                     var badsecs = new Array();
1.8       raeburn  4883:                     if (newsecs != null && newsecs != "") {
                   4884:                         numsplit = newsecs.split(/,/g);
                   4885:                         numsec = numsec + numsplit.length;
1.97.2.13  raeburn  4886:                         for (var i=0; i<numsplit.length; i++) {
                   4887:                             if (re2.test(numsplit[i]) == true) {
                   4888:                                 badsecs.push(numsplit[i]);
                   4889:                             } else {
                   4890:                                 validsecs.push(numsplit[i]);
                   4891:                             }
                   4892:                         }
                   4893:                         if (badsecs.length > 0) {
                   4894:                             alert("$alerts{'nonw'}\\n$alerts{'plch'}");
                   4895:                             return;
                   4896:                         }
                   4897:                         numsec = numsec + validsecs.length;
1.8       raeburn  4898:                     }
                   4899: 
                   4900:                     if ((role == 'st') && (numsec > 1)) {
1.97.2.6  raeburn  4901:                         if (crstype == 'Community') {
                   4902:                             alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
                   4903:                         } else {
                   4904:                             alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
                   4905:                         }
1.8       raeburn  4906:                         return;
                   4907:                     }
                   4908:                     else {
                   4909:                         if (numsplit != null) {
                   4910:                             for (var j=0; j<numsplit.length; j++) {
                   4911:                                 if ((numsplit[j] == 'all') ||
                   4912:                                     (numsplit[j] == 'none')) {
                   4913:                                     alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
                   4914:                                     return;
                   4915:                                 }
                   4916:                                 for (var k=0; k<groups.length; k++) {
                   4917:                                     if (numsplit[j] == groups[k]) {
                   4918:                                         alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
                   4919:                                         return;
                   4920:                                     }
                   4921:                                 }
                   4922:                             }
                   4923:                         }
                   4924:                         formname.elements[i+2].value = sections;
                   4925:                     }
                   4926:                 }
                   4927:             }
                   4928:         }
                   4929:     }
                   4930:     $finish
                   4931: }
                   4932: ENDSECCODE
1.11      raeburn  4933:     return $setsection_js; 
1.8       raeburn  4934: }
                   4935: 
1.15      raeburn  4936: sub can_create_user {
                   4937:     my ($dom,$context,$usertype) = @_;
                   4938:     my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   4939:     my $cancreate = 1;
1.28      raeburn  4940:     if (&Apache::lonnet::allowed('mau',$dom)) {
                   4941:         return $cancreate;
                   4942:     }
1.15      raeburn  4943:     if (ref($domconf{'usercreation'}) eq 'HASH') {
                   4944:         if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
1.97.2.3  raeburn  4945:             if ($context eq 'course' || $context eq 'author' || $context eq 'requestcrs') {
1.15      raeburn  4946:                 my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
                   4947:                 if ($creation eq 'none') {
                   4948:                     $cancreate = 0;
                   4949:                 } elsif ($creation ne 'any') {
                   4950:                     if (defined($usertype)) {
                   4951:                         if ($creation ne $usertype) {
                   4952:                             $cancreate = 0;
                   4953:                         }
                   4954:                     }
                   4955:                 }
                   4956:             }
                   4957:         }
                   4958:     }
                   4959:     return $cancreate;
                   4960: }
                   4961: 
1.20      raeburn  4962: sub can_modify_userinfo {
                   4963:     my ($context,$dom,$fields,$userroles) = @_;
                   4964:     my %domconfig =
                   4965:        &Apache::lonnet::get_dom('configuration',['usermodification'],
                   4966:                                 $dom);
                   4967:     my %canmodify;
                   4968:     if (ref($fields) eq 'ARRAY') {
                   4969:         foreach my $field (@{$fields}) {
                   4970:             $canmodify{$field}  = 0;
                   4971:             if (&Apache::lonnet::allowed('mau',$dom)) {
                   4972:                 $canmodify{$field} = 1;
                   4973:             } else {
                   4974:                 if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   4975:                     if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
                   4976:                         if (ref($userroles) eq 'ARRAY') {
                   4977:                             foreach my $role (@{$userroles}) {
                   4978:                                 my $testrole;
1.60      raeburn  4979:                                 if ($context eq 'selfcreate') {
                   4980:                                     $testrole = $role;
1.20      raeburn  4981:                                 } else {
1.60      raeburn  4982:                                     if ($role =~ /^cr\//) {
                   4983:                                         $testrole = 'cr';
                   4984:                                     } else {
                   4985:                                         $testrole = $role;
                   4986:                                     }
1.20      raeburn  4987:                                 }
                   4988:                                 if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
                   4989:                                     if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
                   4990:                                         $canmodify{$field} = 1;
                   4991:                                         last;
                   4992:                                     }
                   4993:                                 }
                   4994:                             }
                   4995:                         } else {
                   4996:                             foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
                   4997:                                 if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
                   4998:                                     if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
                   4999:                                         $canmodify{$field} = 1;
                   5000:                                         last;
                   5001:                                     }
                   5002:                                 }
                   5003:                             }
                   5004:                         }
                   5005:                     }
                   5006:                 } elsif ($context eq 'course') {
                   5007:                     if (ref($userroles) eq 'ARRAY') {
                   5008:                         if (grep(/^st$/,@{$userroles})) {
                   5009:                             $canmodify{$field} = 1;
                   5010:                         }
                   5011:                     } else {
                   5012:                         $canmodify{$field} = 1;
                   5013:                     }
                   5014:                 }
                   5015:             }
                   5016:         }
                   5017:     }
                   5018:     return %canmodify;
                   5019: }
                   5020: 
1.18      raeburn  5021: sub check_usertype {
                   5022:     my ($dom,$uname,$rules) = @_;
                   5023:     my $usertype;
                   5024:     if (ref($rules) eq 'HASH') {
                   5025:         my @user_rules = keys(%{$rules});
                   5026:         if (@user_rules > 0) {
                   5027:             my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
                   5028:             if (keys(%rule_check) > 0) {
                   5029:                 $usertype = 'unofficial';
                   5030:                 foreach my $item (keys(%rule_check)) {
                   5031:                     if ($rule_check{$item}) {
                   5032:                         $usertype = 'official';
                   5033:                         last;
                   5034:                     }
                   5035:                 }
                   5036:             }
                   5037:         }
                   5038:     }
                   5039:     return $usertype;
                   5040: }
                   5041: 
1.17      raeburn  5042: sub roles_by_context {
1.97.2.4  raeburn  5043:     my ($context,$custom,$crstype) = @_;
1.17      raeburn  5044:     my @allroles;
                   5045:     if ($context eq 'course') {
1.97.2.2  raeburn  5046:         @allroles = ('st');
                   5047:         if ($env{'request.role'} =~ m{^dc\./}) {
                   5048:             push(@allroles,'ad');
                   5049:         }
1.97.2.4  raeburn  5050:         push(@allroles,('ta','ep','in'));
                   5051:         if ($crstype eq 'Community') {
                   5052:             push(@allroles,'co');
                   5053:         } else {
                   5054:             push(@allroles,'cc');
                   5055:         }
1.17      raeburn  5056:         if ($custom) {
                   5057:             push(@allroles,'cr');
                   5058:         }
                   5059:     } elsif ($context eq 'author') {
                   5060:         @allroles = ('ca','aa');
                   5061:     } elsif ($context eq 'domain') {
1.97.2.2  raeburn  5062:         @allroles = ('li','ad','dg','sc','au','dc');
1.17      raeburn  5063:     }
                   5064:     return @allroles;
                   5065: }
                   5066: 
1.16      raeburn  5067: sub get_permission {
1.97.2.4  raeburn  5068:     my ($context,$crstype) = @_;
1.16      raeburn  5069:     my %permission;
                   5070:     if ($context eq 'course') {
1.17      raeburn  5071:         my $custom = 1;
1.97.2.4  raeburn  5072:         my @allroles = &roles_by_context($context,$custom,$crstype);
1.17      raeburn  5073:         foreach my $role (@allroles) {
                   5074:             if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
                   5075:                 $permission{'cusr'} = 1;
                   5076:                 last;
                   5077:             }
1.16      raeburn  5078:         }
                   5079:         if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
                   5080:             $permission{'custom'} = 1;
                   5081:         }
                   5082:         if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
                   5083:             $permission{'view'} = 1;
                   5084:         }
                   5085:         if (!$permission{'view'}) {
                   5086:             my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
                   5087:             $permission{'view'} =  &Apache::lonnet::allowed('vcl',$scope);
                   5088:             if ($permission{'view'}) {
                   5089:                 $permission{'view_section'} = $env{'request.course.sec'};
                   5090:             }
                   5091:         }
1.17      raeburn  5092:         if (!$permission{'cusr'}) {
                   5093:             if ($env{'request.course.sec'} ne '') {
                   5094:                 my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
                   5095:                 $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
                   5096:                 if ($permission{'cusr'}) {
                   5097:                     $permission{'cusr_section'} = $env{'request.course.sec'};
                   5098:                 }
                   5099:             }
                   5100:         }
1.16      raeburn  5101:         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
                   5102:             $permission{'grp_manage'} = 1;
                   5103:         }
                   5104:     } elsif ($context eq 'author') {
                   5105:         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
                   5106:         $permission{'view'} = $permission{'cusr'};
                   5107:     } else {
1.17      raeburn  5108:         my @allroles = &roles_by_context($context);
                   5109:         foreach my $role (@allroles) {
1.28      raeburn  5110:             if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
                   5111:                 $permission{'cusr'} = 1;
1.17      raeburn  5112:                 last;
                   5113:             }
                   5114:         }
                   5115:         if (!$permission{'cusr'}) {
                   5116:             if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
                   5117:                 $permission{'cusr'} = 1;
                   5118:             }
1.16      raeburn  5119:         }
                   5120:         if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
                   5121:             $permission{'custom'} = 1;
                   5122:         }
                   5123:         $permission{'view'} = $permission{'cusr'};
                   5124:     }
                   5125:     my $allowed = 0;
                   5126:     foreach my $perm (values(%permission)) {
                   5127:         if ($perm) { $allowed=1; last; }
                   5128:     }
                   5129:     return (\%permission,$allowed);
                   5130: }
                   5131: 
                   5132: # ==================================================== Figure out author access
                   5133: 
                   5134: sub authorpriv {
                   5135:     my ($auname,$audom)=@_;
                   5136:     unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
                   5137:          || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }    return 1;
                   5138: }
                   5139: 
1.27      raeburn  5140: sub roles_on_upload {
1.97.2.4  raeburn  5141:     my ($context,$setting,$crstype,%customroles) = @_;
1.27      raeburn  5142:     my (@possible_roles,@permitted_roles);
1.97.2.4  raeburn  5143:     @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
1.27      raeburn  5144:     foreach my $role (@possible_roles) {
                   5145:         if ($role eq 'cr') {
                   5146:             push(@permitted_roles,keys(%customroles));
                   5147:         } else {
                   5148:             push(@permitted_roles,$role);
                   5149:         }
                   5150:     }
1.42      raeburn  5151:     return @permitted_roles;
1.27      raeburn  5152: }
                   5153: 
1.17      raeburn  5154: sub get_course_identity {
                   5155:     my ($cid) = @_;
                   5156:     my ($cnum,$cdom,$cdesc);
                   5157:     if ($cid eq '') {
                   5158:         $cid = $env{'request.course.id'}
                   5159:     }
                   5160:     if ($cid ne '') {
                   5161:         $cnum = $env{'course.'.$cid.'.num'};
                   5162:         $cdom = $env{'course.'.$cid.'.domain'};
                   5163:         $cdesc = $env{'course.'.$cid.'.description'};
                   5164:         if ($cnum eq '' || $cdom eq '') {
                   5165:             my %coursehash =
                   5166:                 &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   5167:             $cdom = $coursehash{'domain'};
                   5168:             $cnum = $coursehash{'num'};
                   5169:             $cdesc = $coursehash{'description'};
                   5170:         }
                   5171:     }
                   5172:     return ($cnum,$cdom,$cdesc);
                   5173: }
                   5174: 
1.19      raeburn  5175: sub dc_setcourse_js {
1.37      raeburn  5176:     my ($formname,$mode,$context) = @_;
                   5177:     my ($dc_setcourse_code,$authen_check);
1.19      raeburn  5178:     my $cctext = &Apache::lonnet::plaintext('cc');
1.97.2.6  raeburn  5179:     my $cotext = &Apache::lonnet::plaintext('co');
1.19      raeburn  5180:     my %alerts = &sectioncheck_alerts();
                   5181:     my $role = 'role';
                   5182:     if ($mode eq 'upload') {
                   5183:         $role = 'courserole';
1.37      raeburn  5184:     } else {
                   5185:         $authen_check = &verify_authen($formname,$context);
1.19      raeburn  5186:     }
                   5187:     $dc_setcourse_code = (<<"SCRIPTTOP");
1.37      raeburn  5188: $authen_check
                   5189: 
1.19      raeburn  5190: function setCourse() {
                   5191:     var course = document.$formname.dccourse.value;
                   5192:     if (course != "") {
                   5193:         if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
                   5194:             alert("$alerts{'curd'}");
                   5195:             return;
                   5196:         }
                   5197:         var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
                   5198:         var section="";
                   5199:         var numsections = 0;
                   5200:         var newsecs = new Array();
                   5201:         for (var i=0; i<document.$formname.currsec.length; i++) {
                   5202:             if (document.$formname.currsec.options[i].selected == true ) {
                   5203:                 if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
                   5204:                     if (numsections == 0) {
                   5205:                         section = document.$formname.currsec.options[i].value
                   5206:                         numsections = 1;
                   5207:                     }
                   5208:                     else {
                   5209:                         section = section + "," +  document.$formname.currsec.options[i].value
                   5210:                         numsections ++;
                   5211:                     }
                   5212:                 }
                   5213:             }
                   5214:         }
                   5215:         if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
                   5216:             if (numsections == 0) {
                   5217:                 section = document.$formname.newsec.value
                   5218:             }
                   5219:             else {
                   5220:                 section = section + "," +  document.$formname.newsec.value
                   5221:             }
                   5222:             newsecs = document.$formname.newsec.value.split(/,/g);
                   5223:             numsections = numsections + newsecs.length;
                   5224:         }
                   5225:         if ((userrole == 'st') && (numsections > 1)) {
1.97.2.6  raeburn  5226:             if (document.$formname.crstype.value == 'Community') {
                   5227:                 alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
                   5228:             } else {
                   5229:                 alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
                   5230:             }
1.19      raeburn  5231:             return;
                   5232:         }
                   5233:         for (var j=0; j<newsecs.length; j++) {
                   5234:             if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
                   5235:                 alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
                   5236:                 return;
                   5237:             }
                   5238:             if (document.$formname.groups.value != '') {
                   5239:                 var groups = document.$formname.groups.value.split(/,/g);
                   5240:                 for (var k=0; k<groups.length; k++) {
                   5241:                     if (newsecs[j] == groups[k]) {
1.97.2.6  raeburn  5242:                         if (document.$formname.crstype.value == 'Community') {
                   5243:                             alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
                   5244:                         } else {
                   5245:                             alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
                   5246:                         }
1.19      raeburn  5247:                         return;
                   5248:                     }
                   5249:                 }
                   5250:             }
                   5251:         }
                   5252:         if ((userrole == 'cc') && (numsections > 0)) {
                   5253:             alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
                   5254:             section = "";
                   5255:         }
1.97.2.6  raeburn  5256:         if ((userrole == 'co') && (numsections > 0)) {
                   5257:             alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
                   5258:             section = "";
                   5259:         }
1.19      raeburn  5260: SCRIPTTOP
                   5261:     if ($mode ne 'upload') {
                   5262:         $dc_setcourse_code .= (<<"ENDSCRIPT");
                   5263:         var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
                   5264:         var numcourse = getIndex(document.$formname.dccourse);
                   5265:         if (numcourse == "-1") {
1.97.2.6  raeburn  5266:             if (document.$formname.type == 'Community') {
                   5267:                 alert("$alerts{'thwc'}");
                   5268:             } else {
                   5269:                 alert("$alerts{'thwa'}");
                   5270:             }
1.19      raeburn  5271:             return;
                   5272:         }
                   5273:         else {
                   5274:             document.$formname.elements[numcourse].name = "act"+coursename;
                   5275:             var numnewsec = getIndex(document.$formname.newsec);
                   5276:             if (numnewsec != "-1") {
                   5277:                 document.$formname.elements[numnewsec].name = "sec"+coursename;
                   5278:                 document.$formname.elements[numnewsec].value = section;
                   5279:             }
                   5280:             var numstart = getIndex(document.$formname.start);
                   5281:             if (numstart != "-1") {
                   5282:                 document.$formname.elements[numstart].name = "start"+coursename;
                   5283:             }
                   5284:             var numend = getIndex(document.$formname.end);
                   5285:             if (numend != "-1") {
                   5286:                 document.$formname.elements[numend].name = "end"+coursename
                   5287:             }
                   5288:         }
                   5289:     }
1.37      raeburn  5290:     var authcheck = auth_check();
                   5291:     if (authcheck == 'ok') {
                   5292:         document.$formname.submit();
                   5293:     }
1.19      raeburn  5294: }
                   5295: ENDSCRIPT
                   5296:     } else {
                   5297:         $dc_setcourse_code .=  "
                   5298:         document.$formname.sections.value = section;
                   5299:     }
                   5300:     return 'ok';
                   5301: }
                   5302: ";
                   5303:     }
                   5304:     $dc_setcourse_code .= (<<"ENDSCRIPT");
                   5305: 
                   5306:     function getIndex(caller) {
                   5307:         for (var i=0;i<document.$formname.elements.length;i++) {
                   5308:             if (document.$formname.elements[i] == caller) {
                   5309:                 return i;
                   5310:             }
                   5311:         }
                   5312:         return -1;
                   5313:     }
                   5314: ENDSCRIPT
1.37      raeburn  5315:     return $dc_setcourse_code;
                   5316: }
                   5317: 
                   5318: sub verify_authen {
                   5319:     my ($formname,$context) = @_;
                   5320:     my %alerts = &authcheck_alerts();
                   5321:     my $finish = "return 'ok';";
                   5322:     if ($context eq 'author') {
                   5323:         $finish = "document.$formname.submit();";
                   5324:     }
                   5325:     my $outcome = <<"ENDSCRIPT";
                   5326: 
                   5327: function auth_check() {
                   5328:     var logintype;
                   5329:     if (document.$formname.login.length) {
                   5330:         if (document.$formname.login.length > 0) {
                   5331:             var loginpicked = 0;
                   5332:             for (var i=0; i<document.$formname.login.length; i++) {
                   5333:                 if (document.$formname.login[i].checked == true) {
                   5334:                     loginpicked = 1;
                   5335:                     logintype = document.$formname.login[i].value;
                   5336:                 }
                   5337:             }
                   5338:             if (loginpicked == 0) {
                   5339:                 alert("$alerts{'authen'}");
                   5340:                 return;
                   5341:             }
                   5342:         }
                   5343:     } else {
                   5344:         logintype = document.$formname.login.value;
                   5345:     }
                   5346:     if (logintype == 'nochange') {
                   5347:         return 'ok';
                   5348:     }
                   5349:     var argpicked = document.$formname.elements[logintype+'arg'].value;
                   5350:     if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
                   5351:         var alertmsg = '';
                   5352:         switch (logintype) {
                   5353:             case 'krb':
                   5354:                 alertmsg = '$alerts{'krb'}';
                   5355:                 break;
                   5356:             case 'int':
                   5357:                 alertmsg = '$alerts{'ipass'}';
                   5358:             case 'fsys':
                   5359:                 alertmsg = '$alerts{'ipass'}';
                   5360:                 break;
                   5361:             case 'loc':
                   5362:                 alertmsg = '';
                   5363:                 break;
                   5364:             default:
                   5365:                 alertmsg = '';
                   5366:         }
                   5367:         if (alertmsg != '') {
                   5368:             alert(alertmsg);
                   5369:             return;
                   5370:         }
                   5371:     }
                   5372:     $finish
                   5373: }
                   5374: ENDSCRIPT
1.19      raeburn  5375: }
                   5376: 
                   5377: sub sectioncheck_alerts {
                   5378:     my %alerts = &Apache::lonlocal::texthash(
1.97.2.6  raeburn  5379:                     curd => 'You must select a course or community in the current domain',
1.19      raeburn  5380:                     inea => 'In each course, each user may only have one student role at a time',
1.97.2.6  raeburn  5381:                     inco => 'In each community, each user may only have one member role at a time',
1.19      raeburn  5382:                     youh => 'You had selected',
                   5383:                     sect => 'sections',
                   5384:                     plsm => 'Please modify your selections so they include no more than one section',
                   5385:                     mayn => 'may not be used as the name for a section, as it is a reserved word',
                   5386:                     plsc => 'Please choose a different section name',
                   5387:                     mayt => 'may not be used as the name for a section, as it is the name of a course group',
1.97.2.6  raeburn  5388:                     mayc => 'may not be used as the name for a section, as it is the name of a community group',
1.19      raeburn  5389:                     secn => 'Section names and group names must be distinct',
                   5390:                     secd => 'Section designations do not apply to ',
                   5391:                     role => 'roles',
                   5392:                     accr => 'role will be added with access to all sections',
1.97.2.6  raeburn  5393:                     thwa => 'There was a problem with your course selection',
                   5394:                     thwc => 'There was a problem with your community selection',
1.19      raeburn  5395:                  );
                   5396:     return %alerts;
                   5397: }
1.17      raeburn  5398: 
1.37      raeburn  5399: sub authcheck_alerts {
                   5400:     my %alerts = 
                   5401:         &Apache::lonlocal::texthash(
                   5402:                     authen => 'You must choose an authentication type.',
                   5403:                     krb    => 'You need to specify the Kerberos domain.',
                   5404:                     ipass  => 'You need to specify the initial password.',
                   5405:         );
                   5406:     return %alerts;
                   5407: }
                   5408: 
1.1       raeburn  5409: 1;
                   5410: 

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