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: #
17: # 12/26 Gerd Kortemeyer
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
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;
98: $r->print(<<ENDPICK);
99: <input type=hidden name=phase value=three>
100: <input type=hidden name=datatoken value="$datatoken">
101: <input type=hidden name=upfiletype value=$ENV{'form.upfiletype'}>
102: <hr>
103: <h3>Identify fields</h3>
104: Total number of students: $total
105: <table border=2><tr><th>Field</th><th>Samples</th></tr>
106: ENDPICK
107: my @sone; my @stwo; my @sthree; my $nfields=0;
108: if ($#lines>=0) {
109: $lines[0]=~s/^$remove//;
110: $lines[0]=~s/$remove$//;
111: @sone=split(/$separator/,$lines[0]);
112: $nfields=$#sone;
113: if ($#lines>=1) {
114: $lines[1]=~s/^$remove//;
115: $lines[1]=~s/$remove$//;
116: @stwo=split(/$separator/,$lines[1]);
117: $nfields=$#stwo;
118: }
119: if ($#lines>=2) {
120: $lines[2]=~s/^$remove//;
121: $lines[2]=~s/$remove$//;
122: @sthree=split(/$separator/,$lines[2]);
123: $nfields=$#sthree;
124: }
125: my $i;
126: for ($i=0;$i<=$nfields;$i++) {
127: $r->print('<tr><td><select name=f'.$i.'>');
128: map {
129: my ($value,$display)=split(/\:/,$_);
130: $r->print('<option value='.$value.'>'.$display.
131: '</option>');
132: } ('none: ','username:Username',
133: 'names:Last Name, First Names',
134: 'fname:First Name','mname:Middle Names/Initials',
135: 'lname:Last Name','gen:Generation',
136: 'id:ID/Student Number','sec:Group/Section');
137: $r->print('</select></td><td>');
138: if (defined($sone[$i])) {
139: $r->print($sone[$i]."</br>\n");
140: }
141: if (defined($stwo[$i])) {
142: $r->print($stwo[$i]."</br>\n");
143: }
144: if (defined($sthree[$i])) {
145: $r->print($sthree[$i]."</br>\n");
146: }
147: $r->print('</td></tr>');
148: }
149: }
150: $r->print(
151: '</table><p><input type=submit value="Submit Field Selection">');
152: } elsif ($ENV{'form.enroll'}) {
153: } elsif ($ENV{'form.drop'}) {
154: }
155: }
156: # ----------------------------------------------------------------- Phase three
157: if ($ENV{'form.phase'} eq 'three') {
158: if ($ENV{'form.datatoken'}) {
159: my $separator='';
160: my $remove='';
161: if ($ENV{'form.upfiletype'} eq 'csv') {
162: $separator='\"\,\s*\"';
163: $remove='"';
164: } elsif ($ENV{'form.upfiletype'} eq 'space') {
165: $separator='\s+';
166: } elsif ($ENV{'form.upfiletype'} eq 'tab') {
167: $separator='\t+';
168: } elsif ($ENV{'form.upfiletype'} eq 'xml') {
169: }
170: map {
171: my $line=$_;
172: $line=~s/^$remove//;
173: $line=~s/$remove$//;
174: my @entries=split(/$separator/,$line);
175: $r->print($entries[8].'<br>');
176: } split(/\n/,
177: &Apache::lonnet::unescape(Apache::lonnet::reply(
178: 'tmpget:'.$ENV{'form.datatoken'},$r->dir_config('lonHostID')))
179: );
180:
181: }
182: }
183: # ------------------------------------------------------------------------- End
184: $r->print('</form></body></html>');
185: } else {
186: # ----------------------------- Not in a course, or not allowed to modify parms
187: $ENV{'user.error.msg'}=
188: "/adm/dropadd:cst:0:0:Cannot drop or add students";
189: return HTTP_NOT_ACCEPTABLE;
190: }
191: return OK;
192: }
193:
194: 1;
195: __END__
196:
197:
198:
199:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>