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

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'}) {
                     82:              my $datatoken=Apache::lonnet::reply(
                     83:                 'tmpput:'.Apache::lonnet::escape($ENV{'form.upfile'}),
                     84:                 $r->dir_config('lonHostID'));
                     85:              my $separator='';
                     86:              my $remove='';
                     87:              if ($ENV{'form.upfiletype'} eq 'csv') {
                     88: 		 $separator='\"\,\s*\"';
                     89:                  $remove='"';
                     90:              } elsif ($ENV{'form.upfiletype'} eq 'space') {
                     91:                  $separator='\s+';
                     92:              } elsif ($ENV{'form.upfiletype'} eq 'tab') {
                     93:                  $separator='\t+';
                     94:              } elsif ($ENV{'form.upfiletype'} eq 'xml') {
                     95:              }
                     96:              my @lines=split(/\n/,$ENV{'form.upfile'});
                     97:              my $total=$#lines+1;
1.3     ! www        98:              $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
        !            99: 	     my $krbdefdom=$1;
        !           100:              $krbdefdom=~tr/a-z/A-Z/;
1.2       www       101: 	     $r->print(<<ENDPICK);
                    102: <input type=hidden name=phase value=three>
                    103: <input type=hidden name=datatoken value="$datatoken">
                    104: <input type=hidden name=upfiletype value=$ENV{'form.upfiletype'}>
                    105: <hr>
                    106: <h3>Identify fields</h3>
                    107: Total number of students: $total
1.3     ! www       108: <script>
        !           109: function verify(vf) {
        !           110:     var founduname=0;
        !           111:     var foundpwd=0;
        !           112:     var foundname=0;
        !           113:     var foundid=0;
        !           114:     var foundsec=0;
        !           115:     var foundatype=0;
        !           116:     var tw;
        !           117:     var message='';
        !           118:     for (i=0;i<=vf.nfields.value;i++) {
        !           119:         tw=eval('vf.f'+i+'.selectedIndex');
        !           120:         if (tw==1) { founduname=1; }
        !           121:         if ((tw>=2) && (tw<=6)) { foundname=1; }
        !           122:         if (tw==7) { foundid=1; }
        !           123:         if (tw==8) { foundsec=1; } 
        !           124:         if (tw==9) { foundpwd=1; }
        !           125:     }
        !           126:     if (founduname==0) {
        !           127: 	alert('You need to specify at least the username field');
        !           128:         return;
        !           129:     }
        !           130:     if (vf.login[0].checked) {
        !           131: 	foundatype=1;
        !           132:         if (vf.krbdom.value=='') {
        !           133: 	    alert('You need to specify the Kerberos domain');
        !           134:             return;
        !           135:         }
        !           136:     }
        !           137:     if (vf.login[1].checked) {
        !           138: 	foundatype=1;
        !           139:         if ((vf.intpwd.value=='') && (foundpwd==0)) {
        !           140: 	    alert('You need to specify the initial password');
        !           141:             return;
        !           142:         }
        !           143:     }
        !           144:     if (foundatype==0) {
        !           145: 	alert('You need to set the login type');
        !           146:         return;
        !           147:     }
        !           148:     if (foundname==0) { message='No name fields specified. '; }
        !           149:     if (foundid==0) { message+='No ID or student number field specified. '; }
        !           150:     if (foundsec==0) { message+='No section or group field specified. '; }
        !           151:     message+='Complete enrollment?';
        !           152:     if (confirm(message)) {
        !           153: 	vf.submit();
        !           154:     }
        !           155: }
        !           156: 
        !           157: function flip(vf,tf) {
        !           158:    var nw=eval('vf.f'+tf+'.selectedIndex');
        !           159:    var i;
        !           160:    for (i=0;i<=vf.nfields.value;i++) {
        !           161:       if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
        !           162:           eval('vf.f'+i+'.selectedIndex=0;')      
        !           163:       } 
        !           164:    }
        !           165:    if (nw==2) {
        !           166:       for (i=0;i<=vf.nfields.value;i++) {
        !           167:          if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
        !           168:              (eval('vf.f'+i+'.selectedIndex')<=6)) {
        !           169:              eval('vf.f'+i+'.selectedIndex=0;')
        !           170:          }
        !           171:       }      
        !           172:    }
        !           173:    if ((nw>=3) && (nw<=6)) {
        !           174:       for (i=0;i<=vf.nfields.value;i++) {
        !           175:          if (eval('vf.f'+i+'.selectedIndex')==2) {
        !           176:              eval('vf.f'+i+'.selectedIndex=0;')
        !           177:          }
        !           178:       }      
        !           179:    }
        !           180:    if (nw==9) {
        !           181:        vf.login[1].checked=true;
        !           182:        vf.intpwd.value='';
        !           183:        vf.krbdom.value='';
        !           184:    }
        !           185: 
        !           186: }
        !           187: 
        !           188: function clearpwd(vf) {
        !           189:     var i;
        !           190:     for (i=0;i<=vf.nfields.value;i++) {
        !           191:         if (eval('vf.f'+i+'.selectedIndex')==9) {
        !           192:             eval('vf.f'+i+'.selectedIndex=0;')
        !           193:         }
        !           194:     }      
        !           195: }
        !           196: 
        !           197: function setkrb(vf) {
        !           198:     if (vf.krbdom.value!='') {
        !           199:        clearpwd(vf);
        !           200:        vf.login[0].checked=true;
        !           201:        vf.krbdom.value=vf.krbdom.value.toUpperCase();
        !           202:        vf.intpwd.value='';
        !           203:    }
        !           204: }
        !           205: 
        !           206: function setint(vf) {
        !           207:     if (vf.intpwd.value!='') {
        !           208:        clearpwd(vf);
        !           209:        vf.login[1].checked=true;
        !           210:        vf.krbdom.value='';
        !           211:    }
        !           212: }
        !           213: 
        !           214: function clickkrb(vf) {
        !           215:     vf.krbdom.value='$krbdefdom';
        !           216:     clearpwd(vf);
        !           217:     vf.intpwd.value='';
        !           218: }
        !           219: 
        !           220: function clickint(vf) {
        !           221:     vf.krbdom.value='';
        !           222: }
        !           223: 
        !           224: 
        !           225:     
        !           226: </script>
