Annotation of loncom/interface/londropadd.pm, revision 1.4

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to drop and add students in courses 
                      3: #
                      4: # (Handler to set parameters for assessments
                      5: #
                      6: # (Handler to resolve ambiguous file locations
                      7: #
                      8: # (TeX Content Handler
                      9: #
                     10: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     11: #
                     12: # 10/11,10/12,10/16 Gerd Kortemeyer)
                     13: #
                     14: # 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
                     15: # 12/08,12/12 Gerd Kortemeyer)
                     16: #
1.3       www        17: # 12/26, 12/27 Gerd Kortemeyer
1.1       www        18: 
                     19: package Apache::londropadd;
                     20: 
                     21: use strict;
                     22: use Apache::lonnet;
                     23: use Apache::Constants qw(:common :http REDIRECT);
                     24: 
                     25: 
                     26: # ================================================================ Main Handler
                     27: 
                     28: sub handler {
                     29:    my $r=shift;
                     30: 
                     31:    if ($r->header_only) {
                     32:       $r->content_type('text/html');
                     33:       $r->send_http_header;
                     34:       return OK;
                     35:    }
                     36: 
                     37: # ----------------------------------------------------- Needs to be in a course
                     38: 
                     39:    if (($ENV{'request.course.fn'}) && 
                     40:        (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
                     41: 
                     42: # ------------------------------------------------------------------ Start page
                     43:       $r->content_type('text/html');
                     44:       $r->send_http_header;
                     45:       $r->print(<<ENDHEAD);
                     46: <html>
                     47: <head>
                     48: <title>LON-CAPA Student Drop/Add</title>
                     49: </head>
                     50: <body bgcolor="#FFFFFF">
                     51: <img align=right src=/adm/lonIcons/lonlogos.gif>
                     52: <h1>Drop/Add Students</h1>
                     53: <form method="post" enctype="multipart/form-data"
                     54: action="/adm/dropadd" name="studentform">
                     55: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
                     56: ENDHEAD
1.2       www        57: # --------------------------------------------------- Phase one, initial screen
                     58:     unless ($ENV{'form.phase'}) {
                     59: 	$r->print(<<ENDUPFORM);
                     60: <input type=hidden name=phase value=two>
                     61: <hr>
                     62: <h3>Upload a courselist</h3>
                     63: <input type=file name=upfile size=50>
                     64: <br>Type: <select name=upfiletype>
                     65: <option value=csv>CSV (comma separated values, spreadsheet)</option>
                     66: <option value=space>Space separated</option>
                     67: <option value=tab>Tabulator separated</option>
                     68: <option value=xml>HTML/XML</option>
                     69: </select>
                     70: <p><input type=submit name=fileupload value="Upload Courselist">
                     71: <hr>
                     72: <h3>Enroll a single student</h3>
                     73: <p><input type=submit name=enroll value="Enroll Student">
                     74: <hr>
                     75: <h3>Drop a student</h3>
                     76: <p><input type=submit name=drop value="Drop Student">
                     77: ENDUPFORM
                     78:       }
                     79: # ------------------------------------------------------------------- Phase two
                     80:       if ($ENV{'form.phase'} eq 'two') {
                     81: 	  if ($ENV{'form.fileupload'}) {
1.4     ! www        82: 	      my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.
        !            83: 		  '_enroll_'.$ENV{'request.course.id'}.'_'.time.'_'.$$;
        !            84: 	    {
        !            85:                 my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').
        !            86:                                          '/tmp/'.$datatoken.'.tmp');
        !            87: 		print $fh $ENV{'form.upfile'};
        !            88: 	    }
1.2       www        89:              my $separator='';
                     90:              my $remove='';
                     91:              if ($ENV{'form.upfiletype'} eq 'csv') {
                     92: 		 $separator='\"\,\s*\"';
                     93:                  $remove='"';
                     94:              } elsif ($ENV{'form.upfiletype'} eq 'space') {
                     95:                  $separator='\s+';
                     96:              } elsif ($ENV{'form.upfiletype'} eq 'tab') {
                     97:                  $separator='\t+';
                     98:              } elsif ($ENV{'form.upfiletype'} eq 'xml') {
                     99:              }
                    100:              my @lines=split(/\n/,$ENV{'form.upfile'});
1.4     ! www       101:              my $total=$#lines;
1.3       www       102:              $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                    103: 	     my $krbdefdom=$1;
                    104:              $krbdefdom=~tr/a-z/A-Z/;
1.4     ! www       105:              my $today=time;
        !           106:              my $halfyear=$today+15552000;
        !           107:              my $defdom=$r->dir_config('lonDefDomain');
1.2       www       108: 	     $r->print(<<ENDPICK);
                    109: <input type=hidden name=phase value=three>
                    110: <input type=hidden name=datatoken value="$datatoken">
                    111: <input type=hidden name=upfiletype value=$ENV{'form.upfiletype'}>
                    112: <hr>
                    113: <h3>Identify fields</h3>
1.4     ! www       114: Total number of records found in file: $total
1.3       www       115: <script>
                    116: function verify(vf) {
                    117:     var founduname=0;
                    118:     var foundpwd=0;
                    119:     var foundname=0;
                    120:     var foundid=0;
                    121:     var foundsec=0;
                    122:     var foundatype=0;
                    123:     var tw;
                    124:     var message='';
                    125:     for (i=0;i<=vf.nfields.value;i++) {
                    126:         tw=eval('vf.f'+i+'.selectedIndex');
                    127:         if (tw==1) { founduname=1; }
                    128:         if ((tw>=2) && (tw<=6)) { foundname=1; }
                    129:         if (tw==7) { foundid=1; }
                    130:         if (tw==8) { foundsec=1; } 
                    131:         if (tw==9) { foundpwd=1; }
                    132:     }
                    133:     if (founduname==0) {
                    134: 	alert('You need to specify at least the username field');
                    135:         return;
                    136:     }
                    137:     if (vf.login[0].checked) {
                    138: 	foundatype=1;
                    139:         if (vf.krbdom.value=='') {
                    140: 	    alert('You need to specify the Kerberos domain');
                    141:             return;
                    142:         }
                    143:     }
                    144:     if (vf.login[1].checked) {
                    145: 	foundatype=1;
                    146:         if ((vf.intpwd.value=='') && (foundpwd==0)) {
                    147: 	    alert('You need to specify the initial password');
                    148:             return;
                    149:         }
                    150:     }
                    151:     if (foundatype==0) {
                    152: 	alert('You need to set the login type');
                    153:         return;
                    154:     }
                    155:     if (foundname==0) { message='No name fields specified. '; }
                    156:     if (foundid==0) { message+='No ID or student number field specified. '; }
                    157:     if (foundsec==0) { message+='No section or group field specified. '; }
1.4     ! www       158:     if (vf.startdate.value=='') {
        !           159: 	message+='No starting date set. ';
1.3       www       160:     }
1.4     ! www       161:     if (vf.enddate.value=='') {
        !           162:         message+='No ending date set. ';
        !           163:     }
        !           164:     if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
        !           165:        if (vf.enddate.value<vf.startdate.value) {
        !           166:           alert('Ending date is before starting date');
        !           167:           return;
        !           168:        }
        !           169:     }
        !           170:     if (message!='') {
        !           171:        message+='Continue enrollment?';
        !           172:        if (confirm(message)) {
        !           173: 	  pclose();
        !           174: 	  vf.submit();
        !           175:        }
        !           176:     } else {
        !           177:       pclose();
        !           178:       vf.submit();
        !           179:     }   
1.3       www       180: }
                    181: 
                    182: function flip(vf,tf) {
                    183:    var nw=eval('vf.f'+tf+'.selectedIndex');
                    184:    var i;
                    185:    for (i=0;i<=vf.nfields.value;i++) {
                    186:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
                    187:           eval('vf.f'+i+'.selectedIndex=0;')      
                    188:       } 
                    189:    }
                    190:    if (nw==2) {
                    191:       for (i=0;i<=vf.nfields.value;i++) {
                    192:          if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
                    193:              (eval('vf.f'+i+'.selectedIndex')<=6)) {
                    194:              eval('vf.f'+i+'.selectedIndex=0;')
                    195:          }
                    196:       }      
                    197:    }
                    198:    if ((nw>=3) && (nw<=6)) {
                    199:       for (i=0;i<=vf.nfields.value;i++) {
                    200:          if (eval('vf.f'+i+'.selectedIndex')==2) {
                    201:              eval('vf.f'+i+'.selectedIndex=0;')
                    202:          }
                    203:       }      
                    204:    }
                    205:    if (nw==9) {
                    206:        vf.login[1].checked=true;
                    207:        vf.intpwd.value='';
                    208:        vf.krbdom.value='';
                    209:    }
                    210: 
                    211: }
                    212: 
                    213: function clearpwd(vf) {
                    214:     var i;
                    215:     for (i=0;i<=vf.nfields.value;i++) {
                    216:         if (eval('vf.f'+i+'.selectedIndex')==9) {
                    217:             eval('vf.f'+i+'.selectedIndex=0;')
                    218:         }
                    219:     }      
                    220: }
                    221: 
                    222: function setkrb(vf) {
                    223:     if (vf.krbdom.value!='') {
                    224:        clearpwd(vf);
                    225:        vf.login[0].checked=true;
                    226:        vf.krbdom.value=vf.krbdom.value.toUpperCase();
                    227:        vf.intpwd.value='';
                    228:    }
                    229: }
                    230: 
                    231: function setint(vf) {
                    232:     if (vf.intpwd.value!='') {
                    233:        clearpwd(vf);
                    234:        vf.login[1].checked=true;
                    235:        vf.krbdom.value='';
                    236:    }
                    237: }
                    238: 
                    239: function clickkrb(vf) {
                    240:     vf.krbdom.value='$krbdefdom';
                    241:     clearpwd(vf);
                    242:     vf.intpwd.value='';
                    243: }
                    244: 
                    245: function clickint(vf) {
                    246:     vf.krbdom.value='';
                    247: }
                    248: 
1.4     ! www       249:     function pclose() {
        !           250:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
        !           251:                  "height=350,width=350,scrollbars=no,menubar=no");
        !           252:         parmwin.close();
        !           253:     }
        !           254: 
        !           255:     function pjump(type,dis,value,marker,ret,call) {
        !           256:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
        !           257:                  +"&value="+escape(value)+"&marker="+escape(marker)
        !           258:                  +"&return="+escape(ret)
        !           259:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
        !           260:                  "height=350,width=350,scrollbars=no,menubar=no");
        !           261: 
        !           262:     }
        !           263: 
        !           264:     function dateset() {
        !           265:         if (document.studentform.pres_marker.value=='end') {
        !           266:            document.studentform.enddate.value=
        !           267: 	       document.studentform.pres_value.value;
        !           268:         }
        !           269:         if (document.studentform.pres_marker.value=='start') {
        !           270:            document.studentform.startdate.value=
        !           271: 	       document.studentform.pres_value.value;
        !           272:         }
        !           273:         pclose();
        !           274:     }
