Annotation of loncom/interface/londropadd.pm, revision 1.56
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to drop and add students in courses
3: #
1.56 ! matthew 4: # $Id: londropadd.pm,v 1.55 2002/09/26 14:04:34 matthew Exp $
1.17 albertel 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: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: # (Handler to set parameters for assessments
29: #
30: # (Handler to resolve ambiguous file locations
31: #
32: # (TeX Content Handler
33: #
1.50 matthew 34: ###############################################################
35: ###############################################################
1.1 www 36:
37: package Apache::londropadd;
38:
39: use strict;
1.24 albertel 40: use Apache::lonnet();
41: use Apache::loncommon();
1.50 matthew 42: use Apache::lonhtmlcommon();
1.1 www 43: use Apache::Constants qw(:common :http REDIRECT);
44:
1.50 matthew 45: ###############################################################
46: ###############################################################
1.10 www 47: sub header {
1.46 www 48: my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
1.27 matthew 49: return(<<ENDHEAD);
1.1 www 50: <html>
51: <head>
1.40 matthew 52: <title>LON-CAPA Enrollment Manager</title>
1.1 www 53: </head>
1.46 www 54: $bodytag
1.40 matthew 55: <form method="post" enctype="multipart/form-data"
56: action="/adm/dropadd" name="studentform">
1.1 www 57: ENDHEAD
1.10 www 58: }
59:
1.50 matthew 60: ###############################################################
61: ###############################################################
62: # Drop student from all sections of a course, except optional $csec
1.26 matthew 63: sub modifystudent {
1.33 matthew 64: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
1.26 matthew 65: # if $csec is undefined, drop the student from all the courses matching
66: # this one. If $csec is defined, drop them from all other sections of
67: # this course and add them to section $csec
1.25 matthew 68: $courseid=~s/\_/\//g;
69: $courseid=~s/^(\w)/\/$1/;
1.26 matthew 70: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
71: my ($tmp) = keys(%roles);
72: # Bail out if we were unable to get the students roles
1.35 matthew 73: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1.26 matthew 74: # Go through the roles looking for enrollment in this course
1.35 matthew 75: my $result = '';
1.26 matthew 76: foreach my $course (keys(%roles)) {
1.35 matthew 77: if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
1.26 matthew 78: # We are in this course
1.25 matthew 79: my $section=$1;
1.26 matthew 80: $section='' if ($course eq $courseid.'_st');
1.35 matthew 81: if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
1.27 matthew 82: my (undef,$end,$start)=split(/\_/,$roles{$course});
1.25 matthew 83: my $now=time;
1.50 matthew 84: # if this is an active role
1.27 matthew 85: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
1.25 matthew 86: my $reply=&Apache::lonnet::modifystudent
1.33 matthew 87: ($udom,$unam,'','','','','','','',
88: $section,time,undef,undef,$desiredhost);
1.35 matthew 89: $result .= $reply.':';
1.25 matthew 90: }
1.10 www 91: }
92: }
1.20 harris41 93: }
1.35 matthew 94: if ($result eq '') {
95: $result eq 'Unable to find section for this student';
1.37 matthew 96: } else {
97: $result =~ s/(ok:)+/ok/g;
1.35 matthew 98: }
99: return $result;
1.10 www 100: }
101:
1.50 matthew 102: ###############################################################
103: ###############################################################
104: # build a domain and server selection form
1.31 matthew 105: sub domain_form {
106: my ($defdom) = @_;
107: # Set up domain and server selection forms
108: #
109: # Get the domains
110: my @domains = &Apache::loncommon::get_domains();
111: # build up the menu information to be passed to
112: # &Apache::loncommon::linked_select_forms
113: my %select_menus;
114: foreach my $dom (@domains) {
115: # set up the text for this domain
116: $select_menus{$dom}->{'text'}= $dom;
117: # we want a choice of 'default' as the default in the second menu
118: $select_menus{$dom}->{'default'}= 'default';
119: $select_menus{$dom}->{'select2'}->{'default'} = 'default';
120: # Now build up the other items in the second menu
1.45 matthew 121: my %servers = &Apache::loncommon::get_library_servers($dom);
1.31 matthew 122: foreach my $server (keys(%servers)) {
123: $select_menus{$dom}->{'select2'}->{$server}
124: = "$server $servers{$server}";
125: }
126: }
127: my $result = &Apache::loncommon::linked_select_forms
128: ('studentform',' with home server ',$defdom,
129: 'lcdomain','lcserver',\%select_menus);
130: return $result;
131: }
132:
1.50 matthew 133: ###############################################################
134: ###############################################################
135: # Menu Phase One
136: sub print_main_menu {
1.10 www 137: my $r=shift;
1.48 matthew 138: $r->print(<<END);
139: <p>
1.50 matthew 140: <font size="+1">
141: <a href="/adm/dropadd?action=upload">Upload a course list</a>
142: </font>
143: </p><p>
144: <font size="+1">
145: <a href="/adm/dropadd?action=enrollstudent">Enroll a single student</a>
146: </font>
1.48 matthew 147: </p><p>
1.50 matthew 148: <font size="+1">
149: <a href="/adm/dropadd?action=modifystudent">Modify student data</a>
150: </font>
1.48 matthew 151: </p><p>
1.50 matthew 152: <font size="+1">
153: <a href="/adm/dropadd?action=classlist">View Classlist</a>
154: </font>
1.48 matthew 155: </p><p>
1.50 matthew 156: <font size="+1">
157: <a href="/adm/dropadd?action=drop">Drop Students</a>
158: </font>
1.48 matthew 159: </p>
160: END
1.10 www 161: }
162:
1.50 matthew 163: ###############################################################
164: ###############################################################
165: sub print_upload_manager_header {
1.23 albertel 166: my ($r,$datatoken,$distotal,$krbdefdom)=@_;
1.24 albertel 167: my $javascript;
1.50 matthew 168: if (! exists($ENV{'form.upfile_associate'})) {
169: $ENV{'form.upfile_associate'} = 'forward';
170: }
171: if ($ENV{'form.associate'} eq 'Reverse Association') {
172: if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
173: $ENV{'form.upfile_associate'} = 'reverse';
174: } else {
175: $ENV{'form.upfile_associate'} = 'forward';
176: }
177: }
1.24 albertel 178: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1.50 matthew 179: $javascript=&upload_manager_javascript_reverse_associate();
1.24 albertel 180: } else {
1.50 matthew 181: $javascript=&upload_manager_javascript_forward_associate();
1.24 albertel 182: }
183: my $javascript_validations=&javascript_validations($krbdefdom);
1.10 www 184: $r->print(<<ENDPICK);
1.40 matthew 185: <h3>Uploading Class List</h3>
1.2 www 186: <hr>
187: <h3>Identify fields</h3>
1.22 albertel 188: Total number of records found in file: $distotal <hr />
189: Enter as many fields as you can. The system will inform you and bring you back
190: to this page if the data selected is insufficient to run your class.<hr />
1.36 albertel 191: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.50 matthew 192: <input type="hidden" name="action" value="upload" />
193: <input type="hidden" name="state" value="got_file" />
1.36 albertel 194: <input type="hidden" name="associate" value="" />
1.26 matthew 195: <input type="hidden" name="datatoken" value="$datatoken" />
1.24 albertel 196: <input type="hidden" name="fileupload" value="$ENV{'form.fileupload'}" />
197: <input type="hidden" name="upfiletype" value="$ENV{'form.upfiletype'}" />
1.26 matthew 198: <input type="hidden" name="upfile_associate"
199: value="$ENV{'form.upfile_associate'}" />
1.24 albertel 200: <hr />
1.28 matthew 201: <script type="text/javascript" language="Javascript">
1.24 albertel 202: $javascript
203: $javascript_validations
204: </script>
205: ENDPICK
206: }
207:
1.50 matthew 208: ###############################################################
209: ###############################################################
1.24 albertel 210: sub javascript_validations {
211: my ($krbdefdom)=@_;
1.28 matthew 212: my %param = ( formname => 'studentform',
213: kerb_def_dom => $krbdefdom );
214: my $authheader = &Apache::loncommon::authform_header(%param);
1.24 albertel 215: return (<<ENDPICK);
216: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec) {
1.3 www 217: var foundatype=0;
218: var message='';
219: if (founduname==0) {
1.28 matthew 220: alert('You need to specify the username field');
1.3 www 221: return;
222: }
1.29 matthew 223: if (current.radiovalue == null || current.radiovalue == 'nochange') {
1.28 matthew 224: // They did not check any of the login radiobuttons.
225: alert('You must choose an authentication type');
226: return;
227: }
228: foundatype=1;
1.29 matthew 229: if (current.argfield == null || current.argfield == '') {
1.28 matthew 230: var alertmsg = '';
1.29 matthew 231: switch (current.value) {
1.28 matthew 232: case 'krb':
233: alertmsg = 'You need to specify the Kerberos domain';
234: break;
235: case 'loc':
236: case 'fsys':
237: alertmsg = 'You need to specify the initial password';
238: break;
239: case 'fsys':
240: alertmsg = '';
241: break;
242: default:
243: alertmsg = '';
1.3 www 244: }
1.28 matthew 245: if (alertmsg != '') {
246: alert(alertmsg);
1.3 www 247: return;
248: }
249: }
1.28 matthew 250:
1.3 www 251: if (foundname==0) { message='No name fields specified. '; }
252: if (foundid==0) { message+='No ID or student number field specified. '; }
253: if (foundsec==0) { message+='No section or group field specified. '; }
1.4 www 254: if (vf.startdate.value=='') {
255: message+='No starting date set. ';
1.3 www 256: }
1.4 www 257: if (vf.enddate.value=='') {
258: message+='No ending date set. ';
259: }
260: if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
1.10 www 261: if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
1.4 www 262: alert('Ending date is before starting date');
263: return;
264: }
265: }
266: if (message!='') {
267: message+='Continue enrollment?';
268: if (confirm(message)) {
269: pclose();
1.50 matthew 270: vf.state.value='enrolling';
1.4 www 271: vf.submit();
272: }
273: } else {
274: pclose();
1.50 matthew 275: vf.state.value='enrolling';
1.4 www 276: vf.submit();
1.24 albertel 277: }
1.3 www 278: }
279:
280:
1.4 www 281: function pclose() {
282: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
283: "height=350,width=350,scrollbars=no,menubar=no");
284: parmwin.close();
285: }
286:
287: function pjump(type,dis,value,marker,ret,call) {
288: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
289: +"&value="+escape(value)+"&marker="+escape(marker)
290: +"&return="+escape(ret)
291: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
292: "height=350,width=350,scrollbars=no,menubar=no");
293:
294: }
295:
296: function dateset() {
297: if (document.studentform.pres_marker.value=='end') {
298: document.studentform.enddate.value=
299: document.studentform.pres_value.value;
300: }
301: if (document.studentform.pres_marker.value=='start') {
302: document.studentform.startdate.value=
303: document.studentform.pres_value.value;
304: }
305: pclose();
306: }
1.3 www 307:
1.28 matthew 308: $authheader
1.24 albertel 309: ENDPICK
1.28 matthew 310:
1.24 albertel 311: }
312:
1.50 matthew 313: ###############################################################
314: ###############################################################
315: sub upload_manager_javascript_forward_associate {
1.24 albertel 316: return(<<ENDPICK);
317: function verify(vf) {
318: var founduname=0;
319: var foundpwd=0;
320: var foundname=0;
321: var foundid=0;
322: var foundsec=0;
323: var tw;
324: for (i=0;i<=vf.nfields.value;i++) {
325: tw=eval('vf.f'+i+'.selectedIndex');
326: if (tw==1) { founduname=1; }
327: if ((tw>=2) && (tw<=6)) { foundname=1; }
328: if (tw==7) { foundid=1; }
329: if (tw==8) { foundsec=1; }
330: if (tw==9) { foundpwd=1; }
331: }
332: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
333: }
334:
1.49 matthew 335: //
336: // vf = this.form
337: // tf = column number
338: //
339: // values of nw
340: //
341: // 0 = none
342: // 1 = username
343: // 2 = names (lastname, firstnames)
344: // 3 = fname (firstname)
345: // 4 = mname (middlename)
346: // 5 = lname (lastname)
347: // 6 = gen (generation)
348: // 7 = id
349: // 8 = section
350: // 9 = ipwd (password)
351: //
1.24 albertel 352: function flip(vf,tf) {
353: var nw=eval('vf.f'+tf+'.selectedIndex');
354: var i;
1.49 matthew 355: // make sure no other columns are labeled the same as this one
1.24 albertel 356: for (i=0;i<=vf.nfields.value;i++) {
357: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
358: eval('vf.f'+i+'.selectedIndex=0;')
359: }
360: }
1.49 matthew 361: // If we set this to 'lastname, firstnames', clear out all the ones
362: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
1.24 albertel 363: if (nw==2) {
364: for (i=0;i<=vf.nfields.value;i++) {
365: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
366: (eval('vf.f'+i+'.selectedIndex')<=6)) {
367: eval('vf.f'+i+'.selectedIndex=0;')
368: }
369: }
370: }
1.49 matthew 371: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
372: // clear out any that are set to 'lastname, firstnames' (2)
1.24 albertel 373: if ((nw>=3) && (nw<=6)) {
374: for (i=0;i<=vf.nfields.value;i++) {
375: if (eval('vf.f'+i+'.selectedIndex')==2) {
376: eval('vf.f'+i+'.selectedIndex=0;')
377: }
378: }
379: }
1.49 matthew 380: // If we set the password, make the password form below correspond to
381: // the new value.
1.24 albertel 382: if (nw==9) {
1.28 matthew 383: changed_radio('int',document.studentform);
384: set_auth_radio_buttons('int',document.studentform);
385: vf.intarg.value='';
386: vf.krbarg.value='';
1.24 albertel 387: vf.locarg.value='';
388: }
389: }
390:
391: function clearpwd(vf) {
392: var i;
393: for (i=0;i<=vf.nfields.value;i++) {
394: if (eval('vf.f'+i+'.selectedIndex')==9) {
395: eval('vf.f'+i+'.selectedIndex=0;')
396: }
397: }
398: }
399:
400: ENDPICK
401: }
402:
1.50 matthew 403: ###############################################################
404: ###############################################################
405: sub upload_manager_javascript_reverse_associate {
1.24 albertel 406: return(<<ENDPICK);
407: function verify(vf) {
408: var founduname=0;
409: var foundpwd=0;
410: var foundname=0;
411: var foundid=0;
412: var foundsec=0;
413: var tw;
414: for (i=0;i<=vf.nfields.value;i++) {
415: tw=eval('vf.f'+i+'.selectedIndex');
416: if (i==0 && tw!=0) { founduname=1; }
417: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
418: if (i==6 && tw!=0) { foundid=1; }
419: if (i==7 && tw!=0) { foundsec=1; }
420: if (i==8 && tw!=0) { foundpwd=1; }
421: }
422: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
423: }
424:
425: function flip(vf,tf) {
426: var nw=eval('vf.f'+tf+'.selectedIndex');
427: var i;
428: // picked the all one one name field, reset the other name ones to blank
429: if (tf==1 && nw!=0) {
430: for (i=2;i<=5;i++) {
431: eval('vf.f'+i+'.selectedIndex=0;')
432: }
433: }
434: //picked one of the piecewise name fields, reset the all in
435: //one field to blank
436: if ((tf>=2) && (tf<=5) && (nw!=0)) {
437: eval('vf.f1.selectedIndex=0;')
438: }
439: // intial password specified, pick internal authentication
440: if (tf==8 && nw!=0) {
1.28 matthew 441: changed_radio('int',document.studentform);
442: set_auth_radio_buttons('int',document.studentform);
443: vf.krbarg.value='';
444: vf.intarg.value='';
1.24 albertel 445: vf.locarg.value='';
446: }
447: }
448:
449: function clearpwd(vf) {
450: var i;
451: if (eval('vf.f8.selectedIndex')!=0) {
452: eval('vf.f8.selectedIndex=0;')
453: }
454: }
1.2 www 455: ENDPICK
1.23 albertel 456: }
1.10 www 457:
1.50 matthew 458: ###############################################################
459: ###############################################################
460: sub print_upload_manager_footer {
1.23 albertel 461: my ($r,$i,$keyfields,$defdom,$today,$halfyear)=@_;
1.28 matthew 462: my %param = ( formname => 'document.studentform');
463: my $krbform = &Apache::loncommon::authform_kerberos(%param);
464: my $intform = &Apache::loncommon::authform_internal(%param);
465: my $locform = &Apache::loncommon::authform_local(%param);
1.31 matthew 466: my $domform = &domain_form($defdom);
1.23 albertel 467: $r->print(<<ENDPICK);
1.3 www 468: </table>
1.10 www 469: <input type=hidden name=nfields value=$i>
470: <input type=hidden name=keyfields value="$keyfields">
1.3 www 471: <h3>Login Type</h3>
1.15 albertel 472: <p>Note: this will not take effect if the user already exists</p>
473: <p>
1.28 matthew 474: $krbform
1.15 albertel 475: </p>
476: <p>
1.28 matthew 477: $intform
1.15 albertel 478: </p>
479: <p>
1.28 matthew 480: $locform
1.15 albertel 481: </p>
1.5 www 482: <h3>LON-CAPA Domain for Students</h3>
1.29 matthew 483: LON-CAPA domain: $domform <p>
1.5 www 484: <h3>Starting and Ending Dates</h3>
1.26 matthew 485: <input type="hidden" value='' name="pres_value" >
486: <input type="hidden" value='' name="pres_type" >
487: <input type="hidden" value='' name="pres_marker" >
488: <input type="hidden" value='$today' name="startdate" >
489: <input type="hidden" value='$halfyear' name="enddate" >
1.4 www 490: <a
491: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
492: >Set Starting Date</a><p>
493:
494: <a
495: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
496: >Set Ending Date</a><p>
1.5 www 497: <h3>Full Update</h3>
498: <input type=checkbox name=fullup value=yes> Full update
1.11 www 499: (also print list of users not enrolled anymore)<p>
1.18 www 500: <h3>ID/Student Number</h3>
501: <input type=checkbox name=forceid value=yes>
502: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.19 www 503: (only do if you know what you are doing)<p>
1.36 albertel 504: <input type="button" onClick="javascript:verify(this.form)" value="Update Courselist" /><br />
1.50 matthew 505: Note: for large courses, this operation may be time consuming.
1.3 www 506: ENDPICK
1.23 albertel 507: }
1.24 albertel 508:
1.23 albertel 509: # ======================================================= Menu Phase Two Upload
1.50 matthew 510: sub print_upload_manager_form {
1.23 albertel 511: my $r=shift;
1.26 matthew 512:
1.24 albertel 513: my $datatoken;
514: if (!$ENV{'form.datatoken'}) {
1.26 matthew 515: $datatoken=&Apache::loncommon::upfile_store($r);
1.24 albertel 516: } else {
1.26 matthew 517: $datatoken=$ENV{'form.datatoken'};
518: &Apache::loncommon::load_tmp_file($r);
1.24 albertel 519: }
520: my @records=&Apache::loncommon::upfile_record_sep();
1.23 albertel 521: my $total=$#records;
522: my $distotal=$total+1;
523: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
524: my $krbdefdom=$1;
525: $krbdefdom=~tr/a-z/A-Z/;
526: my $today=time;
527: my $halfyear=$today+15552000;
528: my $defdom=$r->dir_config('lonDefDomain');
1.50 matthew 529: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
1.24 albertel 530: my $i;
531: my $keyfields;
1.23 albertel 532: if ($total>=0) {
1.50 matthew 533: my @d=(['username','Username'],
534: ['names','Last Name, First Names'],
535: ['fname','First Name'],
536: ['mname','Middle Names/Initials'],
537: ['lname','Last Name'],
538: ['gen','Generation'],
539: ['id','ID/Student Number'],
540: ['sec','Group/Section'],
1.24 albertel 541: ['ipwd','Initial Password']);
542: if ($ENV{'form.upfile_associate'} eq 'reverse') {
543: &Apache::loncommon::csv_print_samples($r,\@records);
544: $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
545: foreach (@d) { $keyfields.=$_->[0].','; }
546: chop($keyfields);
547: } else {
548: unshift(@d,['none','']);
549: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
550: my %sone=&Apache::loncommon::record_sep($records[0]);
551: $keyfields=join(',',sort(keys(%sone)));
1.23 albertel 552: }
553: }
1.50 matthew 554: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
1.10 www 555: }
556:
1.12 www 557: # ======================================================= Enroll single student
558: sub enroll_single_student {
559: my $r=shift;
560: $r->print('<h3>Enrolling Student</h3>');
1.54 matthew 561: $r->print('<p>Enrolling '.$ENV{'form.cuname'}." \@ ".
1.34 matthew 562: $ENV{'form.lcdomain'}.'</p>');
1.12 www 563: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
1.31 matthew 564: ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
565: # Deal with home server selection
566: my $domain=$ENV{'form.lcdomain'};
567: my $desiredhost = $ENV{'form.lcserver'};
568: if (lc($desiredhost) eq 'default') {
569: $desiredhost = undef;
570: } else {
1.45 matthew 571: my %home_servers =&Apache::loncommon::get_library_servers($domain);
1.31 matthew 572: if (! exists($home_servers{$desiredhost})) {
573: $r->print('<font color="#ff0000">Error:</font>'.
574: 'Invalid home server specified');
575: return;
576: }
577: }
1.34 matthew 578: $r->print(" with server $desiredhost :") if (defined($desiredhost));
1.31 matthew 579: # End of home server selection logic
1.12 www 580: my $amode='';
581: my $genpwd='';
582: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 583: $amode='krb';
584: $amode.=$ENV{'form.krbver'};
1.28 matthew 585: $genpwd=$ENV{'form.krbarg'};
1.12 www 586: } elsif ($ENV{'form.login'} eq 'int') {
1.26 matthew 587: $amode='internal';
1.28 matthew 588: $genpwd=$ENV{'form.intarg'};
1.15 albertel 589: } elsif ($ENV{'form.login'} eq 'loc') {
590: $amode='localauth';
591: $genpwd=$ENV{'form.locarg'};
592: if (!$genpwd) { $genpwd=" "; }
593: }
1.34 matthew 594: my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
595: $ENV{'form.lcdomain'});
596: if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
1.55 matthew 597: # Clean out any old roles the student has in this class.
1.33 matthew 598: &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
599: $ENV{'request.course.id'},$ENV{'form.csec'},
600: $desiredhost);
1.55 matthew 601: my $login_result = &Apache::lonnet::modifystudent
602: ($ENV{'form.lcdomain'},$ENV{'form.cuname'},
603: $ENV{'form.cstid'},$amode,$genpwd,
604: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
605: $ENV{'form.clast'},$ENV{'form.cgen'},
606: $ENV{'form.csec'},$ENV{'form.enddate'},
607: $ENV{'form.startdate'},$ENV{'form.forceid'},
608: $desiredhost);
609: if ($login_result =~ /^ok/) {
610: $r->print($login_result);
611: $r->print("<p> If active, the new role will be available ".
612: "when the student next logs in to LON-CAPA.</p>");
613: } else {
614: $r->print("unable to enroll: ".$login_result);
615: }
1.12 www 616: } else {
1.34 matthew 617: $r->print('<p><font color="#ff0000">ERROR</font> '.
618: 'Invalid login mode or password. '.
619: 'Unable to enroll '.$ENV{'form.cuname'}.'.</p>');
1.12 www 620: }
621: } else {
622: $r->print('Invalid username or domain');
1.26 matthew 623: }
1.12 www 624: }
625:
1.10 www 626: # ======================================================= Menu Phase Two Enroll
1.50 matthew 627: sub print_enroll_single_student_form {
1.10 www 628: my $r=shift;
1.40 matthew 629: $r->print("<h3>Enroll One Student</h3>");
1.26 matthew 630: my ($krbdefdom) = $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
1.11 www 631: $krbdefdom=~tr/a-z/A-Z/;
1.26 matthew 632: my $today = time;
633: my $halfyear = $today+15552000;
1.11 www 634: my $defdom=$r->dir_config('lonDefDomain');
1.24 albertel 635: my $javascript_validations=&javascript_validations($krbdefdom);
1.28 matthew 636: # Set up authentication forms
637: my %param = ( formname => 'document.studentform');
638: my $krbform = &Apache::loncommon::authform_kerberos(%param);
639: my $intform = &Apache::loncommon::authform_internal(%param);
640: my $locform = &Apache::loncommon::authform_local(%param);
1.29 matthew 641: # Set up domain selection form
1.31 matthew 642: my $domform = &domain_form($defdom);
1.28 matthew 643: # Print it all out
1.50 matthew 644: $r->print(<<END);
645: <input type="hidden" name="action" value="enrollstudent">
646: <input type="hidden" name="state" value="done">
647:
1.28 matthew 648: <script type="text/javascript" language="Javascript">
1.12 www 649: function verify(vf) {
650: var founduname=0;
651: var foundpwd=0;
652: var foundname=0;
653: var foundid=0;
654: var foundsec=0;
655: var tw;
1.26 matthew 656: if ((typeof(vf.cuname.value) !="undefined") && (vf.cuname.value!='') &&
1.31 matthew 657: (typeof(vf.lcdomain.value)!="undefined") && (vf.lcdomain.value!='')) {
1.12 www 658: founduname=1;
659: }
1.14 harris41 660: if ((typeof(vf.cfirst.value)!="undefined") && (vf.cfirst.value!='') &&
1.26 matthew 661: (typeof(vf.clast.value) !="undefined") && (vf.clast.value!='')) {
1.12 www 662: foundname=1;
663: }
1.14 harris41 664: if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
1.12 www 665: foundsec=1;
666: }
1.14 harris41 667: if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
1.12 www 668: foundid=1;
669: }
670: if (founduname==0) {
671: alert('You need to specify at least the username and domain fields');
672: return;
673: }
1.24 albertel 674: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec);
1.12 www 675: }
676:
1.24 albertel 677: $javascript_validations
1.12 www 678:
1.24 albertel 679: function clearpwd(vf) {
680: //nothing else needs clearing
1.15 albertel 681: }
682:
1.12 www 683: </script>
1.11 www 684: <h3>Personal Data</h3>
1.50 matthew 685: <table>
686: <tr><td>First Name:</td><td> <input type="text" name="cfirst" size="15"></td></tr>
687: <tr><td>Middle Name:</td><td> <input type="text" name="cmiddle" size="15"></td></tr>
688: <tr><td>Last Name: </td><td><input type="text" name="clast" size="15"></td></tr>
689: <tr><td>Generation: </td><td><input type="text" name="cgen" size="5"> </td></tr>
690: </table>
1.11 www 691:
1.12 www 692: <h3>Login Data</h3>
1.26 matthew 693: <p>Username: <input type="text" name="cuname" size="15"></p>
1.29 matthew 694: <p>Domain: $domform</p>
1.26 matthew 695: <p>Note: login settings below will not take effect if the user already exists
696: </p><p>
1.28 matthew 697: $krbform
1.26 matthew 698: </p><p>
1.28 matthew 699: $intform
1.26 matthew 700: </p><p>
1.28 matthew 701: $locform
1.26 matthew 702: </p><p>
1.50 matthew 703:
704: <h3>Course Data</h3>
705:
706: <p>Group/Section: <input type="text" name="csec" size="5" />
707: <p>
708: <!-- Date setting form elements -->
709: <input type="hidden" name="pres_value" value='' />
710: <input type="hidden" name="pres_type" value='' />
711: <input type="hidden" name="pres_marker" value='' />
712: <input type="hidden" name="startdate" value='$today' />
713: <input type="hidden" name="enddate" value='$halfyear' />
1.26 matthew 714: </p><p>
1.11 www 715: <a
716: href="javascript:pjump('date_start','Enrollment Starting Date',document.studentform.startdate.value,'start','studentform.pres','dateset');"
1.26 matthew 717: >Set Starting Date</a>
718: </p><p>
1.11 www 719: <a
720: href="javascript:pjump('date_end','Enrollment Ending Date',document.studentform.enddate.value,'end','studentform.pres','dateset');"
1.26 matthew 721: >Set Ending Date</a>
1.50 matthew 722: </p>
723: <h3>ID/Student Number</h3>
724: <p>
725: ID/Student Number: <input type="text" name="cstid" size="10">
1.26 matthew 726: </p><p>
727: <input type="checkbox" name="forceid" value="yes">
1.18 www 728: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
1.50 matthew 729: (only do if you know what you are doing)
730: </p><p>
731: <input type="button" onClick="verify(this.form)" value="Enroll as student">
1.26 matthew 732: </p>
1.50 matthew 733: END
734: return;
1.10 www 735: }
736:
737: # ========================================================= Menu Phase Two Drop
1.51 matthew 738: sub print_drop_menu {
1.10 www 739: my $r=shift;
1.40 matthew 740: $r->print("<h3>Drop Students</h3>");
1.11 www 741: my $cid=$ENV{'request.course.id'};
1.56 ! matthew 742: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
! 743: if (! defined($classlist)) {
1.27 matthew 744: $r->print("There are no students currently enrolled.\n");
1.51 matthew 745: return;
1.25 matthew 746: }
1.51 matthew 747: # Print out the available choices
1.56 ! matthew 748: &show_drop_list($r,$classlist,$keylist);
1.51 matthew 749: return;
1.11 www 750: }
751:
1.40 matthew 752: # ============================================== view classlist
1.50 matthew 753: sub print_html_classlist {
1.40 matthew 754: my $r=shift;
1.48 matthew 755: $r->print(<<END);
1.50 matthew 756: <p>
1.48 matthew 757: <font size="+1">Current Classlist</font>
1.50 matthew 758: <font size="+1"><a href="/adm/dropadd?action=classlist&state=csv">CSV format</a></font>
759: </p>
1.48 matthew 760: END
1.40 matthew 761: my $cid=$ENV{'request.course.id'};
1.56 ! matthew 762: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
! 763: if (! defined($classlist)) {
1.40 matthew 764: $r->print("There are no students currently enrolled.\n");
765: } else {
766: # Print out the available choices
1.50 matthew 767: if ($ENV{'form.action'} eq 'modifystudent') {
1.53 matthew 768: &show_class_list($r,'view','modify','modifystudent',
1.56 ! matthew 769: 'Active',$classlist,$keylist);
1.50 matthew 770: } else {
1.53 matthew 771: &show_class_list($r,'view','aboutme','classlist',
1.56 ! matthew 772: 'Active',$classlist,$keylist);
1.50 matthew 773: }
1.41 matthew 774: }
775: }
776:
777: # ============================================== view classlist
1.50 matthew 778: sub print_csv_classlist {
1.41 matthew 779: my $r=shift;
780: my $cid=$ENV{'request.course.id'};
1.56 ! matthew 781: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
! 782: if (! defined($classlist)) {
1.41 matthew 783: $r->print("There are no students currently enrolled.\n");
784: } else {
1.54 matthew 785: &show_class_list($r,'csv','nolink','csv',
1.56 ! matthew 786: 'Active',$classlist,$keylist);
1.40 matthew 787: }
788: }
789:
790: # =================================================== Show student list to drop
791: sub show_class_list {
1.56 ! matthew 792: my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
1.40 matthew 793: my $cid=$ENV{'request.course.id'};
1.53 matthew 794: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
795: ['sortby']);
796: my $sortby = $ENV{'form.sortby'};
797: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
798: $sortby = 'username';
799: }
1.42 matthew 800: # Print out header
1.41 matthew 801: if ($mode eq 'view') {
1.50 matthew 802: if ($linkto eq 'aboutme') {
1.56 ! matthew 803: $r->print('Select a user name to view the users personal page.');
1.50 matthew 804: } elsif ($linkto eq 'modify') {
805: $r->print('Select a user name to modify the students information');
806: }
1.41 matthew 807: $r->print(<<END);
1.53 matthew 808: <input type="hidden" name="sortby" value="$sortby" />
1.40 matthew 809: <p>
810: <table border=2>
1.53 matthew 811: <tr><th>
812: <a href="/adm/dropadd?action=$action&sortby=username">username</a>
813: </th><th>
814: <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
815: </th><th>
816: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
817: </th><th>
818: <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
819: </th><th>
820: <a href="/adm/dropadd?action=$action&sortby=section">section</a>
821: </th>
822: </tr>
1.40 matthew 823: END
1.41 matthew 824: } elsif ($mode eq 'csv') {
1.51 matthew 825: $r->print('"'.join('","',("username","domain","ID","student name",
1.50 matthew 826: "section")).'"'."\n");
1.41 matthew 827: }
1.56 ! matthew 828: #
! 829: # Sort the students
! 830: my %index;
! 831: my $i;
! 832: foreach (@$keylist) {
! 833: $index{$_} = $i++;
! 834: }
! 835: my $index = $index{$sortby};
! 836: my $second = $index{'username'};
! 837: my $third = $index{'domain'};
1.53 matthew 838: my @Sorted_Students = sort {
1.56 ! matthew 839: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
! 840: ||
! 841: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
! 842: ||
! 843: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
! 844: } (keys(%$classlist));
1.53 matthew 845: foreach my $student (@Sorted_Students) {
1.56 ! matthew 846: my $username = $classlist->{$student}->[$index{'username'}];
! 847: my $domain = $classlist->{$student}->[$index{'domain'}];
! 848: my $section = $classlist->{$student}->[$index{'section'}];
! 849: my $name = $classlist->{$student}->[$index{'fullname'}];
! 850: my $id = $classlist->{$student}->[$index{'id'}];
! 851: my $status = $classlist->{$student}->[$index{'status'}];
1.52 matthew 852: next if (($statusmode ne 'any') && ($status ne $statusmode));
1.51 matthew 853: if ($mode eq 'view') {
854: $r->print("<tr>\n <td>\n ");
855: if ($linkto eq 'nothing') {
856: $r->print($username);
857: } elsif ($linkto eq 'aboutme') {
858: $r->print(&Apache::loncommon::aboutmewrapper($username,
859: $username,
860: $domain));
861: } elsif ($linkto eq 'modify') {
862: $r->print('<a href="/adm/dropadd?action=modifystudent'.
863: '&state=selected'.'&sname='.$username.
1.53 matthew 864: '&sdom='.$domain.'&sortby='.$sortby.'">'.
865: $username."</a>\n");
1.50 matthew 866: }
1.51 matthew 867: $r->print(<<"END");
1.50 matthew 868: </td>
1.51 matthew 869: <td>$domain</td>
870: <td>$id</td>
871: <td>$name</td>
872: <td>$section</td>
1.40 matthew 873: </tr>
874: END
1.51 matthew 875: } elsif ($mode eq 'csv') {
876: # no need to bother with $linkto
877: my @line = ();
878: foreach ($username,$domain,$id,$name,$section) {
879: push @line,&Apache::loncommon::csv_translate($_);
1.41 matthew 880: }
1.51 matthew 881: my $tmp = $";
882: $" = '","';
883: $r->print("\"@line\"\n");
884: $" = $tmp;
1.40 matthew 885: }
886: }
1.41 matthew 887: $r->print('</table><br>') if ($mode eq 'view');
1.40 matthew 888: }
889:
1.50 matthew 890:
891: #
892: # print out form for modification of a single students data
893: #
894: sub print_modify_student_form {
895: my $r = shift();
896: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.53 matthew 897: ['sdom','sname','sortby']);
898: my $sname = $ENV{'form.sname'};
899: my $sdom = $ENV{'form.sdom'};
900: my $sortby = $ENV{'form.sortby'};
1.50 matthew 901: # determine the students name information
902: my %info=&Apache::lonnet::get('environment',
903: ['firstname','middlename',
1.52 matthew 904: 'lastname','generation','id'],
1.50 matthew 905: $sdom, $sname);
906: my ($tmp) = keys(%info);
907: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
908: $r->print('<font color="#ff0000" size="+2">Error</font>'.
909: '<p>'.
910: 'Unable to retrieve environment data for '.$sname.
911: 'in domain '.$sdom.'</p><p>'.
912: 'Please contact your LON-CAPA administrator '.
913: 'regarding this situation.</p></body></html>');
914: return;
915: }
916: # determine the students starting and ending times and section
917: my ($starttime,$endtime,$section) = &get_enrollment_data($sname,$sdom);
918: # Deal with date forms
919: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
920: 'startdate',
921: $starttime);
922: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
923: 'enddate',
924: $endtime);
925: # Make sure student is enrolled in course
926: $r->print(<<END);
1.52 matthew 927: <p>
928: <font size="+1">
929: Only domain coordinators can change a users password.
930: </font>
931: </p>
1.50 matthew 932: <input type="hidden" name="slogin" value="$sname" />
933: <input type="hidden" name="sdomain" value="$sdom" />
934: <input type="hidden" name="action" value="modifystudent" />
1.53 matthew 935: <input type="hidden" name="state" value="done" />
936: <input type="hidden" name="sortby" value="$sortby" />
1.50 matthew 937: <h2>Modify Enrollment for $info{'firstname'} $info{'middlename'}
938: $info{'lastname'} $info{'generation'}, $sname\@$sdom</h2>
939: <p>
940: <b>Student Name</b>
941: <table>
942: <tr><th>First</th><th>Middle</th><th>Last</th><th>Generation</th></tr>
943: <tr><td>
944: <input type="text" name="firstname" value="$info{'firstname'}" /></td><td>
945: <input type="text" name="middlename" value="$info{'middlename'}" /></td><td>
946: <input type="text" name="lastname" value="$info{'lastname'}" /></td><td>
947: <input type="text" name="generation" value="$info{'generation'}" /></td></tr>
948: </table>
949: </p><p>
1.52 matthew 950: <b>Student ID</b>: <input type="text" name="id" value="$info{'id'}" size="12"/>
951: </p><p>
1.53 matthew 952: <input type="checkbox" name="forceid" >
953: Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
954: (only do if you know what you are doing)
955: </p><p>
1.50 matthew 956: <b>Section</b>: <input type="text" name="section" value="$section" size="4"/>
957: </p><p>
958: <table>
959: <tr><td align="right"><b>Starting Date:</b></td><td>$startdateform</td></tr>
960: <tr><td align="right"><b>Ending Date:</b></td><td>$enddateform</td></tr>
961: </table>
962: </p>
963: <input type="submit" value="Submit Modifications" />
964: </body></html>
965: END
966: return;
967: }
968:
969: #
970: # modify a single students section
971: #
972: sub modify_single_student {
973: my $r = shift;
1.53 matthew 974: # Get the 'sortby' variable so the user does not need to re-sort
975: my $sortby = $ENV{'form.sortby'};
976: #
977: # We always need this information
978: my $slogin = $ENV{'form.slogin'};
979: my $sdom = $ENV{'form.sdomain'};
980: #
981: # Get the old data
982: my %old=&Apache::lonnet::get('environment',
983: ['firstname','middlename',
984: 'lastname','generation','id'],
985: $sdom, $slogin);
986: my ($tmp) = keys(%old);
987: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
988: $r->print("There was an error determining the environment values ".
989: " for $slogin \@ $sdom.");
990: return;
991: }
992: undef $tmp;
993: #
994: # Get the new data
1.50 matthew 995: my $firstname = $ENV{'form.firstname'};
996: my $middlename = $ENV{'form.middlename'};
997: my $lastname = $ENV{'form.lastname'};
998: my $generation = $ENV{'form.generation'};
999: my $section = $ENV{'form.section'};
1000: my $courseid = $ENV{'request.course.id'};
1.52 matthew 1001: my $sid = $ENV{'form.id'};
1.50 matthew 1002: my $starttime = &Apache::lonhtmlcommon::get_date_from_form('startdate',
1003: time);
1004: my $endtime = &Apache::lonhtmlcommon::get_date_from_form('enddate',
1005: time);
1006: my $displayable_starttime = localtime($starttime);
1007: my $displayable_endtime = localtime($endtime);
1.53 matthew 1008: #
1009: # check for forceid override
1010: if (($sid ne $old{'id'}) && (! exists($ENV{'form.forceid'}))) {
1011: $r->print("<font color=\"ff0000\">You changed the students id ".
1012: " but did not disable the ID change safeguard.".
1013: " The students id will not be changed.</font>");
1014: $sid = $old{'id'};
1015: }
1016: #
1.50 matthew 1017: # talk to the user about what we are going to do
1018: $r->print(<<END);
1.53 matthew 1019: <h2>Modifying data for user $slogin \@ $sdom </h2>
1.50 matthew 1020: <h3>Student Information</h3>
1.53 matthew 1021: <table rules="rows" border="1" cellpadding="3" >
1022: <tr>
1023: <th> Field </th>
1024: <th> Old Value </th>
1025: <th> New Value </th>
1026: </tr>
1027: <tr>
1028: <td> <b>First name</b> </td>
1029: <td> $old{'firstname'} </td>
1030: <td> $firstname </td>
1031: </tr><tr>
1032: <td> <b>Middle name</b> </td>
1033: <td> $old{'middlename'} </td>
1034: <td> $middlename </td>
1035: </tr><tr>
1036: <td> <b>Last name</b> </td>
1037: <td> $old{'lastname'} </td>
1038: <td> $lastname </td>
1039: </tr><tr>
1040: <td> <b>Generation</b> </td>
1041: <td> $old{'generation'} </td>
1042: <td> $generation </td>
1043: </tr><tr>
1044: <td> <b>ID</b> </td>
1045: <td> $old{'id'} </td>
1046: <td> $sid </td>
1047: </tr>
1.50 matthew 1048: </table>
1049: <h3>Role Information</h3>
1050: <table>
1051: <tr><td>Section </td><td> $section </td></tr>
1052: <tr><td>Start Time </td><td> $displayable_starttime </td></tr>
1053: <tr><td>End Time </td><td> $displayable_endtime </td></tr>
1054: </table>
1.52 matthew 1055: <p>
1.50 matthew 1056: END
1.53 matthew 1057: #
1.52 matthew 1058: # Send request(s) to modify data
1059: my $roleresults = &Apache::lonnet::modifystudent
1.53 matthew 1060: ($sdom,$slogin,$sid,undef,undef,$firstname,$middlename,$lastname,
1061: $generation,$section,$endtime,$starttime,$ENV{'form.forceid'});
1062: if ($roleresults eq 'refused' ) {
1.50 matthew 1063: $r->print("Your request to change the role information for this ".
1.53 matthew 1064: "student was refused. You do not appear to have ".
1065: "sufficient authority to change student information.");
1.50 matthew 1066: } elsif ($roleresults !~ /ok/) {
1067: $r->print("An error occurred during the attempt to change the role".
1.52 matthew 1068: " information for this student. <br />".
1069: "The error reported was ".
1.50 matthew 1070: $roleresults);
1.53 matthew 1071: &Apache::lonnet::logthis("londropadd:failed attempt to modify student".
1072: " data for ".$slogin." \@ ".$sdom." by ".
1073: $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
1074: ":".$roleresults);
1.50 matthew 1075: } else { # everything is okay!
1.52 matthew 1076: $r->print("Student information updated successfully. <br />".
1077: "The student must log out and log in again to see ".
1078: "these changes.");
1.50 matthew 1079: }
1080: $r->print(<<END);
1.52 matthew 1081: </p><p>
1.53 matthew 1082: <a href="/adm/dropadd?action=modifystudent&sortby=$sortby">Modify another students data</a>
1.50 matthew 1083: </body></html>
1084: END
1085: return;
1086: }
1087:
1088: sub get_enrollment_data {
1089: my ($sname,$sdomain) = @_;
1090: my $courseid = $ENV{'request.course.id'};
1091: $courseid =~ s:_:/:g;
1092: my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
1093: my ($tmp) = keys(%roles);
1094: # Bail out if we were unable to get the students roles
1095: return "666" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
1096: # Go through the roles looking for enrollment in this course
1097: my ($end,$start) = (undef,undef);
1098: my $section = '';
1099: my $count = scalar(keys(%roles));
1100: while (my ($course,$role) = each(%roles)) {
1101: &Apache::lonnet::logthis('course = '.$course.' role = '.$role);
1102: if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
1103: #
1104: # Get active role
1105: $section=$1;
1106: (undef,$end,$start)=split(/\_/,$role);
1107: my $now=time;
1108: my $notactive=0;
1109: if ($start) {
1110: if ($now<$start) { $notactive=1; }
1111: }
1112: if ($end) {
1113: if ($now>$end) { $notactive=1; }
1114: }
1115: unless ($notactive) { return ($start,$end,$section); }
1116: }
1117: }
1118: return ($start,$end,$section);
1119: }
1120:
1.56 ! matthew 1121: #################################################
! 1122: #################################################
! 1123:
! 1124: =pod
! 1125:
! 1126: =item show_drop_list
! 1127:
! 1128: Display a list of students to drop
! 1129: Inputs:
! 1130:
! 1131: =over 4
! 1132:
! 1133: =item $r, Apache request
! 1134:
! 1135: =item $classlist, hash pointer returned from loncoursedata::get_classlist();
! 1136:
! 1137: =item $keylist, array pointer returned from loncoursedata::get_classlist()
! 1138: which describes the order elements are stored in the %$classlist values.
! 1139:
! 1140: =item $nosort, if true, sorting links are omitted.
! 1141:
! 1142: =back
! 1143:
! 1144: =cut
! 1145:
! 1146: #################################################
! 1147: #################################################
1.11 www 1148: sub show_drop_list {
1.56 ! matthew 1149: my ($r,$classlist,$keylist,$nosort)=@_;
1.11 www 1150: my $cid=$ENV{'request.course.id'};
1.54 matthew 1151: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1152: ['sortby']);
1153: my $sortby = $ENV{'form.sortby'};
1154: if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
1155: $sortby = 'username';
1156: }
1.56 ! matthew 1157: #
1.54 matthew 1158: my $action = "drop";
1159: $r->print(<<END);
1160: <input type="hidden" name="sortby" value="$sortby" />
1161: <input type="hidden" name="action" value="$action" />
1.50 matthew 1162: <input type="hidden" name="state" value="done" />
1.32 matthew 1163: <script>
1.51 matthew 1164: function checkAll(field) {
1.32 matthew 1165: for (i = 0; i < field.length; i++)
1166: field[i].checked = true ;
1167: }
1168:
1.51 matthew 1169: function uncheckAll(field) {
1.32 matthew 1170: for (i = 0; i < field.length; i++)
1171: field[i].checked = false ;
1172: }
1173: </script>
1174: <p>
1.26 matthew 1175: <input type="hidden" name="phase" value="four">
1.56 ! matthew 1176: END
! 1177:
! 1178: if ($nosort) {
! 1179: $r->print(<<END);
! 1180: <table border=2>
! 1181: <tr>
! 1182: <th> </th>
! 1183: <th>username</th>
! 1184: <th>domain</th>
! 1185: <th>ID</th>
! 1186: <th>student name</th>
! 1187: <th>section</th>
! 1188: </tr>
! 1189: END
! 1190:
! 1191: } else {
! 1192: $r->print(<<END);
1.26 matthew 1193: <table border=2>
1.54 matthew 1194: <tr><th> </th>
1195: <th>
1196: <a href="/adm/dropadd?action=$action&sortby=username">username</a>
1197: </th><th>
1198: <a href="/adm/dropadd?action=$action&sortby=domain">domain</a>
1199: </th><th>
1200: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
1201: </th><th>
1202: <a href="/adm/dropadd?action=$action&sortby=fullname">student name</a>
1203: </th><th>
1204: <a href="/adm/dropadd?action=$action&sortby=section">section</a>
1205: </th>
1206: </tr>
1.26 matthew 1207: END
1.56 ! matthew 1208: }
! 1209: #
! 1210: # Sort the students
! 1211: my %index;
! 1212: my $i;
! 1213: foreach (@$keylist) {
! 1214: $index{$_} = $i++;
! 1215: }
! 1216: my $index = $index{$sortby};
! 1217: my $second = $index{'username'};
! 1218: my $third = $index{'domain'};
1.54 matthew 1219: my @Sorted_Students = sort {
1.56 ! matthew 1220: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
! 1221: ||
! 1222: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
! 1223: ||
! 1224: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
! 1225: } (keys(%$classlist));
1.54 matthew 1226: foreach my $student (@Sorted_Students) {
1.52 matthew 1227: my $error;
1.56 ! matthew 1228: my $username = $classlist->{$student}->[$index{'username'}];
! 1229: my $domain = $classlist->{$student}->[$index{'domain'}];
! 1230: my $section = $classlist->{$student}->[$index{'section'}];
! 1231: my $name = $classlist->{$student}->[$index{'fullname'}];
! 1232: my $id = $classlist->{$student}->[$index{'id'}];
! 1233: my $status = $classlist->{$student}->[$index{'status'}];
1.51 matthew 1234: next if ($status ne 'Active');
1235: #
1236: $r->print(<<"END");
1.26 matthew 1237: <tr>
1.51 matthew 1238: <td><input type="checkbox" name="droplist" value="$student"></td>
1239: <td>$username</td>
1240: <td>$domain</td>
1241: <td>$id</td>
1242: <td>$name</td>
1243: <td>$section</td>
1.26 matthew 1244: </tr>
1245: END
1.25 matthew 1246: }
1247: $r->print('</table><br>');
1.32 matthew 1248: $r->print(<<"END");
1249: </p><p>
1250: <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)">
1251: <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
1252: <p><input type=submit value="Drop Students"></p>
1253: END
1.51 matthew 1254: return;
1.10 www 1255: }
1256:
1.48 matthew 1257: #
1258: # Print out the initial form to get the courselist file
1259: #
1260: sub print_first_courselist_upload_form {
1261: my $r=shift;
1262: my $upfile_select=&Apache::loncommon::upfile_select_html();
1263: my $create_classlist_help =
1264: &Apache::loncommon::help_open_topic("Course_Create_Class_List",
1265: "How do I create a class list from a spreadsheet");
1266: my $create_csv_help =
1267: &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1268: "How do I create a CSV file from a spreadsheet");
1269: $r->print(<<ENDUPFORM);
1270: <input type=hidden name=phase value=two>
1271: <h3>Upload a courselist</h3>
1272: $upfile_select
1.50 matthew 1273: <p>
1274: <input type=submit name="fileupload" value="Upload Courselist">
1275: <input type="hidden" name="action" value="upload" />
1276: <input type="hidden" name="state" value="got_file" />
1277: </p>
1.48 matthew 1278: $create_classlist_help <br />
1279: $create_csv_help
1280: </body></html>
1281: ENDUPFORM
1282: return;
1283: }
1284:
1.10 www 1285: # ================================================= Drop/Add from uploaded file
1286: sub upfile_drop_add {
1287: my $r=shift;
1.24 albertel 1288: &Apache::loncommon::load_tmp_file($r);
1289: my @studentdata=&Apache::loncommon::upfile_record_sep();
1.26 matthew 1290: my @keyfields = split(/\,/,$ENV{'form.keyfields'});
1291: my $cid = $ENV{'request.course.id'};
1.25 matthew 1292: my %fields=();
1.26 matthew 1293: for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
1.25 matthew 1294: if ($ENV{'form.upfile_associate'} eq 'reverse') {
1295: if ($ENV{'form.f'.$i} ne 'none') {
1296: $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
1297: }
1298: } else {
1299: $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
1300: }
1301: }
1.26 matthew 1302: #
1303: my $startdate = $ENV{'form.startdate'};
1304: my $enddate = $ENV{'form.enddate'};
1.25 matthew 1305: if ($startdate=~/\D/) { $startdate=''; }
1.26 matthew 1306: if ($enddate=~/\D/) { $enddate=''; }
1.31 matthew 1307: # Determine domain and desired host (home server)
1.25 matthew 1308: my $domain=$ENV{'form.lcdomain'};
1.31 matthew 1309: my $desiredhost = $ENV{'form.lcserver'};
1310: if (lc($desiredhost) eq 'default') {
1311: $desiredhost = undef;
1312: } else {
1.45 matthew 1313: my %home_servers = &Apache::loncommon::get_library_servers($domain);
1.31 matthew 1314: if (! exists($home_servers{$desiredhost})) {
1315: $r->print('<font color="#ff0000">Error:</font>'.
1316: 'Invalid home server specified');
1317: return;
1318: }
1319: }
1.26 matthew 1320: # Determine authentication mechanism
1321: my $amode = '';
1322: my $genpwd = '';
1.25 matthew 1323: if ($ENV{'form.login'} eq 'krb') {
1.47 albertel 1324: $amode='krb';
1325: $amode.=$ENV{'form.krbver'};
1.28 matthew 1326: $genpwd=$ENV{'form.krbarg'};
1.25 matthew 1327: } elsif ($ENV{'form.login'} eq 'int') {
1328: $amode='internal';
1.28 matthew 1329: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
1330: $genpwd=$ENV{'form.intarg'};
1.25 matthew 1331: }
1332: } elsif ($ENV{'form.login'} eq 'loc') {
1333: $amode='localauth';
1334: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
1335: $genpwd=$ENV{'form.locarg'};
1336: }
1337: }
1338: unless (($domain=~/\W/) || ($amode eq '')) {
1.26 matthew 1339: #######################################
1340: ## Enroll Students ##
1341: #######################################
1.25 matthew 1342: $r->print('<h3>Enrolling Students</h3>');
1343: my $count=0;
1344: my $flushc=0;
1345: my %student=();
1.26 matthew 1346: # Get new classlist
1.25 matthew 1347: foreach (@studentdata) {
1348: my %entries=&Apache::loncommon::record_sep($_);
1.26 matthew 1349: # Determine student name
1.25 matthew 1350: unless (($entries{$fields{'username'}} eq '') ||
1351: (!defined($entries{$fields{'username'}}))) {
1.26 matthew 1352: my ($fname, $mname, $lname,$gen) = ('','','','');
1.25 matthew 1353: if (defined($fields{'names'})) {
1.26 matthew 1354: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
1355: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
1.25 matthew 1356: } else {
1357: if (defined($fields{'fname'})) {
1358: $fname=$entries{$fields{'fname'}};
1359: }
1360: if (defined($fields{'mname'})) {
1361: $mname=$entries{$fields{'mname'}};
1362: }
1363: if (defined($fields{'lname'})) {
1364: $lname=$entries{$fields{'lname'}};
1365: }
1366: if (defined($fields{'gen'})) {
1367: $gen=$entries{$fields{'gen'}};
1368: }
1369: }
1370: if ($entries{$fields{'username'}}=~/\W/) {
1371: $r->print('<p><b>Unacceptable username: '.
1.10 www 1372: $entries{$fields{'username'}}.' for user '.
1.4 www 1373: $fname.' '.$mname.' '.$lname.' '.$gen.'</b><p>');
1.25 matthew 1374: } else {
1.26 matthew 1375: # determine section number
1.25 matthew 1376: my $sec='';
1377: my $username=$entries{$fields{'username'}};
1378: if (defined($fields{'sec'})) {
1379: if (defined($entries{$fields{'sec'}})) {
1380: $sec=$entries{$fields{'sec'}};
1381: }
1382: }
1.26 matthew 1383: # determine student id number
1.25 matthew 1384: my $id='';
1385: if (defined($fields{'id'})) {
1386: if (defined($entries{$fields{'id'}})) {
1387: $id=$entries{$fields{'id'}};
1388: }
1389: $id=~tr/A-Z/a-z/;
1390: }
1.26 matthew 1391: # determine student password
1.25 matthew 1392: my $password='';
1393: if ($genpwd) {
1394: $password=$genpwd;
1395: } else {
1396: if (defined($fields{'ipwd'})) {
1397: if ($entries{$fields{'ipwd'}}) {
1398: $password=$entries{$fields{'ipwd'}};
1399: }
1400: }
1401: }
1.56 ! matthew 1402: # Clean up whitespace
! 1403: foreach (\$domain,\$username,\$id,\$fname,\$mname,
! 1404: \$lname,\$gen,\$sec) {
! 1405: $$_ =~ s/(\s+$|^\s+)//g;
! 1406: }
1.25 matthew 1407: if ($password) {
1.33 matthew 1408: &modifystudent($domain,$username,$cid,$sec,
1409: $desiredhost);
1.25 matthew 1410: my $reply=&Apache::lonnet::modifystudent
1411: ($domain,$username,$id,$amode,$password,
1412: $fname,$mname,$lname,$gen,$sec,$enddate,
1.31 matthew 1413: $startdate,$ENV{'form.forceid'},$desiredhost);
1.26 matthew 1414: if ($reply ne 'ok') {
1415: $r->print('<p><b>'.
1416: 'Error enrolling '.$username.': '.
1417: $reply.'</b></p>');
1.10 www 1418: } else {
1.7 www 1419: $count++; $flushc++;
1420: $student{$username}=1;
1.6 www 1421: $r->print('. ');
1.7 www 1422: if ($flushc>15) {
1423: $r->rflush;
1424: $flushc=0;
1425: }
1.6 www 1426: }
1.25 matthew 1427: } else {
1428: $r->print("<p><b>No password for $username</b><p>");
1429: }
1430: }
1.26 matthew 1431: }
1432: } # end of foreach (@studentdata)
1.55 matthew 1433: $r->print('<p>Processed Students: '.$count.'</p>');
1434: $r->print("<p>If active, the new role will be available when the ".
1435: "students next log in to LON-CAPA.</p>");
1.26 matthew 1436: #####################################
1437: # Drop students #
1438: #####################################
1.25 matthew 1439: if ($ENV{'form.fullup'} eq 'yes') {
1440: $r->print('<h3>Dropping Students</h3>');
1.26 matthew 1441: # Get current classlist
1.56 ! matthew 1442: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
! 1443: if (! defined($classlist)) {
! 1444: $r->print("There are no students currently enrolled.\n");
! 1445: } else {
! 1446: # Remove the students we just added from the list of students.
1.25 matthew 1447: foreach (@studentdata) {
1448: my %entries=&Apache::loncommon::record_sep($_);
1449: unless (($entries{$fields{'username'}} eq '') ||
1450: (!defined($entries{$fields{'username'}}))) {
1.56 ! matthew 1451: delete($classlist->{$entries{$fields{'username'}}.
1.26 matthew 1452: ':'.$domain});
1.25 matthew 1453: }
1454: }
1.56 ! matthew 1455: # Print out list of dropped students.
! 1456: &show_drop_list($r,$classlist,$keylist,'nosort');
1.25 matthew 1457: }
1458: }
1.26 matthew 1459: } # end of unless
1.10 www 1460: }
1461:
1.11 www 1462: # ================================================================== Phase four
1463: sub drop_student_list {
1464: my $r=shift;
1465: my $count=0;
1.35 matthew 1466: my @droplist;
1467: if (ref($ENV{'form.droplist'})) {
1468: @droplist = @{$ENV{'form.droplist'}};
1469: } else {
1470: @droplist = ($ENV{'form.droplist'});
1471: }
1472: foreach (@droplist) {
1.26 matthew 1473: my ($uname,$udom)=split(/\:/,$_);
1.56 ! matthew 1474: # drop student
1.35 matthew 1475: my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
1.37 matthew 1476: if ($result eq 'ok' || $result eq 'ok:') {
1.54 matthew 1477: $r->print('Dropped '.$uname.' @ '.$udom.'<br>');
1.35 matthew 1478: } else {
1.54 matthew 1479: $r->print('Error dropping '.$uname.' @ '.$udom.': '.$result.
1.35 matthew 1480: '<br />');
1481: }
1.26 matthew 1482: $count++;
1.20 harris41 1483: }
1.11 www 1484: $r->print('<p><b>Dropped '.$count.' student(s).</b>');
1485: $r->print('<p>Re-enrollment will re-activate data.');
1486: }
1487:
1.50 matthew 1488: ###################################################################
1489: ###################################################################
1490:
1491: =pod
1492:
1493: =item &handler
1494:
1495: The typical handler you see in all these modules. Takes $r, the
1496: http request, as an argument.
1497:
1498: The response to the request is governed by two form variables
1499:
1500: form.action form.state response
1501: ---------------------------------------------------
1502: undefined undefined print main menu
1503: upload undefined print courselist upload menu
1504: upload got_file deal with uploaded file,
1505: print the upload managing menu
1506: upload enrolling enroll students based on upload
1507: drop undefined print the classlist ready to drop
1508: drop done drop the selected students
1509: enrollstudent undefined print single student enroll menu
1510: enrollstudent enrolling enroll student
1511: classlist undefined print html classlist
1512: classlist csv print csv classlist
1513: modifystudent undefined print classlist to select student to modify
1514: modifystudent selected print modify student menu
1515: modifystudent done make modifications to student record
1516:
1517: =cut
1518:
1519: ###################################################################
1520: ###################################################################
1.10 www 1521: sub handler {
1.26 matthew 1522: my $r=shift;
1523: if ($r->header_only) {
1524: $r->content_type('text/html');
1525: $r->send_http_header;
1526: return OK;
1527: }
1.48 matthew 1528: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.50 matthew 1529: ['action','state']);
1.26 matthew 1530: # Needs to be in a course
1.50 matthew 1531: if (! (($ENV{'request.course.fn'}) &&
1532: (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
1533: # Not in a course, or not allowed to modify parms
1534: $ENV{'user.error.msg'}=
1535: "/adm/dropadd:cst:0:0:Cannot drop or add students";
1536: return HTTP_NOT_ACCEPTABLE;
1537: }
1538: #
1539: # Only output the header information if they did not request csv format
1540: #
1541: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1542: $r->content_type('text/csv');
1543: } else {
1.26 matthew 1544: # Start page
1.50 matthew 1545: $r->content_type('text/html');
1.26 matthew 1546: $r->send_http_header;
1.50 matthew 1547: $r->print(&header());
1548: }
1549: #
1550: # Main switch on form.action and form.state, as appropriate
1551: if (! exists($ENV{'form.action'})) {
1552: &print_main_menu($r);
1553: } elsif ($ENV{'form.action'} eq 'upload') {
1554: if (! exists($ENV{'form.state'})) {
1555: &print_first_courselist_upload_form($r);
1556: } elsif ($ENV{'form.state'} eq 'got_file') {
1557: &print_upload_manager_form($r);
1558: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 1559: if ($ENV{'form.datatoken'}) {
1560: &upfile_drop_add($r);
1.50 matthew 1561: } else {
1562: # Hmmm, this is an error
1.26 matthew 1563: }
1.50 matthew 1564: } else {
1565: &print_first_courselist_upload_form($r);
1.26 matthew 1566: }
1.50 matthew 1567: } elsif ($ENV{'form.action'} eq 'drop') {
1568: if (! exists($ENV{'form.state'})) {
1.51 matthew 1569: &print_drop_menu($r);
1.50 matthew 1570: } elsif ($ENV{'form.state'} eq 'done') {
1.26 matthew 1571: &drop_student_list($r);
1.50 matthew 1572: } else {
1.55 matthew 1573: &print_drop_menu($r);
1.26 matthew 1574: }
1.50 matthew 1575: } elsif ($ENV{'form.action'} eq 'enrollstudent') {
1576: if (! exists($ENV{'form.state'})) {
1577: &print_enroll_single_student_form($r);
1578: } elsif ($ENV{'form.state'} eq 'enrolling') {
1.26 matthew 1579: &enroll_single_student($r);
1.50 matthew 1580: } else {
1581: &print_enroll_single_student_form($r);
1.26 matthew 1582: }
1.50 matthew 1583: } elsif ($ENV{'form.action'} eq 'classlist') {
1584: if (! exists($ENV{'form.state'})) {
1585: &print_html_classlist($r);
1586: } elsif ($ENV{'form.state'} eq 'csv') {
1587: &print_csv_classlist($r);
1588: } else {
1589: &print_html_classlist($r);
1590: }
1591: } elsif ($ENV{'form.action'} eq 'modifystudent') {
1592: if (! exists($ENV{'form.state'})) {
1593: &print_html_classlist($r);
1594: } elsif ($ENV{'form.state'} eq 'selected') {
1595: &print_modify_student_form($r);
1596: } elsif ($ENV{'form.state'} eq 'done') {
1597: &modify_single_student($r);
1598: } else {
1599: &print_html_classlist($r);
1600: }
1601: } else {
1602: # We should not end up here, but I guess it is possible
1603: &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ".
1604: "form.action = ".$ENV{'form.action'}.
1605: "Someone should fix this.");
1606: &print_main_menu($r);
1607: }
1608: #
1609: # Finish up
1610: if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) {
1611: $r->print("\n");
1.26 matthew 1612: } else {
1.50 matthew 1613: $r->print('</form></body></html>');
1.26 matthew 1614: }
1615: return OK;
1.1 www 1616: }
1617:
1.50 matthew 1618: ###################################################################
1619: ###################################################################
1620:
1.1 www 1621: 1;
1622: __END__
1.50 matthew 1623:
1.1 www 1624:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>