1.2       www       227: <table border=2><tr><th>Field</th><th>Samples</th></tr>
                    228: ENDPICK
                    229:              my @sone; my @stwo; my @sthree; my $nfields=0;
                    230:              if ($#lines>=0) {
                    231: 		$lines[0]=~s/^$remove//;
                    232:                 $lines[0]=~s/$remove$//;
                    233:                 @sone=split(/$separator/,$lines[0]);
                    234:                 $nfields=$#sone;
                    235:                 if ($#lines>=1) {
                    236:         	   $lines[1]=~s/^$remove//;
                    237:                    $lines[1]=~s/$remove$//;
                    238:                    @stwo=split(/$separator/,$lines[1]);
                    239:                    $nfields=$#stwo;
                    240: 	        }
                    241:                 if ($#lines>=2) {
                    242: 		   $lines[2]=~s/^$remove//;
                    243:                    $lines[2]=~s/$remove$//;
                    244:                    @sthree=split(/$separator/,$lines[2]);
                    245:                    $nfields=$#sthree;
                    246: 	        }
                    247:                 my $i;
                    248:                 for ($i=0;$i<=$nfields;$i++) {
1.3     ! www       249:                    $r->print('<tr><td><select name=f'.$i.
        !           250:                        ' onChange="flip(this.form,'.$i.');">');
1.2       www       251:                    map {
                    252:                       my ($value,$display)=split(/\:/,$_);
                    253:                       $r->print('<option value='.$value.'>'.$display.
                    254:                               '</option>');
                    255:                    } ('none: ','username:Username',
                    256:                       'names:Last Name, First Names',
                    257:                       'fname:First Name','mname:Middle Names/Initials',
                    258:                       'lname:Last Name','gen:Generation',
1.3     ! www       259:                       'id:ID/Student Number','sec:Group/Section',
        !           260:                       'ipwd:Initial Password');
1.2       www       261:                    $r->print('</select></td><td>');
                    262:                    if (defined($sone[$i])) { 
                    263:                       $r->print($sone[$i]."</br>\n"); 
                    264:                    }
                    265: 	           if (defined($stwo[$i])) { 
                    266:                       $r->print($stwo[$i]."</br>\n"); 
                    267:                    }
                    268: 	           if (defined($sthree[$i])) { 
                    269:                       $r->print($sthree[$i]."</br>\n"); 
                    270:                    }
                    271:                    $r->print('</td></tr>');
                    272: 	       }
                    273: 	     }
1.3     ! www       274:              $r->print(<<ENDPICK);
        !           275: </table>
        !           276: <input type=hidden name=nfields value=$nfields>
        !           277: <h3>Login Type</h3>
        !           278: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
        !           279: Kerberos authenticated with domain
        !           280: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
        !           281: <input type=radio name=login value=int onClick="clickint(this.form);"> 
        !           282: Internally authenticated (with initial password 
        !           283: <input type=text size=10 name=intpwd onChange="setint(this.form);">)<p>
        !           284: <input type=button onClick="verify(this.form)" value="Submit Selection">
        !           285: ENDPICK
1.2       www       286:          } elsif ($ENV{'form.enroll'}) {
                    287:          } elsif ($ENV{'form.drop'}) {
                    288:          }
                    289:       }
                    290: # ----------------------------------------------------------------- Phase three
                    291:       if ($ENV{'form.phase'} eq 'three') {
                    292: 	  if ($ENV{'form.datatoken'}) {
                    293:              my $separator='';
                    294:              my $remove='';
                    295:              if ($ENV{'form.upfiletype'} eq 'csv') {
                    296: 		 $separator='\"\,\s*\"';
                    297:                  $remove='"';
                    298:              } elsif ($ENV{'form.upfiletype'} eq 'space') {
                    299:                  $separator='\s+';
                    300:              } elsif ($ENV{'form.upfiletype'} eq 'tab') {
                    301:                  $separator='\t+';
                    302:              } elsif ($ENV{'form.upfiletype'} eq 'xml') {
                    303:              }
                    304: 	      map {
                    305:                   my $line=$_;
                    306:                   $line=~s/^$remove//;
                    307:                   $line=~s/$remove$//;
                    308: 		  my @entries=split(/$separator/,$line);
                    309:                   $r->print($entries[8].'<br>');
                    310:               } split(/\n/,
                    311:                  &Apache::lonnet::unescape(Apache::lonnet::reply(
                    312:                  'tmpget:'.$ENV{'form.datatoken'},$r->dir_config('lonHostID')))
                    313:                  );
                    314:              
                    315:           }
                    316:       }
                    317: # ------------------------------------------------------------------------- End
1.1       www       318:       $r->print('</form></body></html>');
                    319:    } else {
                    320: # ----------------------------- Not in a course, or not allowed to modify parms
                    321:       $ENV{'user.error.msg'}=
                    322:         "/adm/dropadd:cst:0:0:Cannot drop or add students";
                    323:       return HTTP_NOT_ACCEPTABLE; 
                    324:    }
                    325:    return OK;
                    326: }
                    327: 
                    328: 1;
                    329: __END__
                    330: 
                    331: 
                    332: 
                    333: 

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