1.3       www       275: 
                    276: </script>
1.2       www       277: <table border=2><tr><th>Field</th><th>Samples</th></tr>
                    278: ENDPICK
                    279:              my @sone; my @stwo; my @sthree; my $nfields=0;
                    280:              if ($#lines>=0) {
                    281: 		$lines[0]=~s/^$remove//;
                    282:                 $lines[0]=~s/$remove$//;
                    283:                 @sone=split(/$separator/,$lines[0]);
                    284:                 $nfields=$#sone;
                    285:                 if ($#lines>=1) {
                    286:         	   $lines[1]=~s/^$remove//;
                    287:                    $lines[1]=~s/$remove$//;
                    288:                    @stwo=split(/$separator/,$lines[1]);
                    289:                    $nfields=$#stwo;
                    290: 	        }
                    291:                 if ($#lines>=2) {
                    292: 		   $lines[2]=~s/^$remove//;
                    293:                    $lines[2]=~s/$remove$//;
                    294:                    @sthree=split(/$separator/,$lines[2]);
                    295:                    $nfields=$#sthree;
                    296: 	        }
                    297:                 my $i;
                    298:                 for ($i=0;$i<=$nfields;$i++) {
1.3       www       299:                    $r->print('<tr><td><select name=f'.$i.
                    300:                        ' onChange="flip(this.form,'.$i.');">');
1.2       www       301:                    map {
                    302:                       my ($value,$display)=split(/\:/,$_);
                    303:                       $r->print('<option value='.$value.'>'.$display.
                    304:                               '</option>');
                    305:                    } ('none: ','username:Username',
                    306:                       'names:Last Name, First Names',
                    307:                       'fname:First Name','mname:Middle Names/Initials',
                    308:                       'lname:Last Name','gen:Generation',
1.3       www       309:                       'id:ID/Student Number','sec:Group/Section',
                    310:                       'ipwd:Initial Password');
1.2       www       311:                    $r->print('</select></td><td>');
                    312:                    if (defined($sone[$i])) { 
                    313:                       $r->print($sone[$i]."</br>\n"); 
                    314:                    }
                    315: 	           if (defined($stwo[$i])) { 
                    316:                       $r->print($stwo[$i]."</br>\n"); 
                    317:                    }
                    318: 	           if (defined($sthree[$i])) { 
                    319:                       $r->print($sthree[$i]."</br>\n"); 
                    320:                    }
                    321:                    $r->print('</td></tr>');
                    322: 	       }
                    323: 	     }
