File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.8:
download - view:
text,
annotated -
select for diffs
Wed Dec 5 16:49:55 2007 UTC (16 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Move routines from loncreateuser.pm to lonuserutils.pm
- &classlist_drop()
- &active_student_roles()
- &course_sections()
Moved determination of a list of groups for incorportion in a javascript Array() to &&get_groupslist() routine in lonuserutils.pm
&setsections_javascript() routine created in lonuersutils.pm - provides javascript function that aggregates and verifies section selections when adding a new role.
Modified in readiness to support section changing for multiple users/roles in a course. Corresponding javascript function eliminated from loncreateuser.
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.8 2007/12/05 16:49:55 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon;
37: use Apache::lonlocal;
38: use Apache::longroup;
39: use LONCAPA qw(:DEFAULT :match);
40:
41: ###############################################################
42: ###############################################################
43: # Drop student from all sections of a course, except optional $csec
44: sub modifystudent {
45: my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
46: # if $csec is undefined, drop the student from all the courses matching
47: # this one. If $csec is defined, drop them from all other sections of
48: # this course and add them to section $csec
49: my $cdom = $env{'course.'.$courseid.'.domain'};
50: my $cnum = $env{'course.'.$courseid.'.num'};
51: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
52: my ($tmp) = keys(%roles);
53: # Bail out if we were unable to get the students roles
54: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
55: # Go through the roles looking for enrollment in this course
56: my $result = '';
57: foreach my $course (keys(%roles)) {
58: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
59: # We are in this course
60: my $section=$1;
61: $section='' if ($course eq "/$cdom/$cnum".'_st');
62: if (defined($csec) && $section eq $csec) {
63: $result .= 'ok:';
64: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
65: my (undef,$end,$start)=split(/\_/,$roles{$course});
66: my $now=time;
67: # if this is an active role
68: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
69: my $reply=&Apache::lonnet::modifystudent
70: # dom name id mode pass f m l g
71: ($udom,$unam,'', '', '',undef,undef,undef,undef,
72: $section,time,undef,undef,$desiredhost);
73: $result .= $reply.':';
74: }
75: }
76: }
77: }
78: if ($result eq '') {
79: $result = 'Unable to find section for this student';
80: } else {
81: $result =~ s/(ok:)+/ok/g;
82: }
83: return $result;
84: }
85:
86: sub modifyuserrole {
87: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
88: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
89: $end,$start,$checkid) = @_;
90: my ($scope,$userresult,$authresult,$roleresult,$idresult);
91: if ($setting eq 'course' || $context eq 'course') {
92: $scope = '/'.$cid;
93: $scope =~ s/\_/\//g;
94: if ($role ne 'cc' && $sec ne '') {
95: $scope .='/'.$sec;
96: }
97: } elsif ($context eq 'domain') {
98: $scope = '/'.$env{'request.role.domain'}.'/';
99: } elsif ($context eq 'construction_space') {
100: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
101: }
102: if ($context eq 'domain') {
103: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
104: if ($uhome ne 'no_host') {
105: if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
106: if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
107: ($umode eq 'localauth')) {
108: $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
109: }
110: }
111: if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
112: ($env{'form.recurseid'}) && ($checkid)) {
113: my %userupdate = (
114: lastname => $last,
115: middlename => $middle,
116: firstname => $first,
117: generation => $gene,
118: id => $uid,
119: );
120: $idresult = &propagate_id_change($uname,$udom,\%userupdate);
121: }
122: }
123: }
124: $userresult =
125: &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
126: $middle,$last,$gene,$forceid,$desiredhome,
127: $email,$role,$start,$end);
128: if ($userresult eq 'ok') {
129: if ($role ne '') {
130: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
131: $role,$end,$start);
132: }
133: }
134: return ($userresult,$authresult,$roleresult,$idresult);
135: }
136:
137: sub propagate_id_change {
138: my ($uname,$udom,$user) = @_;
139: my (@types,@roles,@cdoms);
140: @types = ('active','future');
141: @roles = ('st');
142: my $idresult;
143: my %roleshash = &Apache::lonnet::get_my_roles($uname,
144: $udom,'userroles',\@types,\@roles,\@cdoms);
145: foreach my $item (keys(%roleshash)) {
146: my ($cnum,$cdom,$role) = split(/:/,$item);
147: my ($start,$end) = split(/:/,$roleshash{$item});
148: if (&Apache::lonnet::is_course($cdom,$cnum)) {
149: my %userupdate;
150: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%userupdate);
151: if ($result eq 'ok') {
152: $idresult .= "Classlist change: $uname:$udom - class -> $cnum:$cdom\n";
153: } else {
154: $idresult .= "Error - $result -during classlist update for $uname:$udom in $cnum:$cdom\n";
155: }
156: }
157: }
158: return $idresult;
159: }
160:
161: sub update_classlist {
162: my ($cdom,$cnum,$udom,$uname,$user) = @_;
163: my ($uid,$classlistentry);
164: my $fullname =
165: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
166: $user->{'lastname'},$user->{'generation'},
167: 'lastname');
168: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
169: $cdom,$cnum);
170: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
171: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
172: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
173: for (my $i=0; $i<@classinfo; $i++) {
174: if ($i == $ididx) {
175: if (defined($user->{'id'})) {
176: $classlistentry .= $user->{'id'}.':';
177: } else {
178: $classlistentry .= $classinfo[$i].':';
179: }
180: } elsif ($i == $nameidx) {
181: $classlistentry .= $fullname.':';
182: } else {
183: $classlistentry .= $classinfo[$i].':';
184: }
185: }
186: $classlistentry =~ s/:$//;
187: my $reply=&Apache::lonnet::cput('classlist',
188: {"$uname:$udom" => $classlistentry},
189: $cdom,$cnum);
190: if (($reply eq 'ok') || ($reply eq 'delayed')) {
191: return 'ok';
192: } else {
193: return 'error: '.$reply;
194: }
195: }
196:
197:
198: ###############################################################
199: ###############################################################
200: # build a role type and role selection form
201: sub domain_roles_select {
202: # Set up the role type and role selection boxes when in
203: # domain context
204: #
205: # Role types
206: my @roletypes = ('domain','construction_space','course');
207: my %lt = &role_type_names();
208: #
209: # build up the menu information to be passed to
210: # &Apache::loncommon::linked_select_forms
211: my %select_menus;
212: if ($env{'form.roletype'} eq '') {
213: $env{'form.roletype'} = 'domain';
214: }
215: foreach my $roletype (@roletypes) {
216: # set up the text for this domain
217: $select_menus{$roletype}->{'text'}= $lt{$roletype};
218: # we want a choice of 'default' as the default in the second menu
219: if ($env{'form.roletype'} ne '') {
220: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
221: } else {
222: $select_menus{$roletype}->{'default'} = 'Any';
223: }
224: # Now build up the other items in the second menu
225: my @roles;
226: if ($roletype eq 'domain') {
227: @roles = &domain_roles();
228: } elsif ($roletype eq 'construction_space') {
229: @roles = &construction_space_roles();
230: } else {
231: @roles = &course_roles('domain');
232: unshift(@roles,'cr');
233: }
234: my $order = ['Any',@roles];
235: $select_menus{$roletype}->{'order'} = $order;
236: foreach my $role (@roles) {
237: if ($role eq 'cr') {
238: $select_menus{$roletype}->{'select2'}->{$role} =
239: &mt('Custom role');
240: } else {
241: $select_menus{$roletype}->{'select2'}->{$role} =
242: &Apache::lonnet::plaintext($role);
243: }
244: }
245: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
246: }
247: my $result = &Apache::loncommon::linked_select_forms
248: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
249: 'roletype','showrole',\%select_menus,['domain','construction_space','course']);
250: return $result;
251: }
252:
253: ###############################################################
254: ###############################################################
255: sub hidden_input {
256: my ($name,$value) = @_;
257: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
258: }
259:
260: sub print_upload_manager_header {
261: my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
262: my $javascript;
263: #
264: if (! exists($env{'form.upfile_associate'})) {
265: $env{'form.upfile_associate'} = 'forward';
266: }
267: if ($env{'form.associate'} eq 'Reverse Association') {
268: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
269: $env{'form.upfile_associate'} = 'reverse';
270: } else {
271: $env{'form.upfile_associate'} = 'forward';
272: }
273: }
274: if ($env{'form.upfile_associate'} eq 'reverse') {
275: $javascript=&upload_manager_javascript_reverse_associate();
276: } else {
277: $javascript=&upload_manager_javascript_forward_associate();
278: }
279: #
280: # Deal with restored settings
281: my $password_choice = '';
282: if (exists($env{'form.ipwd_choice'}) &&
283: $env{'form.ipwd_choice'} ne '') {
284: # If a column was specified for password, assume it is for an
285: # internal password. This is a bug waiting to be filed (could be
286: # local or krb auth instead of internal) but I do not have the
287: # time to mess around with this now.
288: $password_choice = 'int';
289: }
290: #
291: my $javascript_validations =
292: &javascript_validations('auth',$krbdefdom,$password_choice,undef,
293: $env{'request.role.domain'});
294: my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
295: $r->print(&mt('Total number of records found in file: <b>[_1]</b>.',$distotal).
296: "<br />\n");
297: $r->print('<div class="LC_left_float"><h3>'.
298: &mt('Identify fields in uploaded list')."</h3>\n");
299: $r->print(&mt('Enter as many fields as you can.<br /> The system will inform you and bring you back to this page, <br /> if the data selected are insufficient to add users.')."<br />\n");
300: $r->print(&hidden_input('action','upload').
301: &hidden_input('state','got_file').
302: &hidden_input('associate','').
303: &hidden_input('datatoken',$datatoken).
304: &hidden_input('fileupload',$env{'form.fileupload'}).
305: &hidden_input('upfiletype',$env{'form.upfiletype'}).
306: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
307: $r->print('<br /><input type="button" value="Reverse Association" '.
308: 'name="'.&mt('Reverse Association').'" '.
309: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
310: $r->print('<label><input type="checkbox" name="noFirstLine"'.$checked.'/>'.
311: &mt('Ignore First Line').'</label>');
312: $r->print("<br /><br />\n".
313: '<script type="text/javascript" language="Javascript">'."\n".
314: $javascript."\n".$javascript_validations.'</script>');
315: }
316:
317: ###############################################################
318: ###############################################################
319: sub javascript_validations {
320: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_;
321: my $authheader;
322: if ($mode eq 'auth') {
323: my %param = ( formname => 'studentform',
324: kerb_def_dom => $krbdefdom,
325: curr_authtype => $curr_authtype);
326: $authheader = &Apache::loncommon::authform_header(%param);
327: } elsif ($mode eq 'createcourse') {
328: my %param = ( formname => 'ccrs',
329: kerb_def_dom => $krbdefdom,
330: curr_authtype => $curr_authtype );
331: $authheader = &Apache::loncommon::authform_header(%param);
332: } elsif ($mode eq 'modifycourse') {
333: my %param = ( formname => 'cmod',
334: kerb_def_dom => $krbdefdom,
335: mode => 'modifycourse',
336: curr_authtype => $curr_authtype,
337: curr_autharg => $curr_authfield );
338: $authheader = &Apache::loncommon::authform_header(%param);
339: }
340:
341: my %alert = &Apache::lonlocal::texthash
342: (username => 'You need to specify the username field.',
343: authen => 'You must choose an authentication type.',
344: krb => 'You need to specify the Kerberos domain.',
345: ipass => 'You need to specify the initial password.',
346: name => 'The optional name field was not specified.',
347: snum => 'The optional ID number field was not specified.',
348: section => 'The optional section field was not specified.',
349: email => 'The optional email address field was not specified.',
350: role => 'The optional role field was not specified.',
351: continue => 'Continue adding users?',
352: );
353:
354: # my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
355: my $function_name =(<<END);
356: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
357: END
358: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
359: my $auth_checks;
360: if ($mode eq 'createcourse') {
361: $auth_checks .= (<<END);
362: if (vf.autoadds[0].checked == true) {
363: if (current.radiovalue == null || current.radiovalue == 'nochange') {
364: alert('$alert{'authen'}');
365: return;
366: }
367: }
368: END
369: } else {
370: $auth_checks .= (<<END);
371: var foundatype=0;
372: if (founduname==0) {
373: alert('$alert{'username'}');
374: return;
375: }
376:
377: END
378: if ($authnum > 1) {
379: $auth_checks .= (<<END);
380: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
381: // They did not check any of the login radiobuttons.
382: alert('$alert{'authen'}');
383: return;
384: }
385: END
386: }
387: }
388: if ($mode eq 'createcourse') {
389: $auth_checks .= "
390: if ( (vf.autoadds[0].checked == true) &&
391: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
392: ";
393: } elsif ($mode eq 'modifycourse') {
394: $auth_checks .= "
395: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
396: ";
397: }
398: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
399: $auth_checks .= (<<END);
400: var alertmsg = '';
401: switch (current.radiovalue) {
402: case 'krb':
403: alertmsg = '$alert{'krb'}';
404: break;
405: default:
406: alertmsg = '';
407: }
408: if (alertmsg != '') {
409: alert(alertmsg);
410: return;
411: }
412: }
413: END
414: } else {
415: $auth_checks .= (<<END);
416: foundatype=1;
417: if (current.argfield == null || current.argfield == '') {
418: var alertmsg = '';
419: switch (current.value) {
420: case 'krb':
421: alertmsg = '$alert{'krb'}';
422: break;
423: case 'loc':
424: case 'fsys':
425: alertmsg = '$alert{'ipass'}';
426: break;
427: case 'fsys':
428: alertmsg = '';
429: break;
430: default:
431: alertmsg = '';
432: }
433: if (alertmsg != '') {
434: alert(alertmsg);
435: return;
436: }
437: }
438: END
439: }
440: my $section_checks;
441: my $optional_checks = '';
442: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
443: $optional_checks = (<<END);
444: vf.submit();
445: }
446: END
447: } else {
448: $section_checks = §ion_check_js();
449: $optional_checks = (<<END);
450: var message='';
451: if (foundname==0) {
452: message='$alert{'name'}';
453: }
454: if (foundid==0) {
455: if (message!='') {
456: message+='\\n';
457: }
458: message+='$alert{'snum'}';
459: }
460: if (foundsec==0) {
461: if (message!='') {
462: message+='\\n';
463: }
464: }
465: if (foundemail==0) {
466: if (message!='') {
467: message+='\\n';
468: }
469: message+='$alert{'email'}';
470: }
471: if (message!='') {
472: message+= '\\n$alert{'continue'}';
473: if (confirm(message)) {
474: vf.state.value='enrolling';
475: vf.submit();
476: }
477: } else {
478: vf.state.value='enrolling';
479: vf.submit();
480: }
481: }
482: END
483: }
484: my $result = $function_name;
485: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
486: $result .= $auth_checks;
487: }
488: $result .= $optional_checks."\n".$section_checks;
489: if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
490: $result .= $authheader;
491: }
492: return $result;
493: }
494: ###############################################################
495: ###############################################################
496: sub upload_manager_javascript_forward_associate {
497: return(<<ENDPICK);
498: function verify(vf,sec_caller) {
499: var founduname=0;
500: var foundpwd=0;
501: var foundname=0;
502: var foundid=0;
503: var foundsec=0;
504: var foundemail=0;
505: var foundrole=0;
506: var tw;
507: for (i=0;i<=vf.nfields.value;i++) {
508: tw=eval('vf.f'+i+'.selectedIndex');
509: if (tw==1) { founduname=1; }
510: if ((tw>=2) && (tw<=6)) { foundname=1; }
511: if (tw==7) { foundid=1; }
512: if (tw==8) { foundsec=1; }
513: if (tw==9) { foundpwd=1; }
514: if (tw==10) { foundemail=1; }
515: if (tw==11) { foundrole=1; }
516: }
517: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole);
518: }
519:
520: //
521: // vf = this.form
522: // tf = column number
523: //
524: // values of nw
525: //
526: // 0 = none
527: // 1 = username
528: // 2 = names (lastname, firstnames)
529: // 3 = fname (firstname)
530: // 4 = mname (middlename)
531: // 5 = lname (lastname)
532: // 6 = gen (generation)
533: // 7 = id
534: // 8 = section
535: // 9 = ipwd (password)
536: // 10 = email address
537: // 11 = role
538:
539: function flip(vf,tf) {
540: var nw=eval('vf.f'+tf+'.selectedIndex');
541: var i;
542: // make sure no other columns are labeled the same as this one
543: for (i=0;i<=vf.nfields.value;i++) {
544: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
545: eval('vf.f'+i+'.selectedIndex=0;')
546: }
547: }
548: // If we set this to 'lastname, firstnames', clear out all the ones
549: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
550: if (nw==2) {
551: for (i=0;i<=vf.nfields.value;i++) {
552: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
553: (eval('vf.f'+i+'.selectedIndex')<=6)) {
554: eval('vf.f'+i+'.selectedIndex=0;')
555: }
556: }
557: }
558: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
559: // clear out any that are set to 'lastname, firstnames' (2)
560: if ((nw>=3) && (nw<=6)) {
561: for (i=0;i<=vf.nfields.value;i++) {
562: if (eval('vf.f'+i+'.selectedIndex')==2) {
563: eval('vf.f'+i+'.selectedIndex=0;')
564: }
565: }
566: }
567: // If we set the password, make the password form below correspond to
568: // the new value.
569: if (nw==9) {
570: changed_radio('int',document.studentform);
571: set_auth_radio_buttons('int',document.studentform);
572: vf.intarg.value='';
573: vf.krbarg.value='';
574: vf.locarg.value='';
575: }
576: }
577:
578: function clearpwd(vf) {
579: var i;
580: for (i=0;i<=vf.nfields.value;i++) {
581: if (eval('vf.f'+i+'.selectedIndex')==9) {
582: eval('vf.f'+i+'.selectedIndex=0;')
583: }
584: }
585: }
586:
587: ENDPICK
588: }
589:
590: ###############################################################
591: ###############################################################
592: sub upload_manager_javascript_reverse_associate {
593: return(<<ENDPICK);
594: function verify(vf,sec_caller) {
595: var founduname=0;
596: var foundpwd=0;
597: var foundname=0;
598: var foundid=0;
599: var foundsec=0;
600: var foundrole=0;
601: var tw;
602: for (i=0;i<=vf.nfields.value;i++) {
603: tw=eval('vf.f'+i+'.selectedIndex');
604: if (i==0 && tw!=0) { founduname=1; }
605: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
606: if (i==6 && tw!=0) { foundid=1; }
607: if (i==7 && tw!=0) { foundsec=1; }
608: if (i==8 && tw!=0) { foundpwd=1; }
609: if (i==9 && tw!=0) { foundrole=1; }
610: }
611: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole);
612: }
613:
614: function flip(vf,tf) {
615: var nw=eval('vf.f'+tf+'.selectedIndex');
616: var i;
617: // picked the all one name field, reset the other name ones to blank
618: if (tf==1 && nw!=0) {
619: for (i=2;i<=5;i++) {
620: eval('vf.f'+i+'.selectedIndex=0;')
621: }
622: }
623: //picked one of the piecewise name fields, reset the all in
624: //one field to blank
625: if ((tf>=2) && (tf<=5) && (nw!=0)) {
626: eval('vf.f1.selectedIndex=0;')
627: }
628: // intial password specified, pick internal authentication
629: if (tf==8 && nw!=0) {
630: changed_radio('int',document.studentform);
631: set_auth_radio_buttons('int',document.studentform);
632: vf.krbarg.value='';
633: vf.intarg.value='';
634: vf.locarg.value='';
635: }
636: }
637:
638: function clearpwd(vf) {
639: var i;
640: if (eval('vf.f8.selectedIndex')!=0) {
641: eval('vf.f8.selectedIndex=0;')
642: }
643: }
644: ENDPICK
645: }
646:
647: ###############################################################
648: ###############################################################
649: sub print_upload_manager_footer {
650: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context)=@_;
651: my $formname;
652: if ($context eq 'course') {
653: $formname = 'document.studentform';
654: } elsif ($context eq 'construction_space') {
655: $formname = 'document.studentform';
656: } elsif ($context eq 'domain') {
657: $formname = 'document.studentform';
658: }
659: my ($krbdef,$krbdefdom) =
660: &Apache::loncommon::get_kerberos_defaults($defdom);
661: my %param = ( formname => $formname,
662: kerb_def_dom => $krbdefdom,
663: kerb_def_auth => $krbdef
664: );
665: if (exists($env{'form.ipwd_choice'}) &&
666: defined($env{'form.ipwd_choice'}) &&
667: $env{'form.ipwd_choice'} ne '') {
668: $param{'curr_authtype'} = 'int';
669: }
670: my $krbform = &Apache::loncommon::authform_kerberos(%param);
671: my $intform = &Apache::loncommon::authform_internal(%param);
672: my $locform = &Apache::loncommon::authform_local(%param);
673: my $date_table = &date_setting_table(undef,undef,$context);
674:
675: my $Str = "\n".'<div class="LC_left_float">';
676: $Str .= &hidden_input('nfields',$i);
677: $Str .= &hidden_input('keyfields',$keyfields);
678: $Str .= "<h3>".&mt('Login Type')."</h3>\n";
679: if ($context eq 'domain') {
680: $Str .= '<p>'.&mt('Change authentication for existing users to these settings?').' <span class="LC_nobreak"><label><input type="radio" name="changeauth" value="No" checked="checked" />'.&mt('No').'</label> <label><input type="radio" name="changeauth" value="Yes" />'.&mt('Yes').'</label></span></p>';
681: } else {
682: $Str .= "<p>\n".
683: &mt('Note: this will not take effect if the user already exists').
684: &Apache::loncommon::help_open_topic('Auth_Options').
685: "</p>\n";
686: }
687: $Str .= &set_login($defdom,$krbform,$intform,$locform);
688: my ($home_server_pick,$numlib) =
689: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
690: 'default','hide');
691: if ($numlib > 1) {
692: $Str .= '<h3>'.&mt('LON-CAPA Home Server for New Users')."</h3>\n".
693: &mt('LON-CAPA domain: [_1] with home server: [_2]',$defdom,
694: $home_server_pick).'<br />';
695: } else {
696: $Str .= $home_server_pick;
697: }
698: $Str .= '<h3>'.&mt('Starting and Ending Dates').
699: "</h3>\n";
700: $Str .= "<p>\n".$date_table."</p>\n";
701: if ($context eq 'domain') {
702: $Str .= '<h3>'.&mt('Settings for assigning roles:').'</h3>'."\n".
703: &mt('Pick the action to take on roles for these users:').'<br /><span class="LC_nobreak"><label><input type="radio" name="roleaction" value="norole" checked="checked" /> '.&mt('No role changes').'</label> <label><input type="radio" name="roleaction" value="domain" /> '.&mt('Add a domain role').'</label> <label><input type="radio" name="roleaction" value="course" /> '.&mt('Add a course role').'</label></span>';
704: }
705: if ($context eq 'construction_space') {
706: $Str .= '<h3>'.&mt('Default role')."</h3>\n".
707: &mt('Choose the role to assign to users without one specified in the uploaded file');
708: } elsif ($context eq 'course') {
709: $Str .= '<h3>'.&mt('Default role and section')."</h3>\n".
710: &mt('Choose the role and/or section to assign to users without one specified in the uploaded file');
711: } else {
712: $Str .= '<br /><br /><b>'.&mt('Default role and/or section')."</b><br />\n".
713: &mt('Role and/or section for users without one in the uploaded file.');
714: }
715: $Str .= '<br /><br />';
716: my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
717: if ($context eq 'domain') {
718: $Str .= '<span class="LC_role_level">'.&mt('Domain Level').'</span><br />'.$options.'<br /><br /><span class="LC_role_level">'.&mt('Course Level').'</span><br />'.$cb_script.$coursepick;
719: } elsif ($context eq 'construction_space') {
720: $Str .= $options;
721: } else {
722: $Str .= '<table><tr><td><span class="LC_nobreak"<b>'.&mt('role').': </b>'.
723: $options.'</span></td><td> </td><td><span class="LC_nobreak">'.
724: '<b>'.&mt('section').': </b><input type="text" name="section" value="" size="12" /></span></td></tr></table>';
725: }
726: if ($context eq 'course') {
727: $Str .= "<h3>".&mt('Full Update')."</h3>\n".
728: '<label><input type="checkbox" name="fullup" value="yes">'.
729: ' '.&mt('Full update (also print list of users not enrolled anymore)').
730: "</label></p>\n";
731: }
732: if ($context eq 'course' || $context eq 'domain') {
733: $Str .= &forceid_change($context);
734: }
735: $Str .= '</div><div class="LC_clear_float_footer"><br /><input type="button"'.
736: 'onClick="javascript:verify(this.form,this.form.csec)" '.
737: 'value="Update Users" />'."<br />\n";
738: if ($context eq 'course') {
739: $Str .= &mt('Note: for large courses, this operation may be time '.
740: 'consuming');
741: }
742: $Str .= '</div>';
743: $r->print($Str);
744: return;
745: }
746:
747: sub forceid_change {
748: my ($context) = @_;
749: my $output =
750: "<h3>".&mt('ID/Student Number')."</h3>\n".
751: "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">'.
752: &mt('Disable ID/Student Number Safeguard and Force Change '.
753: 'of Conflicting IDs').'</label><br />'."\n".
754: &mt('(only do if you know what you are doing.)')."</br><br />\n";
755: if ($context eq 'domain') {
756: $output .= '<label><input type="checkbox" name="recurseid"'.
757: ' value="yes">'.
758: &mt('Update ID/Student Number in courses in which user is an Active or Future student, (if forcing change).').
759: '</label></p>'."\n";
760: }
761: return $output;
762: }
763:
764: ###############################################################
765: ###############################################################
766: sub print_upload_manager_form {
767: my ($r,$context) = @_;
768: my $firstLine;
769: my $datatoken;
770: if (!$env{'form.datatoken'}) {
771: $datatoken=&Apache::loncommon::upfile_store($r);
772: } else {
773: $datatoken=$env{'form.datatoken'};
774: &Apache::loncommon::load_tmp_file($r);
775: }
776: my @records=&Apache::loncommon::upfile_record_sep();
777: if($env{'form.noFirstLine'}){
778: $firstLine=shift(@records);
779: }
780: my $total=$#records;
781: my $distotal=$total+1;
782: my $today=time;
783: my $halfyear=$today+15552000;
784: #
785: # Restore memorized settings
786: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
787: 'names_choice' => 'scalar',
788: 'fname_choice' => 'scalar',
789: 'mname_choice' => 'scalar',
790: 'lname_choice' => 'scalar',
791: 'gen_choice' => 'scalar',
792: 'id_choice' => 'scalar',
793: 'sec_choice' => 'scalar',
794: 'ipwd_choice' => 'scalar',
795: 'email_choice' => 'scalar',
796: 'role_choice' => 'scalar',
797: };
798: my $defdom = $env{'request.role.domain'};
799: if ($context eq 'course') {
800: &Apache::loncommon::restore_course_settings('enrollment_upload',
801: $col_setting_names);
802: } else {
803: &Apache::loncommon::restore_settings($context,'user_upload',
804: $col_setting_names);
805: }
806: #
807: # Determine kerberos parameters as appropriate
808: my ($krbdef,$krbdefdom) =
809: &Apache::loncommon::get_kerberos_defaults($defdom);
810: #
811: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context);
812: my $i;
813: my $keyfields;
814: if ($total>=0) {
815: my @field=
816: (['username',&mt('Username'), $env{'form.username_choice'}],
817: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
818: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
819: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
820: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
821: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
822: ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
823: ['sec', &mt('Section'), $env{'form.sec_choice'}],
824: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
825: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
826: ['role',&mt('Role'), $env{'form.role_choice'}]);
827: if ($env{'form.upfile_associate'} eq 'reverse') {
828: &Apache::loncommon::csv_print_samples($r,\@records);
829: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
830: \@field);
831: foreach (@field) {
832: $keyfields.=$_->[0].',';
833: }
834: chop($keyfields);
835: } else {
836: unshift(@field,['none','']);
837: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
838: \@field);
839: my %sone=&Apache::loncommon::record_sep($records[0]);
840: $keyfields=join(',',sort(keys(%sone)));
841: }
842: }
843: $r->print('</div>');
844: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
845: $context);
846: }
847:
848: sub setup_date_selectors {
849: my ($starttime,$endtime,$mode) = @_;
850: if (! defined($starttime)) {
851: $starttime = time;
852: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
853: if (exists($env{'course.'.$env{'request.course.id'}.
854: '.default_enrollment_start_date'})) {
855: $starttime = $env{'course.'.$env{'request.course.id'}.
856: '.default_enrollment_start_date'};
857: }
858: }
859: }
860: if (! defined($endtime)) {
861: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
862: unless ($mode eq 'createcourse') {
863: if (exists($env{'course.'.$env{'request.course.id'}.
864: '.default_enrollment_end_date'})) {
865: $endtime = $env{'course.'.$env{'request.course.id'}.
866: '.default_enrollment_end_date'};
867: }
868: }
869: }
870: my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
871: 'startdate',
872: $starttime);
873: my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
874: 'enddate',
875: $endtime);
876: if ($mode eq 'create_enrolldates') {
877: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
878: 'startenroll',
879: $starttime);
880: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
881: 'endenroll',
882: $endtime);
883: }
884: if ($mode eq 'create_defaultdates') {
885: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
886: 'startaccess',
887: $starttime);
888: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
889: 'endaccess',
890: $endtime);
891: }
892: return ($startdateform,$enddateform);
893: }
894:
895:
896: sub get_dates_from_form {
897: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
898: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
899: if ($env{'form.no_end_date'}) {
900: $enddate = 0;
901: }
902: return ($startdate,$enddate);
903: }
904:
905: sub date_setting_table {
906: my ($starttime,$endtime,$mode) = @_;
907: my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
908: my $dateDefault;
909: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
910: $dateDefault = ' ';
911: } elsif ($mode ne 'construction_space' && $mode ne 'domain') {
912: $dateDefault = '<nobr>'.
913: '<label><input type="checkbox" name="makedatesdefault" /> '.
914: &mt('make these dates the default for future enrollment').
915: '</label></nobr>';
916: }
917: my $perpetual = '<nobr><label><input type="checkbox" name="no_end_date"';
918: if (defined($endtime) && $endtime == 0) {
919: $perpetual .= ' checked';
920: }
921: $perpetual.= ' /> '.&mt('no ending date').'</label></nobr>';
922: if ($mode eq 'create_enrolldates') {
923: $perpetual = ' ';
924: }
925: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n".
926: &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
927: 'LC_oddrow_value')."\n".
928: $startform."\n".
929: &Apache::lonhtmlcommon::row_closure(1).
930: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
931: 'LC_oddrow_value')."\n".
932: $endform.' '.$perpetual.
933: &Apache::lonhtmlcommon::row_closure(1).
934: &Apache::lonhtmlcommon::end_pick_box().'<br />';
935: if ($dateDefault) {
936: $result .= $dateDefault.'<br />'."\n";
937: }
938: return $result;
939: }
940:
941: sub make_dates_default {
942: my ($startdate,$enddate,$context) = @_;
943: my $result = '';
944: if ($context eq 'course') {
945: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
946: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
947: my $put_result = &Apache::lonnet::put('environment',
948: {'default_enrollment_start_date'=>$startdate,
949: 'default_enrollment_end_date' =>$enddate},$dom,$crs);
950: if ($put_result eq 'ok') {
951: $result .= "Set default start and end dates for course<br />";
952: #
953: # Refresh the course environment
954: &Apache::lonnet::coursedescription($env{'request.course.id'},
955: {'freshen_cache' => 1});
956: } else {
957: $result .= &mt('Unable to set default dates for course').":".$put_result.
958: '<br />';
959: }
960: }
961: return $result;
962: }
963:
964: sub default_role_selector {
965: my ($context,$checkpriv) = @_;
966: my %customroles;
967: my ($options,$coursepick,$cb_jscript);
968: if ($context ne 'construction_space') {
969: %customroles = &my_custom_roles();
970: }
971:
972: my %lt=&Apache::lonlocal::texthash(
973: 'rol' => "Role",
974: 'grs' => "Section",
975: 'exs' => "Existing sections",
976: 'new' => "New section",
977: );
978: $options = '<select name="defaultrole">'."\n".
979: ' <option value="">'.&mt('Please select').'</option>'."\n";
980: if ($context eq 'course') {
981: $options .= &default_course_roles($context,$checkpriv,%customroles);
982: } elsif ($context eq 'construction_space') {
983: my @roles = &construction_space_roles($checkpriv);
984: foreach my $role (@roles) {
985: my $plrole=&Apache::lonnet::plaintext($role);
986: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
987: }
988: } elsif ($context eq 'domain') {
989: my @roles = &domain_roles($checkpriv);
990: foreach my $role (@roles) {
991: my $plrole=&Apache::lonnet::plaintext($role);
992: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
993: }
994: my $courseform = &Apache::loncommon::selectcourse_link
995: ('studentform','defaultcourse','defaultdomain','defaultdesc',"$env{'request.role.domain'}",undef,'Course');
996: $cb_jscript =
997: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'defaultsec','studentform');
998: $coursepick = &Apache::loncommon::start_data_table().
999: &Apache::loncommon::start_data_table_header_row().
1000: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1001: '<th>'.$lt{'grs'}.'</th>'.
1002: &Apache::loncommon::end_data_table_header_row().
1003: &Apache::loncommon::start_data_table_row()."\n".
1004: '<td><input type="text" name="defaultdesc" value="" onFocus="this.blur();opencrsbrowser('."'studentform','defcourse','defdomain','coursedesc',''".')" /></td>'."\n".
1005: '<td><select name="courserole">'."\n".
1006: &default_course_roles($context,$checkpriv,%customroles)."\n".
1007: '</select></td><td>'.
1008: '<table class="LC_createuser">'.
1009: '<tr class="LC_section_row"><td valign"top">'.
1010: $lt{'exs'}.'<br /><select name="defaultsec">'.
1011: ' <option value=""><--'.&mt('Pick course first').
1012: '</select></td>'.
1013: '<td> </td>'.
1014: '<td valign="top">'.$lt{'new'}.'<br />'.
1015: '<input type="text" name="newsec" value="" size="5" />'.
1016: '<input type="hidden" name="groups" value="" /></td>'.
1017: '</tr></table></td>'.
1018: &Apache::loncommon::end_data_table_row().
1019: &Apache::loncommon::end_data_table()."\n".
1020: '<input type="hidden" name="defaultcourse" value="" />'.
1021: '<input type="hidden" name="defaultdomain" value="" />';
1022: }
1023: $options .= '</select>';
1024: return ($options,$cb_jscript,$coursepick);
1025: }
1026:
1027: sub default_course_roles {
1028: my ($context,$checkpriv,%customroles) = @_;
1029: my $output;
1030: my @roles = &course_roles($context,$checkpriv);
1031: foreach my $role (@roles) {
1032: my $plrole=&Apache::lonnet::plaintext($role);
1033: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1034: }
1035: if (keys(%customroles) > 0) {
1036: my %customroles = &my_custom_roles();
1037: foreach my $cust (sort(keys(%customroles))) {
1038: my $custrole='cr_cr_'.$env{'user.domain'}.
1039: '_'.$env{'user.name'}.'_'.$cust;
1040: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1041: }
1042: }
1043: return $output;
1044: }
1045:
1046: sub construction_space_roles {
1047: my ($checkpriv) = @_;
1048: my @allroles = ('ca','aa');
1049: my @roles;
1050: if ($checkpriv) {
1051: foreach my $role (@allroles) {
1052: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
1053: push(@roles,$role);
1054: }
1055: }
1056: return @roles;
1057: } else {
1058: return @allroles;
1059: }
1060: }
1061:
1062: sub domain_roles {
1063: my ($checkpriv) = @_;
1064: my @allroles = ('dc','li','dg','au','sc');
1065: my @roles;
1066: if ($checkpriv) {
1067: foreach my $role (@allroles) {
1068: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1069: push(@roles,$role);
1070: }
1071: }
1072: return @roles;
1073: } else {
1074: return @allroles;
1075: }
1076: }
1077:
1078: sub course_roles {
1079: my ($context,$checkpriv) = @_;
1080: my @allroles = ('st','ta','ep','in','cc');
1081: my @roles;
1082: if ($context eq 'domain') {
1083: @roles = @allroles;
1084: } elsif ($context eq 'course') {
1085: if ($env{'request.course.id'}) {
1086: if ($checkpriv) {
1087: foreach my $role (@allroles) {
1088: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
1089: push(@roles,$role);
1090: } else {
1091: if ($role ne 'cc' && $env{'request.course.section'} ne '') {
1092: if (!&Apache::lonnet::allowed('c'.$role,
1093: $env{'request.course.id'}.'/'.
1094: $env{'request.course.section'})) {
1095: push(@roles,$role);
1096: }
1097: }
1098: }
1099: }
1100: } else {
1101: @roles = @allroles;
1102: }
1103: }
1104: }
1105: return @roles;
1106: }
1107:
1108: sub curr_role_permissions {
1109: my ($context,$setting,$checkpriv) = @_;
1110: my @roles;
1111: if ($context eq 'construction_space') {
1112: @roles = &construction_space_roles($checkpriv);
1113: } elsif ($context eq 'domain') {
1114: if ($setting eq 'course') {
1115: @roles = &course_roles($context,$checkpriv);
1116: } else {
1117: @roles = &domain_roles($checkpriv);
1118: }
1119: } elsif ($context eq 'course') {
1120: @roles = &course_roles($context,$checkpriv);
1121: }
1122: return @roles;
1123: }
1124:
1125: # ======================================================= Existing Custom Roles
1126:
1127: sub my_custom_roles {
1128: my %returnhash=();
1129: my %rolehash=&Apache::lonnet::dump('roles');
1130: foreach my $key (keys %rolehash) {
1131: if ($key=~/^rolesdef\_(\w+)$/) {
1132: $returnhash{$1}=$1;
1133: }
1134: }
1135: return %returnhash;
1136: }
1137:
1138: sub print_userlist {
1139: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1140: $idlist,$idlist_titles) = @_;
1141: my $format = $env{'form.output'};
1142: if (! exists($env{'form.sortby'})) {
1143: $env{'form.sortby'} = 'username';
1144: }
1145: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1146: $env{'form.Status'} = 'Active';
1147: }
1148: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1149: ($env{'form.Status'});
1150:
1151: if ($env{'form.showrole'} eq '') {
1152: $env{'form.showrole'} = 'Any';
1153: }
1154: if (! defined($env{'form.output'}) ||
1155: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1156: $env{'form.output'} = 'html';
1157: }
1158:
1159: my @statuses;
1160: if ($env{'form.Status'} eq 'Any') {
1161: @statuses = ('previous','active','future');
1162: } elsif ($env{'form.Status'} eq 'Expired') {
1163: @statuses = ('previous');
1164: } elsif ($env{'form.Status'} eq 'Active') {
1165: @statuses = ('active');
1166: } elsif ($env{'form.Status'} eq 'Future') {
1167: @statuses = ('future');
1168: }
1169:
1170: # if ($context eq 'course') {
1171: # $r->print(&display_adv_courseroles());
1172: # }
1173: #
1174: # Interface output
1175: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1176: '<input type="hidden" name="action" value="'.
1177: $env{'form.action'}.'" />');
1178: $r->print("<p>\n");
1179: if ($env{'form.action'} ne 'modifystudent') {
1180: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1181: 'excel' => "Excel",
1182: 'html' => 'HTML');
1183: my $output_selector = '<select size="1" name="output" >';
1184: foreach my $outputformat ('html','csv','excel') {
1185: my $option = '<option value="'.$outputformat.'" ';
1186: if ($outputformat eq $env{'form.output'}) {
1187: $option .= 'selected ';
1188: }
1189: $option .='>'.$lt{$outputformat}.'</option>';
1190: $output_selector .= "\n".$option;
1191: }
1192: $output_selector .= '</select>';
1193: $r->print('<label>'.&mt('Output Format: [_1]',$output_selector).'</label>'.(' 'x3));
1194: }
1195: $r->print('<label>'.&mt('User Status: [_1]',$status_select).'</label>'.(' 'x3)."\n");
1196: my $roleselected = '';
1197: if ($env{'form.showrole'} eq 'Any') {
1198: $roleselected = ' selected="selected" ';
1199: }
1200: my $role_select;
1201: if ($context eq 'domain') {
1202: $role_select = &domain_roles_select();
1203: $r->print('<label>'.&mt('Role Type: [_1]',$role_select).'</label>');
1204: } else {
1205: $role_select = '<select name="showrole">'."\n".
1206: '<option value="Any" '.$roleselected.'>'.
1207: &mt('Any role').'</option>';
1208: my @poss_roles = &curr_role_permissions($context);
1209: foreach my $role (@poss_roles) {
1210: $roleselected = '';
1211: if ($role eq $env{'form.showrole'}) {
1212: $roleselected = ' selected="selected" ';
1213: }
1214: my $plrole=&Apache::lonnet::plaintext($role);
1215: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
1216: }
1217: $roleselected = '';
1218: if ($env{'form.showrole'} eq 'cr') {
1219: $roleselected = ' selected="selected" ';
1220: }
1221: $role_select .= '<option value="cr"'.$roleselected.'>'.&mt('Custom role').'</option>'.
1222: '</select>';
1223: $r->print('<label>'.&mt('Role: [_1]',$role_select).'</label>');
1224: }
1225: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1226: $r->print(&list_submit_button(&mt('Update Display'))."\n</p>\n");
1227: }
1228: my ($indexhash,$keylist) = &make_keylist_array();
1229: my (%userlist,%userinfo);
1230: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1231: my $courseform =
1232: &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
1233: $codetitles,$idlist,$idlist_titles);
1234: $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
1235: &Apache::lonhtmlcommon::start_pick_box()."\n".
1236: &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
1237: 'LC_oddrow_value')."\n".
1238: $courseform."\n".
1239: &Apache::lonhtmlcommon::row_closure(1).
1240: &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1241: '<p>'.&list_submit_button(&mt('Update Display')).
1242: "\n</p>\n");
1243: }
1244: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1245: $r->rflush();
1246: if ($context eq 'course') {
1247: my $classlist = &Apache::loncoursedata::get_classlist();
1248: my $secidx = &Apache::loncoursedata::CL_SECTION();
1249: foreach my $student (keys(%{$classlist})) {
1250: if (exists($permission->{'view_section'})) {
1251: if ($classlist->{$student}[$secidx] ne $permission->{'view_section'}) {
1252: next;
1253: } else {
1254: $userlist{$student} = $classlist->{$student};
1255: }
1256: } else {
1257: $userlist{$student} = $classlist->{$student};
1258: }
1259: }
1260: my $cid =$env{'request.course.id'};
1261: my $cdom=$env{'course.'.$cid.'.domain'};
1262: my $cnum=$env{'course.'.$cid.'.num'};
1263: my $showroles;
1264: if ($env{'form.showrole'} ne 'Any') {
1265: $showroles = [$env{'form.showrole'}];
1266: } else {
1267: $showroles = undef;
1268: }
1269: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1270: \@statuses,$showroles);
1271: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1272: \%advrolehash);
1273: } else {
1274: my (%cstr_roles,%dom_roles);
1275: if ($context eq 'construction_space') {
1276: # List co-authors and assistant co-authors
1277: my @possroles = ('ca','aa');
1278: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1279: \@statuses,\@possroles);
1280: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1281: \%cstr_roles);
1282: } elsif ($context eq 'domain') {
1283: if ($env{'form.roletype'} eq 'domain') {
1284: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1285: foreach my $key (keys(%dom_roles)) {
1286: if (ref($dom_roles{$key}) eq 'HASH') {
1287: &gather_userinfo($context,$format,\%userlist,$indexhash,
1288: \%userinfo,$dom_roles{$key});
1289: }
1290: }
1291: } elsif ($env{'form.roletype'} eq 'construction_space') {
1292: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1293: my %coauthors;
1294: foreach my $key (keys(%dom_roles)) {
1295: if (ref($dom_roles{$key}) eq 'HASH') {
1296: if ($env{'form.showrole'} eq 'au') {
1297: &gather_userinfo($context,$format,\%userlist,$indexhash,
1298: \%userinfo,$dom_roles{$key});
1299: } else {
1300: my @possroles;
1301: if ($env{'form.showrole'} eq 'Any') {
1302: @possroles = ('ca','aa');
1303: } else {
1304: @possroles = ($env{'form.showrole'});
1305: }
1306: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1307: my ($role,$authorname,$authordom) = split(/:/,$author);
1308: my $extent = '/'.$authordom.'/'.$authorname;
1309: %{$coauthors{$extent}} =
1310: &Apache::lonnet::get_my_roles($authorname,
1311: $authordom,undef,\@statuses,\@possroles);
1312: }
1313: &gather_userinfo($context,$format,\%userlist,
1314: $indexhash,\%userinfo,\%coauthors);
1315: }
1316: }
1317: }
1318: } elsif ($env{'form.roletype'} eq 'course') {
1319: if ($env{'form.coursepick'}) {
1320: my %courses = &process_coursepick();
1321: my %allusers;
1322: foreach my $cid (keys(%courses)) {
1323: my %coursehash =
1324: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1325: my $cdom = $coursehash{'domain'};
1326: my $cnum = $coursehash{'num'};
1327: my $cdesc = $coursehash{'description'};
1328: my (@roles,@sections,%access,%users,%userdata,
1329: %statushash);
1330: if ($env{'form.showrole'} eq 'Any') {
1331: @roles = &course_roles($context);
1332: unshift(@roles,'cr');
1333: } else {
1334: @roles = ($env{'form.showrole'});
1335: }
1336: foreach my $role (@roles) {
1337: %{$users{$role}} = ();
1338: }
1339: foreach my $type (@statuses) {
1340: $access{$type} = $type;
1341: }
1342: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash);
1343: foreach my $user (keys(%userdata)) {
1344: next if (ref($userinfo{$user}) eq 'HASH');
1345: foreach my $item ('fullname','id') {
1346: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1347: }
1348: }
1349: foreach my $role (keys(%users)) {
1350: foreach my $user (keys(%{$users{$role}})) {
1351: my $uniqid = $user.':'.$role;
1352: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1353: secs => $statushash{$user}{$role},
1354: };
1355: }
1356: }
1357: }
1358: &gather_userinfo($context,$format,\%userlist,$indexhash,
1359: \%userinfo,\%allusers);
1360: } else {
1361: return;
1362: }
1363: }
1364: }
1365: }
1366: if (keys(%userlist) == 0) {
1367: if ($context eq 'construction_space') {
1368: $r->print(&mt('There are no co-authors to display.')."\n");
1369: } elsif ($context eq 'domain') {
1370: if ($env{'form.roletype'} eq 'domain') {
1371: $r->print(&mt('There are no users with domain roles to display.')."\n");
1372: } elsif ($env{'form.roletype'} eq 'construction_space') {
1373: $r->print(&mt('There are no authors or co-authors to display.')."\n");
1374: } elsif ($env{'form.roletype'} eq 'course') {
1375: $r->print(&mt('There are no course users to display')."\n");
1376: }
1377: } elsif ($context eq 'course') {
1378: $r->print(&mt('There are no course users to display.')."\n");
1379: }
1380: } else {
1381: # Print out the available choices
1382: my $usercount;
1383: if ($env{'form.action'} eq 'modifystudent') {
1384: ($usercount) = &show_users_list($r,$context,'view','modify',
1385: $env{'form.Status'},\%userlist,$keylist);
1386: } else {
1387: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1388: 'aboutme',$env{'form.Status'},\%userlist,$keylist);
1389: }
1390: if (!$usercount) {
1391: $r->print('<br />'.&mt('There are no users matching the search criteria.'));
1392: }
1393: }
1394: $r->print('</form>');
1395: }
1396:
1397: sub list_submit_button {
1398: my ($text) = @_;
1399: return '<input type="submit" value="'.$text.'" />';
1400: }
1401:
1402: sub gather_userinfo {
1403: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash) = @_;
1404: foreach my $item (keys(%{$rolehash})) {
1405: @{$userlist->{$item}} = ();
1406: my %userdata;
1407: if ($context eq 'construction_space' || $context eq 'course') {
1408: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1409: split(/:/,$item);
1410: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1411: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1412: } elsif ($context eq 'domain') {
1413: if ($env{'form.roletype'} eq 'domain') {
1414: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
1415: split(/:/,$item);
1416: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1417: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1418: } elsif ($env{'form.roletype'} eq 'construction_space') {
1419: if (ref($rolehash->{$item}) eq 'HASH') {
1420: $userdata{'extent'} = $item;
1421: foreach my $key (keys(%{$rolehash->{$item}})) {
1422: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
1423: ($userdata{'start'},$userdata{'end'}) =
1424: split(/:/,$rolehash->{$item}{$key});
1425: my $uniqid = $key.':'.$item;
1426: &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist);
1427: }
1428: }
1429: } elsif ($env{'form.roletype'} eq 'course') {
1430: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1431: split(/:/,$item);
1432: if (ref($rolehash->{$item}) eq 'HASH') {
1433: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
1434: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
1435: my $spanstart = '';
1436: my $spanend = '; ';
1437: my $space = ', ';
1438: if ($format eq 'html' || $format eq 'view') {
1439: $spanstart = '<span class="LC_nobreak">';
1440: $spanend = '</span><br />';
1441: $space = ', ';
1442: }
1443: $userdata{'extent'} .= $spanstart.
1444: $rolehash->{$item}{$cid}{'desc'}.$space;
1445: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
1446: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1447: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
1448: }
1449: }
1450: }
1451: }
1452: }
1453: &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
1454: }
1455: }
1456: }
1457: return;
1458: }
1459:
1460: sub build_user_record {
1461: my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1462: &process_date_info($userdata);
1463: my $username = $userdata->{'username'};
1464: my $domain = $userdata->{'domain'};
1465: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1466: $userdata->{'fullname'} =
1467: $userinfo->{$username.':'.$domain}{'fullname'};
1468: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1469: } else {
1470: &aggregate_user_info($domain,$username,$userinfo);
1471: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1472: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1473: }
1474: foreach my $key (keys(%{$indexhash})) {
1475: if (defined($userdata->{$key})) {
1476: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
1477: }
1478: }
1479: return;
1480: }
1481:
1482: sub courses_selector {
1483: my ($cdom,$formname) = @_;
1484: my %coursecodes = ();
1485: my %codes = ();
1486: my @codetitles = ();
1487: my %cat_titles = ();
1488: my %cat_order = ();
1489: my %idlist = ();
1490: my %idnums = ();
1491: my %idlist_titles = ();
1492: my $caller = 'global';
1493: my $format_reply;
1494: my $jscript = '';
1495:
1496: my $totcodes = 0;
1497: $totcodes =
1498: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1499: $cdom,$totcodes);
1500: if ($totcodes > 0) {
1501: $format_reply =
1502: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1503: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1504: if ($format_reply eq 'ok') {
1505: my $numtypes = @codetitles;
1506: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1507: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1508: my $longtitles_str = join('","',@{$longtitles});
1509: my $allidlist = $idlist{$codetitles[0]};
1510: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1511: $jscript .= $scripttext;
1512: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1513: }
1514: }
1515: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1516:
1517: my %elements = (
1518: Year => 'selectbox',
1519: coursepick => 'radio',
1520: coursetotal => 'text',
1521: courselist => 'text',
1522: );
1523: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1524: if ($env{'form.coursepick'} eq 'category') {
1525: $jscript .= qq|
1526: function setCourseCat(formname) {
1527: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1528: return;
1529: }
1530: courseSet('Year');
1531: for (var j=0; j<formname.Semester.length; j++) {
1532: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
1533: formname.Semester.options[j].selected = true;
1534: }
1535: }
1536: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
1537: return;
1538: }
1539: courseSet('Semester');
1540: for (var j=0; j<formname.Department.length; j++) {
1541: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
1542: }
1543: }
1544: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
1545: return;
1546: }
1547: courseSet('Department');
1548: for (var j=0; j<formname.Number.length; j++) {
1549: if (formname.Number.options[j].value == "$env{'form.Number'}") {
1550: formname.Number.options[j].selected = true;
1551: }
1552: }
1553: }
1554: |;
1555: }
1556: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
1557: \%idlist_titles);
1558: }
1559:
1560: sub course_selector_loadcode {
1561: my ($formname) = @_;
1562: my $loadcode;
1563: if ($env{'form.coursepick'} ne '') {
1564: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
1565: if ($env{'form.coursepick'} eq 'category') {
1566: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
1567: }
1568: }
1569: return $loadcode;
1570: }
1571:
1572: sub process_coursepick {
1573: my $coursefilter = $env{'form.coursepick'};
1574: my $cdom = $env{'request.role.domain'};
1575: my %courses;
1576: if ($coursefilter eq 'all') {
1577: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1578: undef,undef,'Course');
1579: } elsif ($coursefilter eq 'category') {
1580: my $instcode = &instcode_from_coursefilter();
1581: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1582: undef,undef,'Course');
1583: } elsif ($coursefilter eq 'specific') {
1584: if ($env{'form.coursetotal'} > 1) {
1585: my @course_ids = split(/&&/,$env{'form.courselist'});
1586: foreach my $cid (@course_ids) {
1587: $courses{$cid} = '';
1588: }
1589: } else {
1590: $courses{$env{'form.courselist'}} = '';
1591: }
1592: }
1593: return %courses;
1594: }
1595:
1596: sub instcode_from_coursefilter {
1597: my $instcode = '';
1598: my @cats = ('Semester','Year','Department','Number');
1599: foreach my $category (@cats) {
1600: if (defined($env{'form.'.$category})) {
1601: unless ($env{'form.'.$category} eq '-1') {
1602: $instcode .= $env{'form.'.$category};
1603: }
1604: }
1605: }
1606: if ($instcode eq '') {
1607: $instcode = '.';
1608: }
1609: return $instcode;
1610: }
1611:
1612: sub display_adv_courseroles {
1613: my $output;
1614: #
1615: # List course personnel
1616: my %coursepersonnel =
1617: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
1618: #
1619: $output = '<br />'.&Apache::loncommon::start_data_table();
1620: foreach my $role (sort(keys(%coursepersonnel))) {
1621: next if ($role =~ /^\s*$/);
1622: $output .= &Apache::loncommon::start_data_table_row().
1623: '<td>'.$role.'</td><td>';
1624: foreach my $user (split(',',$coursepersonnel{$role})) {
1625: my ($puname,$pudom)=split(':',$user);
1626: $output .= ' '.&Apache::loncommon::aboutmewrapper(
1627: &Apache::loncommon::plainname($puname,$pudom),
1628: $puname,$pudom);
1629: }
1630: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
1631: }
1632: $output .= &Apache::loncommon::end_data_table();
1633: }
1634:
1635: sub make_keylist_array {
1636: my ($index,$keylist);
1637: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
1638: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
1639: $index->{'end'} = &Apache::loncoursedata::CL_END();
1640: $index->{'start'} = &Apache::loncoursedata::CL_START();
1641: $index->{'id'} = &Apache::loncoursedata::CL_ID();
1642: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
1643: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
1644: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
1645: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
1646: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
1647: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
1648: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
1649: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
1650: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1651: foreach my $key (keys(%{$index})) {
1652: $keylist->[$index->{$key}] = $key;
1653: }
1654: return ($index,$keylist);
1655: }
1656:
1657: sub aggregate_user_info {
1658: my ($udom,$uname,$userinfo) = @_;
1659: my %info=&Apache::lonnet::get('environment',
1660: ['firstname','middlename',
1661: 'lastname','generation','id'],
1662: $udom,$uname);
1663: my ($tmp) = keys(%info);
1664: my ($fullname,$id);
1665: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
1666: $fullname = 'not available';
1667: $id = 'not available';
1668: &Apache::lonnet::logthis('unable to retrieve environment '.
1669: 'for '.$uname.':'.$udom);
1670: } else {
1671: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
1672: $id = $info{'id'};
1673: }
1674: $userinfo->{$uname.':'.$udom} = {
1675: fullname => $fullname,
1676: id => $id,
1677: };
1678: return;
1679: }
1680:
1681: sub process_date_info {
1682: my ($userdata) = @_;
1683: my $now = time;
1684: $userdata->{'status'} = 'Active';
1685: if ($userdata->{'start'} > 0) {
1686: if ($now < $userdata->{'start'}) {
1687: $userdata->{'status'} = 'Future';
1688: }
1689: }
1690: if ($userdata->{'end'} > 0) {
1691: if ($now > $userdata->{'end'}) {
1692: $userdata->{'status'} = 'Expired';
1693: }
1694: }
1695: return;
1696: }
1697:
1698: sub show_users_list {
1699: my ($r,$context,$mode,$linkto,$statusmode,$userlist,$keylist)=@_;
1700: #
1701: # Variables for excel output
1702: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1703: #
1704: # Variables for csv output
1705: my ($CSVfile,$CSVfilename);
1706: #
1707: my $sortby = $env{'form.sortby'};
1708: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1709: if ($context eq 'course') {
1710: push(@sortable,('section','groups','type'));
1711: } else {
1712: push(@sortable,'extent');
1713: }
1714: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1715: $sortby = 'username';
1716: }
1717: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1718: if ($context eq 'course') {
1719: $cid=$env{'request.course.id'};
1720: $cdom = $env{'course.'.$cid.'.domain'};
1721: $cnum = $env{'course.'.$cid.'.num'};
1722: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1723: $userlist,$keylist,$cdom,$cnum);
1724: if (! exists($env{'form.displayphotos'})) {
1725: $env{'form.displayphotos'} = 'off';
1726: }
1727: $displayphotos = $env{'form.displayphotos'};
1728: if (! exists($env{'form.displayclickers'})) {
1729: $env{'form.displayclickers'} = 'off';
1730: }
1731: $displayclickers = $env{'form.displayclickers'};
1732: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1733: $r->print('
1734: <script type="text/javascript">
1735: function photowindow(photolink) {
1736: var title = "Photo_Viewer";
1737: var options = "scrollbars=1,resizable=1,menubar=0";
1738: options += ",width=240,height=240";
1739: stdeditbrowser = open(photolink,title,options,"1");
1740: stdeditbrowser.focus();
1741: }
1742: </script>
1743: ');
1744: }
1745: $r->print(<<END);
1746: <input type="hidden" name="displayphotos" value="$displayphotos" />
1747: <input type="hidden" name="displayclickers" value="$displayclickers" />
1748: END
1749: }
1750: unless ($mode eq 'autoenroll') {
1751: $r->print(<<END);
1752: <input type="hidden" name="state" value="$env{'form.state'}" />
1753: END
1754: }
1755: $r->print(<<END);
1756: <input type="hidden" name="sortby" value="$sortby" />
1757: END
1758:
1759: my %lt=&Apache::lonlocal::texthash(
1760: 'username' => "username",
1761: 'domain' => "domain",
1762: 'id' => 'ID',
1763: 'fullname' => "name",
1764: 'section' => "section",
1765: 'groups' => "active groups",
1766: 'start' => "start date",
1767: 'end' => "end date",
1768: 'status' => "status",
1769: 'role' => "role",
1770: 'type' => "enroll type/action",
1771: 'email' => "email address",
1772: 'clicker' => "clicker id",
1773: 'photo' => "photo",
1774: 'extent' => "extent",
1775: );
1776: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1777: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1778: } elsif ($context eq 'construction_space') {
1779: $lt{'extent'} = &mt('Author');
1780: }
1781: my @cols = ('username','domain','id','fullname');
1782: if ($context eq 'course') {
1783: push(@cols,'section');
1784: }
1785: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
1786: push(@cols,('start','end'));
1787: }
1788: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
1789: push(@cols,'role');
1790: }
1791: if ($context eq 'domain' && ($env{'form.roletype'} eq 'construction_space' ||
1792: $env{'form.roletype'} eq 'course')) {
1793: push (@cols,'extent');
1794: }
1795: if (($statusmode eq 'Any') &&
1796: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
1797: push(@cols,'status');
1798: }
1799: if ($context eq 'course') {
1800: push(@cols,'groups');
1801: }
1802: push(@cols,'email');
1803:
1804: my $rolefilter = $env{'form.showrole'};
1805: if ($env{'form.showrole'} eq 'cr') {
1806: $rolefilter = &mt('custom');
1807: } elsif ($env{'form.showrole'} ne 'Any') {
1808: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
1809: }
1810: my $results_description = &results_header_row($rolefilter,$statusmode,
1811: $context);
1812: $r->print('<b>'.$results_description.'</b><br />');
1813: my $output;
1814: if ($mode eq 'html' || $mode eq 'view') {
1815: $r->print(<<END);
1816: <input type="hidden" name="sname" value="" />
1817: <input type="hidden" name="sdom" value="" />
1818: END
1819: if ($linkto eq 'aboutme') {
1820: $output = &mt("Select a user name to view the user's personal page.");
1821: } elsif ($linkto eq 'modify') {
1822: $output = &mt("Select a user name to modify the user's information");
1823: }
1824: $output .= "\n<p>\n".
1825: &Apache::loncommon::start_data_table().
1826: &Apache::loncommon::start_data_table_header_row();
1827: if ($mode eq 'autoenroll') {
1828: $output .= "
1829: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1830: ";
1831: } else {
1832: $output .= "
1833: <th>Count</th>
1834: ";
1835: }
1836: foreach my $item (@cols) {
1837: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
1838: }
1839: my %role_types = &role_type_names();
1840: if ($context eq 'course') {
1841: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
1842: # Clicker display on or off?
1843: my %clicker_options = &Apache::lonlocal::texthash(
1844: 'on' => 'Show',
1845: 'off' => 'Hide',
1846: );
1847: my $clickerchg = 'on';
1848: if ($displayclickers eq 'on') {
1849: $clickerchg = 'off';
1850: }
1851: $output .= ' <th>'."\n".' '.
1852: '<a href="javascript:document.studentform.displayclickers.value='.
1853: "'".$clickerchg."'".';document.studentform.submit();">'.
1854: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
1855: ' </th>'."\n";
1856:
1857: # Photo display on or off?
1858: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1859: my %photo_options = &Apache::lonlocal::texthash(
1860: 'on' => 'Show',
1861: 'off' => 'Hide',
1862: );
1863: my $photochg = 'on';
1864: if ($displayphotos eq 'on') {
1865: $photochg = 'off';
1866: }
1867: $output .= ' <th>'."\n".' '.
1868: '<a href="javascript:document.studentform.displayphotos.value='.
1869: "'".$photochg."'".';document.studentform.submit();">'.
1870: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1871: ' </th>'."\n";
1872: }
1873: }
1874: $output .= &Apache::loncommon::end_data_table_header_row();
1875: }
1876: # Done with the HTML header line
1877: } elsif ($mode eq 'csv') {
1878: #
1879: # Open a file
1880: $CSVfilename = '/prtspool/'.
1881: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1882: time.'_'.rand(1000000000).'.csv';
1883: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
1884: $r->log_error("Couldn't open $CSVfilename for output $!");
1885: $r->print("Problems occured in writing the csv file. ".
1886: "This error has been logged. ".
1887: "Please alert your LON-CAPA administrator.");
1888: $CSVfile = undef;
1889: }
1890: #
1891: # Write headers and data to file
1892: print $CSVfile '"'.$results_description.'"'."\n";
1893: print $CSVfile '"'.join('","',map {
1894: &Apache::loncommon::csv_translate($lt{$_})
1895: } (@cols)).'"'."\n";
1896: } elsif ($mode eq 'excel') {
1897: # Create the excel spreadsheet
1898: ($excel_workbook,$excel_filename,$format) =
1899: &Apache::loncommon::create_workbook($r);
1900: return if (! defined($excel_workbook));
1901: $excel_sheet = $excel_workbook->addworksheet('userlist');
1902: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1903: #
1904: my @colnames = map {$lt{$_}} (@cols);
1905: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
1906: }
1907:
1908: # Done with header lines in all formats
1909:
1910: my %index;
1911: my $i;
1912: foreach my $idx (@$keylist) {
1913: $index{$idx} = $i++;
1914: }
1915: my $usercount = 0;
1916: # Get groups, role, permanent e-mail so we can sort on them if
1917: # necessary.
1918: foreach my $user (keys(%{$userlist})) {
1919: my ($uname,$udom,$role,$groups,$email);
1920: if (($statusmode ne 'Any') &&
1921: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
1922: delete($userlist->{$user});
1923: next;
1924: }
1925: if ($context eq 'domain') {
1926: if ($env{'form.roletype'} eq 'domain') {
1927: ($role,$uname,$udom) = split(/:/,$user);
1928:
1929: } elsif ($env{'form.roletype'} eq 'construction_space') {
1930: ($uname,$udom,$role) = split(/:/,$user,-1);
1931: } elsif ($env{'form.roletype'} eq 'course') {
1932: ($uname,$udom,$role) = split(/:/,$user);
1933: }
1934: } else {
1935: ($uname,$udom,$role) = split(/:/,$user,-1);
1936: if (($context eq 'course') && $role eq '') {
1937: $role = 'st';
1938: }
1939: }
1940: $userlist->{$user}->[$index{'role'}] = $role;
1941: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
1942: delete($userlist->{$user});
1943: next;
1944: }
1945: if (ref($classgroups) eq 'HASH') {
1946: $groups = $classgroups->{$user};
1947: }
1948: if (ref($groups->{active}) eq 'HASH') {
1949: $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}}));
1950: }
1951: my %emails = &Apache::loncommon::getemails($uname,$udom);
1952: if ($emails{'permanentemail'} =~ /\S/) {
1953: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
1954: }
1955: $usercount ++;
1956: }
1957: my $autocount = 0;
1958: my $manualcount = 0;
1959: my $lockcount = 0;
1960: my $unlockcount = 0;
1961: if ($usercount) {
1962: $r->print($output);
1963: } else {
1964: if ($mode eq 'autoenroll') {
1965: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1966: } else {
1967: return;
1968: }
1969: }
1970: #
1971: # Sort the users
1972: my $index = $index{$sortby};
1973: my $second = $index{'username'};
1974: my $third = $index{'domain'};
1975: my @sorted_users = sort {
1976: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
1977: ||
1978: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
1979: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
1980: } (keys(%$userlist));
1981: my $rowcount = 0;
1982: foreach my $user (@sorted_users) {
1983: my %in;
1984: my $sdata = $userlist->{$user};
1985: $rowcount ++;
1986: foreach my $item (@{$keylist}) {
1987: $in{$item} = $sdata->[$index{$item}];
1988: }
1989: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
1990: if (! defined($in{'start'}) || $in{'start'} == 0) {
1991: $in{'start'} = &mt('none');
1992: } else {
1993: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
1994: }
1995: if (! defined($in{'end'}) || $in{'end'} == 0) {
1996: $in{'end'} = &mt('none');
1997: } else {
1998: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
1999: }
2000: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2001: $r->print(&Apache::loncommon::start_data_table_row());
2002: $r->print("<td>$rowcount</td>\n");
2003: if ($linkto eq 'aboutme') {
2004: $in{'username'} =
2005: &Apache::loncommon::aboutmewrapper($in{'username'},
2006: $in{'username'},
2007: $in{'domain'});
2008: } elsif ($linkto eq 'modify') {
2009: $in{'username'} = '<a href="'.
2010: "javascript:document.studentform.sname.value='".
2011: $in{'username'}.
2012: "';document.studentform.sdom.value='".$in{'domain'}.
2013: "';document.studentform.state.value='selected".
2014: "';document.studentform.submit();".'">'.
2015: $in{'username'}."</a>\n";
2016: }
2017: foreach my $item (@cols) {
2018: $r->print('<td>'.$in{$item}.'</td>'."\n");
2019: }
2020: if ($context eq 'course') {
2021: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2022: if ($displayclickers eq 'on') {
2023: my $clickers =
2024: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2025: if ($clickers!~/\w/) { $clickers='-'; }
2026: $r->print('<td>'.$clickers.'</td>');
2027: } else {
2028: $r->print(' <td> </td> ');
2029: }
2030: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2031: if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') {
2032: my $imgurl =
2033: &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},
2034: 'gif','thumbnail');
2035: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
2036: } else {
2037: $r->print(' <td> </td> ');
2038: }
2039: }
2040: }
2041: }
2042: $r->print(&Apache::loncommon::end_data_table_row());
2043: } elsif ($mode eq 'csv') {
2044: next if (! defined($CSVfile));
2045: # no need to bother with $linkto
2046: if (! defined($in{'start'}) || $in{'start'} == 0) {
2047: $in{'start'} = &mt('none');
2048: } else {
2049: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2050: }
2051: if (! defined($in{'end'}) || $in{'end'} == 0) {
2052: $in{'end'} = &mt('none');
2053: } else {
2054: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2055: }
2056: my @line = ();
2057: foreach my $item (@cols) {
2058: push @line,&Apache::loncommon::csv_translate($in{$item});
2059: }
2060: print $CSVfile '"'.join('","',@line).'"'."\n";
2061: } elsif ($mode eq 'excel') {
2062: my $col = 0;
2063: foreach my $item (@cols) {
2064: if ($item eq 'start' || $item eq 'end') {
2065: if (defined($item) && $item != 0) {
2066: $excel_sheet->write($row,$col++,
2067: &Apache::lonstathelpers::calc_serial($in{item}),
2068: $format->{'date'});
2069: } else {
2070: $excel_sheet->write($row,$col++,'none');
2071: }
2072: } else {
2073: $excel_sheet->write($row,$col++,$in{$item});
2074: }
2075: }
2076: $row++;
2077: }
2078: }
2079: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2080: $r->print(&Apache::loncommon::end_data_table().'<br />');
2081: } elsif ($mode eq 'excel') {
2082: $excel_workbook->close();
2083: $r->print('<p><a href="'.$excel_filename.'">'.
2084: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2085: } elsif ($mode eq 'csv') {
2086: close($CSVfile);
2087: $r->print('<a href="'.$CSVfilename.'">'.
2088: &mt('Your CSV file').'</a> is ready for download.'.
2089: "\n");
2090: $r->rflush();
2091: }
2092: if ($mode eq 'autoenroll') {
2093: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2094: } else {
2095: return ($usercount);
2096: }
2097: }
2098:
2099: sub role_type_names {
2100: my %lt = &Apache::lonlocal::texthash (
2101: 'domain' => 'Domain Roles',
2102: 'construction_space' => 'Co-Author Roles',
2103: 'course' => 'Course Roles',
2104: );
2105: return %lt;
2106: }
2107:
2108: sub results_header_row {
2109: my ($rolefilter,$statusmode,$context) = @_;
2110: my ($description,$showfilter);
2111: if ($rolefilter ne 'Any') {
2112: $showfilter = $rolefilter;
2113: }
2114: if ($context eq 'course') {
2115: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
2116: if ($statusmode eq 'Expired') {
2117: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
2118: }
2119: if ($statusmode eq 'Future') {
2120: $description .= &mt('Users in course with future [_1] roles',$showfilter);
2121: } elsif ($statusmode eq 'Active') {
2122: $description .= &mt('Users in course with active [_1] roles',$showfilter);
2123: } else {
2124: if ($rolefilter eq 'Any') {
2125: $description .= &mt('All users in course');
2126: } else {
2127: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2128: }
2129: }
2130: } elsif ($context eq 'construction_space') {
2131: $description = &mt('Author space for [_1].').' ';
2132: if ($statusmode eq 'Expired') {
2133: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
2134: } elsif ($statusmode eq 'Future') {
2135: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
2136: } elsif ($statusmode eq 'Active') {
2137: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
2138: } else {
2139: if ($rolefilter eq 'Any') {
2140: $description .= &mt('All co-authors');
2141: } else {
2142: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2143: }
2144: }
2145: } elsif ($context eq 'domain') {
2146: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2147: $description = &mt('Domain - ').$domdesc.': ';
2148: if ($env{'form.roletype'} eq 'domain') {
2149: if ($statusmode eq 'Expired') {
2150: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
2151: } elsif ($statusmode eq 'Future') {
2152: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
2153: } elsif ($statusmode eq 'Active') {
2154: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
2155: } else {
2156: if ($rolefilter eq 'Any') {
2157: $description .= &mt('All users in domain');
2158: } else {
2159: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
2160: }
2161: }
2162: } elsif ($env{'form.roletype'} eq 'construction_space') {
2163: if ($statusmode eq 'Expired') {
2164: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
2165: } elsif ($statusmode eq 'Future') {
2166: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
2167: } elsif ($statusmode eq 'Active') {
2168: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
2169: } else {
2170: if ($rolefilter eq 'Any') {
2171: $description .= &mt('All users with co-author roles in domain',$showfilter);
2172: } else {
2173: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
2174: }
2175: }
2176: } elsif ($env{'form.roletype'} eq 'course') {
2177: my $coursefilter = $env{'form.coursepick'};
2178: if ($coursefilter eq 'category') {
2179: my $instcode = &instcode_from_coursefilter();
2180: if ($instcode eq '.') {
2181: $description .= &mt('All courses in domain').' - ';
2182: } else {
2183: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
2184: }
2185: } elsif ($coursefilter eq 'selected') {
2186: $description .= &mt('Selected courses in domain').' - ';
2187: } elsif ($coursefilter eq 'all') {
2188: $description .= &mt('All courses in domain').' - ';
2189: }
2190: if ($statusmode eq 'Expired') {
2191: $description .= &mt('users with expired [_1] roles',$showfilter);
2192: } elsif ($statusmode eq 'Future') {
2193: $description .= &mt('users with future [_1] roles',$showfilter);
2194: } elsif ($statusmode eq 'Active') {
2195: $description .= &mt('users with active [_1] roles',$showfilter);
2196: } else {
2197: if ($rolefilter eq 'Any') {
2198: $description .= &mt('all users');
2199: } else {
2200: $description .= &mt('users with [_1] roles',$rolefilter);
2201: }
2202: }
2203: }
2204: }
2205: return $description;
2206: }
2207:
2208: #################################################
2209: #################################################
2210: sub show_drop_list {
2211: my ($r,$classlist,$keylist,$nosort)=@_;
2212: my $cid=$env{'request.course.id'};
2213: if (! exists($env{'form.sortby'})) {
2214: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2215: ['sortby']);
2216: }
2217: my $sortby = $env{'form.sortby'};
2218: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
2219: $sortby = 'username';
2220: }
2221: my $cdom = $env{'course.'.$cid.'.domain'};
2222: my $cnum = $env{'course.'.$cid,'.num'};
2223: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
2224: $classlist,$keylist,$cdom,$cnum);
2225: #
2226: my $action = "drop";
2227: $r->print(<<END);
2228: <input type="hidden" name="sortby" value="$sortby" />
2229: <input type="hidden" name="action" value="$action" />
2230: <input type="hidden" name="state" value="done" />
2231: <script>
2232: function checkAll(field) {
2233: for (i = 0; i < field.length; i++)
2234: field[i].checked = true ;
2235: }
2236:
2237: function uncheckAll(field) {
2238: for (i = 0; i < field.length; i++)
2239: field[i].checked = false ;
2240: }
2241: </script>
2242: <p>
2243: <input type="hidden" name="phase" value="four">
2244: END
2245:
2246: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
2247: 'dom' => "domain",
2248: 'sn' => "student name",
2249: 'sec' => "section",
2250: 'start' => "start date",
2251: 'end' => "end date",
2252: 'groups' => "active groups",
2253: );
2254: if ($nosort) {
2255: $r->print(&Apache::loncommon::start_data_table());
2256: $r->print(<<END);
2257: <tr>
2258: <th> </th>
2259: <th>$lt{'usrn'}</th>
2260: <th>$lt{'dom'}</th>
2261: <th>ID</th>
2262: <th>$lt{'sn'}</th>
2263: <th>$lt{'sec'}</th>
2264: <th>$lt{'start'}</th>
2265: <th>$lt{'end'}</th>
2266: <th>$lt{'groups'}</th>
2267: </tr>
2268: END
2269:
2270: } else {
2271: $r->print(&Apache::loncommon::start_data_table());
2272: $r->print(<<END);
2273: <tr><th> </th>
2274: <th>
2275: <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
2276: </th><th>
2277: <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
2278: </th><th>
2279: <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
2280: </th><th>
2281: <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
2282: </th><th>
2283: <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
2284: </th><th>
2285: <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
2286: </th><th>
2287: <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
2288: </th><th>
2289: <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
2290: </th>
2291: </tr>
2292: END
2293: }
2294: #
2295: # Sort the students
2296: my %index;
2297: my $i;
2298: foreach (@$keylist) {
2299: $index{$_} = $i++;
2300: }
2301: $index{'groups'} = scalar(@$keylist);
2302: my $index = $index{$sortby};
2303: my $second = $index{'username'};
2304: my $third = $index{'domain'};
2305: my @Sorted_Students = sort {
2306: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
2307: ||
2308: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
2309: ||
2310: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
2311: } (keys(%$classlist));
2312: foreach my $student (@Sorted_Students) {
2313: my $error;
2314: my $sdata = $classlist->{$student};
2315: my $username = $sdata->[$index{'username'}];
2316: my $domain = $sdata->[$index{'domain'}];
2317: my $section = $sdata->[$index{'section'}];
2318: my $name = $sdata->[$index{'fullname'}];
2319: my $id = $sdata->[$index{'id'}];
2320: my $start = $sdata->[$index{'start'}];
2321: my $end = $sdata->[$index{'end'}];
2322: my $groups = $classgroups->{$student};
2323: my $active_groups;
2324: if (ref($groups->{active}) eq 'HASH') {
2325: $active_groups = join(', ',keys(%{$groups->{'active'}}));
2326: }
2327: if (! defined($start) || $start == 0) {
2328: $start = &mt('none');
2329: } else {
2330: $start = &Apache::lonlocal::locallocaltime($start);
2331: }
2332: if (! defined($end) || $end == 0) {
2333: $end = &mt('none');
2334: } else {
2335: $end = &Apache::lonlocal::locallocaltime($end);
2336: }
2337: my $status = $sdata->[$index{'status'}];
2338: next if ($status ne 'Active');
2339: #
2340: $r->print(&Apache::loncommon::start_data_table_row());
2341: $r->print(<<"END");
2342: <td><input type="checkbox" name="droplist" value="$student"></td>
2343: <td>$username</td>
2344: <td>$domain</td>
2345: <td>$id</td>
2346: <td>$name</td>
2347: <td>$section</td>
2348: <td>$start</td>
2349: <td>$end</td>
2350: <td>$active_groups</td>
2351: END
2352: $r->print(&Apache::loncommon::end_data_table_row());
2353: }
2354: $r->print(&Apache::loncommon::end_data_table().'<br />');
2355: %lt=&Apache::lonlocal::texthash(
2356: 'dp' => "Expire Users' Roles",
2357: 'ca' => "check all",
2358: 'ua' => "uncheck all",
2359: );
2360: $r->print(<<"END");
2361: </p><p>
2362: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
2363: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
2364: <p><input type=submit value="$lt{'dp'}"></p>
2365: END
2366: return;
2367: }
2368:
2369: #
2370: # Print out the initial form to get the file containing a list of users
2371: #
2372: sub print_first_users_upload_form {
2373: my ($r,$context) = @_;
2374: my $str;
2375: $str = '<input type="hidden" name="phase" value="two">';
2376: $str .= '<input type="hidden" name="action" value="upload" />';
2377: $str .= '<input type="hidden" name="state" value="got_file" />';
2378: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
2379: $str .= &Apache::loncommon::upfile_select_html();
2380: $str .= "<p>\n";
2381: $str .= '<input type="submit" name="fileupload" value="'.
2382: &mt('Upload file of users').'">'."\n";
2383: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
2384: &mt('Ignore First Line')."</label></p>\n";
2385: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
2386: &mt("How do I create a users list from a spreadsheet")).
2387: "<br />\n";
2388: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
2389: &mt("How do I create a CSV file from a spreadsheet")).
2390: "<br />\n";
2391: $str .= &Apache::loncommon::end_page();
2392: $r->print($str);
2393: return;
2394: }
2395:
2396: # ================================================= Drop/Add from uploaded file
2397: sub upfile_drop_add {
2398: my ($r,$context) = @_;
2399: &Apache::loncommon::load_tmp_file($r);
2400: my @userdata=&Apache::loncommon::upfile_record_sep();
2401: if($env{'form.noFirstLine'}){shift(@userdata);}
2402: my @keyfields = split(/\,/,$env{'form.keyfields'});
2403: my %fields=();
2404: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
2405: if ($env{'form.upfile_associate'} eq 'reverse') {
2406: if ($env{'form.f'.$i} ne 'none') {
2407: $fields{$keyfields[$i]}=$env{'form.f'.$i};
2408: }
2409: } else {
2410: $fields{$env{'form.f'.$i}}=$keyfields[$i];
2411: }
2412: }
2413: #
2414: # Store the field choices away
2415: foreach my $field (qw/username names
2416: fname mname lname gen id sec ipwd email role/) {
2417: $env{'form.'.$field.'_choice'}=$fields{$field};
2418: }
2419: &Apache::loncommon::store_course_settings('enrollment_upload',
2420: { 'username_choice' => 'scalar',
2421: 'names_choice' => 'scalar',
2422: 'fname_choice' => 'scalar',
2423: 'mname_choice' => 'scalar',
2424: 'lname_choice' => 'scalar',
2425: 'gen_choice' => 'scalar',
2426: 'id_choice' => 'scalar',
2427: 'sec_choice' => 'scalar',
2428: 'ipwd_choice' => 'scalar',
2429: 'email_choice' => 'scalar',
2430: 'role_choice' => 'scalar' });
2431: #
2432: my ($startdate,$enddate) = &get_dates_from_form();
2433: if ($env{'form.makedatesdefault'}) {
2434: $r->print(&make_dates_default($startdate,$enddate));
2435: }
2436: # Determine domain and desired host (home server)
2437: my $domain=$env{'request.role.domain'};
2438: my $desiredhost = $env{'form.lcserver'};
2439: if (lc($desiredhost) eq 'default') {
2440: $desiredhost = undef;
2441: } else {
2442: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
2443: if (! exists($home_servers{$desiredhost})) {
2444: $r->print('<span class="LC_error">'.&mt('Error').
2445: &mt('Invalid home server specified').'</span>');
2446: $r->print(&Apache::loncommon::end_page());
2447: return;
2448: }
2449: }
2450: # Determine authentication mechanism
2451: my $changeauth;
2452: if ($context eq 'domain') {
2453: $changeauth = $env{'form.changeauth'};
2454: }
2455: my $amode = '';
2456: my $genpwd = '';
2457: if ($env{'form.login'} eq 'krb') {
2458: $amode='krb';
2459: $amode.=$env{'form.krbver'};
2460: $genpwd=$env{'form.krbarg'};
2461: } elsif ($env{'form.login'} eq 'int') {
2462: $amode='internal';
2463: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
2464: $genpwd=$env{'form.intarg'};
2465: }
2466: } elsif ($env{'form.login'} eq 'loc') {
2467: $amode='localauth';
2468: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
2469: $genpwd=$env{'form.locarg'};
2470: }
2471: }
2472: if ($amode =~ /^krb/) {
2473: if (! defined($genpwd) || $genpwd eq '') {
2474: $r->print('<span class="Error">'.
2475: &mt('Unable to enroll users').' '.
2476: &mt('No Kerberos domain was specified.').'</span></p>');
2477: $amode = ''; # This causes the loop below to be skipped
2478: }
2479: }
2480: my ($cid,$defaultsec,$defaultrole,$setting);
2481: if ($context eq 'domain') {
2482: $setting = $env{'form.roleaction'};
2483: if ($setting eq 'domain') {
2484: $defaultrole = $env{'form.defaultrole'};
2485: } elsif ($setting eq 'course') {
2486: $defaultrole = $env{'form.courserole'};
2487: }
2488: } elsif ($context eq 'construction_space') {
2489: $defaultrole = $env{'form.defaultrole'};
2490: }
2491: if ($context eq 'domain' && $setting eq 'course') {
2492: if ($env{'form.newsec'} ne '') {
2493: $defaultsec = $env{'form.newsec'};
2494: } elsif ($env{'form.defaultsec'} ne '') {
2495: $defaultsec = $env{'form.defaultsec'}
2496: }
2497: }
2498: if ($env{'request.course.id'} ne '') {
2499: $cid = $env{'request.course.id'};
2500: } elsif ($env{'form.defaultdomain'} ne '' && $env{'form.defaultcourse'} ne '') {
2501: $cid = $env{'form.defaultdomain'}.'_'.
2502: $env{'form.defaultcourse'};
2503: }
2504: if ( $domain eq &LONCAPA::clean_domain($domain)
2505: && ($amode ne '')) {
2506: #######################################
2507: ## Add/Modify Users ##
2508: #######################################
2509: if ($context eq 'course') {
2510: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
2511: } elsif ($context eq 'construction_space') {
2512: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
2513: } else {
2514: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
2515: }
2516: my %counts = (
2517: user => 0,
2518: auth => 0,
2519: role => 0,
2520: );
2521: my $flushc=0;
2522: my %student=();
2523: my %curr_groups;
2524: my %userchg;
2525: if ($context eq 'course') {
2526: # Get information about course groups
2527: %curr_groups = &Apache::longroup::coursegroups();
2528: }
2529: my (%curr_rules,%got_rules,%alerts);
2530: # Get new users list
2531: foreach (@userdata) {
2532: my %entries=&Apache::loncommon::record_sep($_);
2533: # Determine user name
2534: unless (($entries{$fields{'username'}} eq '') ||
2535: (!defined($entries{$fields{'username'}}))) {
2536: my ($fname, $mname, $lname,$gen) = ('','','','');
2537: if (defined($fields{'names'})) {
2538: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
2539: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
2540: } else {
2541: if (defined($fields{'fname'})) {
2542: $fname=$entries{$fields{'fname'}};
2543: }
2544: if (defined($fields{'mname'})) {
2545: $mname=$entries{$fields{'mname'}};
2546: }
2547: if (defined($fields{'lname'})) {
2548: $lname=$entries{$fields{'lname'}};
2549: }
2550: if (defined($fields{'gen'})) {
2551: $gen=$entries{$fields{'gen'}};
2552: }
2553: }
2554: if ($entries{$fields{'username'}}
2555: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
2556: $r->print('<br />'.
2557: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
2558: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
2559: '</b>');
2560: } else {
2561: my $username = $entries{$fields{'username'}};
2562: my $sec;
2563: if ($context eq 'course' || $setting eq 'course') {
2564: # determine section number
2565: if (defined($fields{'sec'})) {
2566: if (defined($entries{$fields{'sec'}})) {
2567: $sec=$entries{$fields{'sec'}};
2568: }
2569: } else {
2570: $sec = $defaultsec;
2571: }
2572: # remove non alphanumeric values from section
2573: $sec =~ s/\W//g;
2574: if ($sec eq "none" || $sec eq 'all') {
2575: $r->print('<br />'.
2576: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
2577: $username,$sec,$fname,$mname,$lname,$gen));
2578: next;
2579: } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
2580: $r->print('<br />'.
2581: &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a course group. Section names and group names must be distinct.',
2582: $username,$sec,$fname,$mname,$lname,$gen));
2583: next;
2584: }
2585: }
2586: # determine id number
2587: my $id='';
2588: if (defined($fields{'id'})) {
2589: if (defined($entries{$fields{'id'}})) {
2590: $id=$entries{$fields{'id'}};
2591: }
2592: $id=~tr/A-Z/a-z/;
2593: }
2594: # determine email address
2595: my $email='';
2596: if (defined($fields{'email'})) {
2597: if (defined($entries{$fields{'email'}})) {
2598: $email=$entries{$fields{'email'}};
2599: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
2600: }
2601: # determine user password
2602: my $password = $genpwd;
2603: if (defined($fields{'ipwd'})) {
2604: if ($entries{$fields{'ipwd'}}) {
2605: $password=$entries{$fields{'ipwd'}};
2606: }
2607: }
2608: # determine user role
2609: my $role = '';
2610: if (defined($fields{'role'})) {
2611: if ($entries{$fields{'role'}}) {
2612: my @poss_roles =
2613: &curr_role_permissions($context,$setting);
2614: if (grep(/^\Q$entries{$fields{'role'}}\E/,@poss_roles)) {
2615: $role=$entries{$fields{'role'}};
2616: } else {
2617: my $rolestr = join(', ',@poss_roles);
2618: $r->print('<br />'.
2619: &mt('<b>[_1]</b>: You do not have permission to add the requested role [_2] for the user.',$entries{$fields{'username'}},$entries{$fields{'role'}}).'<br />'.&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n");
2620: next;
2621: }
2622: }
2623: }
2624: if ($role eq '') {
2625: $role = $defaultrole;
2626: }
2627: # Clean up whitespace
2628: foreach (\$domain,\$username,\$id,\$fname,\$mname,
2629: \$lname,\$gen,\$sec,\$role) {
2630: $$_ =~ s/(\s+$|^\s+)//g;
2631: }
2632: # check against rules
2633: my $checkid = 0;
2634: my $newuser = 0;
2635: my (%rulematch,%inst_results,%idinst_results);
2636: my $uhome=&Apache::lonnet::homeserver($username,$domain);
2637: if ($uhome eq 'no_host') {
2638: $checkid = 1;
2639: $newuser = 1;
2640: my $checkhash;
2641: my $checks = { 'username' => 1 };
2642: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
2643: &Apache::loncommon::user_rule_check($checkhash,$checks,
2644: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
2645: \%got_rules);
2646: if (ref($alerts{'username'}) eq 'HASH') {
2647: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
2648: next if ($alerts{'username'}{$domain}{$username});
2649: }
2650: }
2651: }
2652: if ($id ne '') {
2653: if (!$newuser) {
2654: my %idhash = &Apache::lonnet::idrget($domain,($username));
2655: if ($idhash{$username} ne $id) {
2656: $checkid = 1;
2657: }
2658: }
2659: if ($checkid) {
2660: my $checkhash;
2661: my $checks = { 'id' => 1 };
2662: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
2663: 'id' => $id };
2664: &Apache::loncommon::user_rule_check($checkhash,$checks,
2665: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
2666: \%got_rules);
2667: if (ref($alerts{'id'}) eq 'HASH') {
2668: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
2669: next if ($alerts{'id'}{$domain}{$id});
2670: }
2671: }
2672: }
2673: }
2674: if ($password || $env{'form.login'} eq 'loc') {
2675: my ($userresult,$authresult,$roleresult);
2676: if ($role eq 'st') {
2677: &modifystudent($domain,$username,$cid,$sec,
2678: $desiredhost);
2679: $roleresult =
2680: &Apache::lonnet::modifystudent
2681: ($domain,$username,$id,$amode,$password,
2682: $fname,$mname,$lname,$gen,$sec,$enddate,
2683: $startdate,$env{'form.forceid'},
2684: $desiredhost,$email);
2685: } else {
2686: ($userresult,$authresult,$roleresult) =
2687: &modifyuserrole($context,$setting,
2688: $changeauth,$cid,$domain,$username,
2689: $id,$amode,$password,$fname,
2690: $mname,$lname,$gen,$sec,
2691: $env{'form.forceid'},$desiredhost,
2692: $email,$role,$enddate,$startdate,$checkid);
2693: }
2694: $flushc =
2695: &user_change_result($r,$userresult,$authresult,
2696: $roleresult,\%counts,$flushc,
2697: $username,%userchg);
2698: } else {
2699: if ($context eq 'course') {
2700: $r->print('<br />'.
2701: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
2702: );
2703: } elsif ($context eq 'construction_space') {
2704: $r->print('<br />'.
2705: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
2706: );
2707: } else {
2708: $r->print('<br />'.
2709: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
2710: );
2711: }
2712: }
2713: }
2714: }
2715: } # end of foreach (@userdata)
2716: # Flush the course logs so reverse user roles immediately updated
2717: &Apache::lonnet::flushcourselogs();
2718: $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).
2719: "</p>\n");
2720: if ($counts{'role'} > 0) {
2721: $r->print("<p>\n".
2722: &mt('Roles added for [_1] users. If user is active, the new role will be available when the user next logs in to LON-CAPA.',$counts{'role'})."</p>\n");
2723: }
2724: if ($counts{'auth'} > 0) {
2725: $r->print("<p>\n".
2726: &mt('Authentication changed for [_1] existing users.',
2727: $counts{'auth'})."</p>\n");
2728: }
2729: if (keys(%alerts) > 0) {
2730: if (ref($alerts{'username'}) eq 'HASH') {
2731: foreach my $dom (sort(keys(%{$alerts{'username'}}))) {
2732: my $count;
2733: if (ref($alerts{'username'}{$dom}) eq 'HASH') {
2734: $count = keys(%{$alerts{'username'}{$dom}});
2735: }
2736: my $domdesc = &Apache::lonnet::domain($domain,'description');
2737: if (ref($curr_rules{$dom}) eq 'HASH') {
2738: $r->print(&Apache::loncommon::instrule_disallow_msg(
2739: 'username',$domdesc,$count,'upload'));
2740: }
2741: $r->print(&Apache::loncommon::user_rule_formats($dom,
2742: $domdesc,$curr_rules{$dom}{'username'},
2743: 'username'));
2744: }
2745: }
2746: if (ref($alerts{'id'}) eq 'HASH') {
2747: foreach my $dom (sort(keys(%{$alerts{'id'}}))) {
2748: my $count;
2749: if (ref($alerts{'id'}{$dom}) eq 'HASH') {
2750: $count = keys(%{$alerts{'id'}{$dom}});
2751: }
2752: my $domdesc = &Apache::lonnet::domain($domain,'description');
2753: if (ref($curr_rules{$dom}) eq 'HASH') {
2754: $r->print(&Apache::loncommon::instrule_disallow_msg(
2755: 'id',$domdesc,$count,'upload'));
2756: }
2757: $r->print(&Apache::loncommon::user_rule_formats($dom,
2758: $domdesc,$curr_rules{$dom}{'id'},'id'));
2759: }
2760: }
2761: }
2762: $r->print('<form name="uploadresult" action="/adm/createuser">');
2763: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
2764: $r->print('</form>');
2765: #####################################
2766: # Drop students #
2767: #####################################
2768: if ($env{'form.fullup'} eq 'yes') {
2769: $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
2770: # Get current classlist
2771: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
2772: if (! defined($classlist)) {
2773: $r->print(&mt('There are no students currently enrolled.').
2774: "\n");
2775: } else {
2776: # Remove the students we just added from the list of students.
2777: foreach (@userdata) {
2778: my %entries=&Apache::loncommon::record_sep($_);
2779: unless (($entries{$fields{'username'}} eq '') ||
2780: (!defined($entries{$fields{'username'}}))) {
2781: delete($classlist->{$entries{$fields{'username'}}.
2782: ':'.$domain});
2783: }
2784: }
2785: # Print out list of dropped students.
2786: &show_drop_list($r,$classlist,$keylist,'nosort');
2787: }
2788: }
2789: } # end of unless
2790: }
2791:
2792: sub user_change_result {
2793: my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
2794: $userchg) = @_;
2795: my $okresult = 0;
2796: if ($userresult ne 'ok') {
2797: if ($userresult =~ /^error:(.+)$/) {
2798: my $error = $1;
2799: $r->print('<br />'.
2800: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
2801: }
2802: } else {
2803: $counts->{'user'} ++;
2804: $okresult = 1;
2805: }
2806: if ($authresult ne 'ok') {
2807: if ($authresult =~ /^error:(.+)$/) {
2808: my $error = $1;
2809: $r->print('<br />'.
2810: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
2811: }
2812: } else {
2813: $counts->{'auth'} ++;
2814: $okresult = 1;
2815: }
2816: if ($roleresult ne 'ok') {
2817: if ($roleresult =~ /^error:(.+)$/) {
2818: my $error = $1;
2819: $r->print('<br />'.
2820: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
2821: }
2822: } else {
2823: $counts->{'role'} ++;
2824: $okresult = 1;
2825: }
2826: if ($okresult) {
2827: $flushc++;
2828: $userchg->{$username}=1;
2829: $r->print('. ');
2830: if ($flushc>15) {
2831: $r->rflush;
2832: $flushc=0;
2833: }
2834: }
2835: return $flushc;
2836: }
2837:
2838: # ========================================================= Menu Phase Two Drop
2839: sub print_expire_menu {
2840: my ($r,$context) = @_;
2841: $r->print("<h3>".&mt("Expire Users' Roles")."</h3>");
2842: my $cid=$env{'request.course.id'};
2843: my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
2844: if (! defined($classlist)) {
2845: $r->print(&mt('There are no students currently enrolled.')."\n");
2846: return;
2847: }
2848: # Print out the available choices
2849: &show_drop_list($r,$classlist,$keylist);
2850: return;
2851: }
2852:
2853:
2854: # ================================================================== Phase four
2855:
2856: sub expire_user_list {
2857: my ($r,$context) = @_;
2858: my $count=0;
2859: my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
2860: foreach (@droplist) {
2861: my ($uname,$udom)=split(/\:/,$_);
2862: # drop student
2863: my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
2864: if ($result eq 'ok' || $result eq 'ok:') {
2865: $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'<br>');
2866: $count++;
2867: } else {
2868: $r->print(
2869: &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
2870: '<br />');
2871: }
2872: }
2873: $r->print('<p><b>'.&mt('Dropped [_1] user(s).',$count).'</b></p>');
2874: $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
2875: }
2876:
2877: sub classlist_drop {
2878: my ($scope,$uname,$udom,$now,$action) = @_;
2879: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
2880: my $cid=$cdom.'_'.$cnum;
2881: my $user = $uname.':'.$udom;
2882: if ($action eq 'drop') {
2883: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
2884: my $result =
2885: &Apache::lonnet::cput('classlist',
2886: { $user => $now },
2887: $env{'course.'.$cid.'.domain'},
2888: $env{'course.'.$cid.'.num'});
2889: return &mt('Drop from classlist: [_1]',
2890: '<b>'.$result.'</b>').'<br />';
2891: }
2892: }
2893: }
2894:
2895: sub active_student_roles {
2896: my ($cnum,$cdom,$uname,$udom) = @_;
2897: my %roles =
2898: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
2899: ['future','active'],['st']);
2900: return exists($roles{"$cnum:$cdom:st"});
2901: }
2902:
2903: sub section_check_js {
2904: my $groupslist= &get_groupslist();
2905: return <<"END";
2906: function validate(caller) {
2907: var groups = new Array("$groupslist");
2908: var secname = caller.value;
2909: if ((secname == 'all') || (secname == 'none')) {
2910: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
2911: return 'error';
2912: }
2913: if (secname != '') {
2914: for (var k=0; k<groups.length; k++) {
2915: if (secname == groups[k]) {
2916: alert("'"+secname+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
2917: return 'error';
2918: }
2919: }
2920: }
2921: return 'ok';
2922: }
2923: END
2924: }
2925:
2926: sub set_login {
2927: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
2928: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2929: my $response;
2930: my ($authnum,%can_assign) =
2931: &Apache::loncommon::get_assignable_auth($dom);
2932: if ($authnum) {
2933: $response = &Apache::loncommon::start_data_table();
2934: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2935: $response .= &Apache::loncommon::start_data_table_row().
2936: '<td>'.$authformkrb.'</td>'.
2937: &Apache::loncommon::end_data_table_row()."\n";
2938: }
2939: if ($can_assign{'int'}) {
2940: $response .= &Apache::loncommon::start_data_table_row().
2941: '<td>'.$authformint.'</td>'.
2942: &Apache::loncommon::end_data_table_row()."\n"
2943: }
2944: if ($can_assign{'loc'}) {
2945: $response .= &Apache::loncommon::start_data_table_row().
2946: '<td>'.$authformloc.'</td>'.
2947: &Apache::loncommon::end_data_table_row()."\n";
2948: }
2949: $response .= &Apache::loncommon::end_data_table();
2950: }
2951: return $response;
2952: }
2953:
2954: sub course_sections {
2955: my ($sections_count,$role) = @_;
2956: my $output = '';
2957: my @sections = (sort {$a <=> $b} keys %{$sections_count});
2958: if (scalar(@sections) == 1) {
2959: $output = '<select name="currsec_'.$role.'" >'."\n".
2960: ' <option value="">Select</option>'."\n".
2961: ' <option value="">No section</option>'."\n".
2962: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
2963: } else {
2964: $output = '<select name="currsec_'.$role.'" ';
2965: my $multiple = 4;
2966: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
2967: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
2968: foreach my $sec (@sections) {
2969: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
2970: }
2971: }
2972: $output .= '</select>';
2973: return $output;
2974: }
2975:
2976: sub get_groupslist {
2977: my $groupslist;
2978: my %curr_groups = &Apache::longroup::coursegroups();
2979: if (%curr_groups) {
2980: $groupslist = join('","',sort(keys(%curr_groups)));
2981: $groupslist = '"'.$groupslist.'"';
2982: }
2983: return $groupslist;
2984: }
2985:
2986: sub setsections_javascript {
2987: my ($form,$groupslist) = @_;
2988: my ($checkincluded,$finish,$roleplace,$setsection_js);
2989: if ($form eq 'cu') {
2990: $checkincluded = 'formname.elements[i-1].checked == true';
2991: $finish = 'formname.submit()';
2992: $roleplace = 3;
2993: } else {
2994: $checkincluded = 'formname.name == "'.$form.'"';
2995: $finish = "seccheck = 'ok';";
2996: $roleplace = 1;
2997: $setsection_js = "var seccheck = 'alert';";
2998: }
2999: my %alerts = &Apache::lonlocal::texthash(
3000: secd => 'Section designations do not apply to Course Coordinator roles.',
3001: accr => 'A course coordinator role will be added with access to all sections.',
3002: inea => 'In each course, each user may only have one student role at a time.',
3003: youh => 'You had selected ',
3004: secs => 'sections.',
3005: plmo => 'Please modify your selections so they include no more than one section.',
3006: mayn => 'may not be used as the name for a section, as it is a reserved word.',
3007: plch => 'Please choose a different section name.',
3008: mnot => 'may not be used as a section name, as it is the name of a course group.',
3009: secn => 'Section names and group names must be distinct. Please choose a different section name.',
3010: );
3011: $setsection_js .= <<"ENDSECCODE";
3012:
3013: function setSections(formname) {
3014: var re1 = /^currsec_/;
3015: var groups = new Array($groupslist);
3016: for (var i=0;i<formname.elements.length;i++) {
3017: var str = formname.elements[i].name;
3018: var checkcurr = str.match(re1);
3019: if (checkcurr != null) {
3020: if ($checkincluded) {
3021: var match = str.split('_');
3022: var role = match[$roleplace];
3023: if (role == 'cc') {
3024: alert("$alerts{'secd'}\\n$alerts{'accr'}");
3025: }
3026: else {
3027: var sections = '';
3028: var numsec = 0;
3029: var sections;
3030: for (var j=0; j<formname.elements[i].length; j++) {
3031: if (formname.elements[i].options[j].selected == true ) {
3032: if (formname.elements[i].options[j].value != "") {
3033: if (numsec == 0) {
3034: if (formname.elements[i].options[j].value != "") {
3035: sections = formname.elements[i].options[j].value;
3036: numsec ++;
3037: }
3038: }
3039: else {
3040: sections = sections + "," + formname.elements[i].options[j].value
3041: numsec ++;
3042: }
3043: }
3044: }
3045: }
3046: if (numsec > 0) {
3047: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
3048: sections = sections + "," + formname.elements[i+1].value;
3049: }
3050: }
3051: else {
3052: sections = formname.elements[i+1].value;
3053: }
3054: var newsecs = formname.elements[i+1].value;
3055: var numsplit;
3056: if (newsecs != null && newsecs != "") {
3057: numsplit = newsecs.split(/,/g);
3058: numsec = numsec + numsplit.length;
3059: }
3060:
3061: if ((role == 'st') && (numsec > 1)) {
3062: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
3063: return;
3064: }
3065: else {
3066: if (numsplit != null) {
3067: for (var j=0; j<numsplit.length; j++) {
3068: if ((numsplit[j] == 'all') ||
3069: (numsplit[j] == 'none')) {
3070: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
3071: return;
3072: }
3073: for (var k=0; k<groups.length; k++) {
3074: if (numsplit[j] == groups[k]) {
3075: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
3076: return;
3077: }
3078: }
3079: }
3080: }
3081: formname.elements[i+2].value = sections;
3082: }
3083: }
3084: }
3085: }
3086: }
3087: $finish
3088: }
3089: ENDSECCODE
3090: return $setsection_js;
3091: }
3092:
3093: 1;
3094:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>