1.3       www       324:              $r->print(<<ENDPICK);
                    325: </table>
                    326: <input type=hidden name=nfields value=$nfields>
                    327: <h3>Login Type</h3>
                    328: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
                    329: Kerberos authenticated with domain
                    330: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
                    331: <input type=radio name=login value=int onClick="clickint(this.form);"> 
                    332: Internally authenticated (with initial password 
                    333: <input type=text size=10 name=intpwd onChange="setint(this.form);">)<p>
1.4     ! www       334: LON-CAPA domain: <input type=text size=10 value=$defdom name=lcdomain><p>
        !           335: 
        !           336: <input type="hidden" value='' name="pres_value">
        !           337: <input type="hidden" value='' name="pres_type">
        !           338: <input type="hidden" value='' name="pres_marker">
        !           339: <input type="hidden" value='$today' name=startdate>
        !           340: <input type="hidden" value='$halfyear' name=enddate>
        !           341: <a 
        !           342:  href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
        !           343: >Set Starting Date</a><p>
        !           344: 
        !           345: <a 
        !           346:  href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
        !           347: >Set Ending Date</a><p>
        !           348: 
1.3       www       349: <input type=button onClick="verify(this.form)" value="Submit Selection">
                    350: ENDPICK
1.2       www       351:          } elsif ($ENV{'form.enroll'}) {
                    352:          } elsif ($ENV{'form.drop'}) {
                    353:          }
                    354:       }
                    355: # ----------------------------------------------------------------- Phase three
                    356:       if ($ENV{'form.phase'} eq 'three') {
                    357: 	  if ($ENV{'form.datatoken'}) {
                    358:              my $separator='';
                    359:              my $remove='';
                    360:              if ($ENV{'form.upfiletype'} eq 'csv') {
                    361: 		 $separator='\"\,\s*\"';
                    362:                  $remove='"';
                    363:              } elsif ($ENV{'form.upfiletype'} eq 'space') {
                    364:                  $separator='\s+';
                    365:              } elsif ($ENV{'form.upfiletype'} eq 'tab') {
                    366:                  $separator='\t+';
                    367:              } elsif ($ENV{'form.upfiletype'} eq 'xml') {
                    368:              }
1.4     ! www       369:              my %fields=();
        !           370:              for (my $i=0;$i<=$ENV{'form.nfields'};$i++) {
        !           371:                  $fields{$ENV{'form.f'.$i}}=$i;
        !           372:              }
        !           373:              my $startdate=$ENV{'form.startdate'};
        !           374:              my $enddate=$ENV{'form.enddate'};
        !           375:              if ($startdate=~/\D/) { $startdate=''; }
        !           376:              if ($enddate=~/\D/) { $enddate=''; }
        !           377:              my $count=1;
        !           378:              my @studentdata=();
        !           379:              {
        !           380:                 my $fh;
        !           381:                 if ($fh=Apache::File->new($r->dir_config('lonDaemons').
        !           382: 		              '/tmp/'.$ENV{'form.datatoken'}.'.tmp')) {
        !           383: 		    @studentdata=<$fh>;
        !           384:                 }
        !           385: 	     }
1.2       www       386: 	      map {
1.4     ! www       387:                 my $line=$_;
        !           388:                 chomp($line);
        !           389:                 $line=~s/^$remove//;
        !           390:                 $line=~s/$remove$//;
        !           391: 	        my @entries=split(/$separator/,$line);
        !           392:                 unless (($entries[$fields{'username'}] eq '') ||
        !           393:                         (!defined($entries[$fields{'username'}]))) {
        !           394:                   my $fname=''; my $mname=''; my $lname=''; my $gen='';
        !           395:                   if (defined($fields{'names'})) {
        !           396: 		      ($lname,$fname,$mname)=
        !           397: 	            ($entries[$fields{'names'}]=~/([^\,]+)\,\s*(\w+)\s*(.*)$/);
        !           398:                   } else {
        !           399:                       if (defined($fields{'fname'})) {
        !           400: 		         $fname=$entries[$fields{'fname'}];
        !           401: 		      }
        !           402:                       if (defined($fields{'mname'})) {
        !           403: 		         $mname=$entries[$fields{'mname'}];
        !           404: 		      }
        !           405:                       if (defined($fields{'lname'})) {
        !           406: 		         $lname=$entries[$fields{'lname'}];
        !           407: 		      }
        !           408:                       if (defined($fields{'gen'})) {
        !           409: 		         $gen=$entries[$fields{'gen'}];
        !           410: 		      }
        !           411:                   }
        !           412:                   if ($entries[$fields{'username'}]=~/\W/) {
        !           413:                      $r->print('<p><b>Unacceptable username: '.
        !           414:                               $entries[$fields{'username'}].' for user '.
        !           415:                               $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
        !           416: 		  } else {   
        !           417: $r->print($count.': '.$fname.' - '.$mname.' - '.$lname.' - '.$gen.'<br>'); $count++;
        !           418:                   }
        !           419:                  }                 
        !           420:               } @studentdata;
1.2       www       421:           }
                    422:       }
                    423: # ------------------------------------------------------------------------- End
1.1       www       424:       $r->print('</form></body></html>');
                    425:    } else {
                    426: # ----------------------------- Not in a course, or not allowed to modify parms
                    427:       $ENV{'user.error.msg'}=
                    428:         "/adm/dropadd:cst:0:0:Cannot drop or add students";
                    429:       return HTTP_NOT_ACCEPTABLE; 
                    430:    }
                    431:    return OK;
                    432: }
                    433: 
                    434: 1;
                    435: __END__
                    436: 
                    437: 
                    438: 
                    439: 

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