File:
[LON-CAPA] /
loncom /
interface /
lonuserutils.pm
Revision
1.44:
download - view:
text,
annotated -
select for diffs
Sat Jan 5 18:36:26 2008 UTC (16 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
bugs 5661, 5662.
- request for urls to access photos (both thumbnails and full size images) served from library server (via token mechanism), moved to occur during first pass of %userlist.
- eliminates timing problems caused when tokens were being requested as table display was being generated.
1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
4: # $Id: lonuserutils.pm,v 1.44 2008/01/05 18:36:26 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 ($cnum,$cdom) = &get_course_identity($courseid);
50: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
51: my ($tmp) = keys(%roles);
52: # Bail out if we were unable to get the students roles
53: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
54: # Go through the roles looking for enrollment in this course
55: my $result = '';
56: foreach my $course (keys(%roles)) {
57: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
58: # We are in this course
59: my $section=$1;
60: $section='' if ($course eq "/$cdom/$cnum".'_st');
61: if (defined($csec) && $section eq $csec) {
62: $result .= 'ok:';
63: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
64: my (undef,$end,$start)=split(/\_/,$roles{$course});
65: my $now=time;
66: # if this is an active role
67: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
68: my $reply=&Apache::lonnet::modifystudent
69: # dom name id mode pass f m l g
70: ($udom,$unam,'', '', '',undef,undef,undef,undef,
71: $section,time,undef,undef,$desiredhost,'','manual',
72: '',$courseid);
73: $result .= $reply.':';
74: }
75: }
76: }
77: }
78: if ($result eq '') {
79: $result = &mt('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 'author') {
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: $role =~ s/_/\//g;
131: $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
132: $role,$end,$start);
133: }
134: }
135: return ($userresult,$authresult,$roleresult,$idresult);
136: }
137:
138: sub propagate_id_change {
139: my ($uname,$udom,$user) = @_;
140: my (@types,@roles);
141: @types = ('active','future');
142: @roles = ('st');
143: my $idresult;
144: my %roleshash = &Apache::lonnet::get_my_roles($uname,
145: $udom,'userroles',\@types,\@roles);
146: my %args = (
147: one_time => 1,
148: );
149: foreach my $item (keys(%roleshash)) {
150: my ($cnum,$cdom,$role) = split(/:/,$item,-1);
151: my ($start,$end) = split(/:/,$roleshash{$item});
152: if (&Apache::lonnet::is_course($cdom,$cnum)) {
153: my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
154: my %coursehash =
155: &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
156: my $cdesc = $coursehash{'description'};
157: if ($cdesc eq '') {
158: $cdesc = $cdom.'_'.$cnum;
159: }
160: if ($result eq 'ok') {
161: $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'<br />'."\n";
162: } else {
163: $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'<br />'."\n";
164: }
165: }
166: }
167: return $idresult;
168: }
169:
170: sub update_classlist {
171: my ($cdom,$cnum,$udom,$uname,$user) = @_;
172: my ($uid,$classlistentry);
173: my $fullname =
174: &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
175: $user->{'lastname'},$user->{'generation'},
176: 'lastname');
177: my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
178: $cdom,$cnum);
179: my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
180: my $ididx=&Apache::loncoursedata::CL_ID() - 2;
181: my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
182: for (my $i=0; $i<@classinfo; $i++) {
183: if ($i == $ididx) {
184: if (defined($user->{'id'})) {
185: $classlistentry .= $user->{'id'}.':';
186: } else {
187: $classlistentry .= $classinfo[$i].':';
188: }
189: } elsif ($i == $nameidx) {
190: $classlistentry .= $fullname.':';
191: } else {
192: $classlistentry .= $classinfo[$i].':';
193: }
194: }
195: $classlistentry =~ s/:$//;
196: my $reply=&Apache::lonnet::cput('classlist',
197: {"$uname:$udom" => $classlistentry},
198: $cdom,$cnum);
199: if (($reply eq 'ok') || ($reply eq 'delayed')) {
200: return 'ok';
201: } else {
202: return 'error: '.$reply;
203: }
204: }
205:
206:
207: ###############################################################
208: ###############################################################
209: # build a role type and role selection form
210: sub domain_roles_select {
211: # Set up the role type and role selection boxes when in
212: # domain context
213: #
214: # Role types
215: my @roletypes = ('domain','author','course');
216: my %lt = &role_type_names();
217: #
218: # build up the menu information to be passed to
219: # &Apache::loncommon::linked_select_forms
220: my %select_menus;
221: if ($env{'form.roletype'} eq '') {
222: $env{'form.roletype'} = 'domain';
223: }
224: foreach my $roletype (@roletypes) {
225: # set up the text for this domain
226: $select_menus{$roletype}->{'text'}= $lt{$roletype};
227: # we want a choice of 'default' as the default in the second menu
228: if ($env{'form.roletype'} ne '') {
229: $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
230: } else {
231: $select_menus{$roletype}->{'default'} = 'Any';
232: }
233: # Now build up the other items in the second menu
234: my @roles;
235: if ($roletype eq 'domain') {
236: @roles = &domain_roles();
237: } elsif ($roletype eq 'author') {
238: @roles = &construction_space_roles();
239: } else {
240: my $custom = 1;
241: @roles = &course_roles('domain',undef,$custom);
242: }
243: my $order = ['Any',@roles];
244: $select_menus{$roletype}->{'order'} = $order;
245: foreach my $role (@roles) {
246: if ($role eq 'cr') {
247: $select_menus{$roletype}->{'select2'}->{$role} =
248: &mt('Custom role');
249: } else {
250: $select_menus{$roletype}->{'select2'}->{$role} =
251: &Apache::lonnet::plaintext($role);
252: }
253: }
254: $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
255: }
256: my $result = &Apache::loncommon::linked_select_forms
257: ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
258: 'roletype','showrole',\%select_menus,['domain','author','course']);
259: return $result;
260: }
261:
262: ###############################################################
263: ###############################################################
264: sub hidden_input {
265: my ($name,$value) = @_;
266: return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
267: }
268:
269: sub print_upload_manager_header {
270: my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
271: my $javascript;
272: #
273: if (! exists($env{'form.upfile_associate'})) {
274: $env{'form.upfile_associate'} = 'forward';
275: }
276: if ($env{'form.associate'} eq 'Reverse Association') {
277: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
278: $env{'form.upfile_associate'} = 'reverse';
279: } else {
280: $env{'form.upfile_associate'} = 'forward';
281: }
282: }
283: if ($env{'form.upfile_associate'} eq 'reverse') {
284: $javascript=&upload_manager_javascript_reverse_associate();
285: } else {
286: $javascript=&upload_manager_javascript_forward_associate();
287: }
288: #
289: # Deal with restored settings
290: my $password_choice = '';
291: if (exists($env{'form.ipwd_choice'}) &&
292: $env{'form.ipwd_choice'} ne '') {
293: # If a column was specified for password, assume it is for an
294: # internal password. This is a bug waiting to be filed (could be
295: # local or krb auth instead of internal) but I do not have the
296: # time to mess around with this now.
297: $password_choice = 'int';
298: }
299: #
300: my $groupslist;
301: if ($context eq 'course') {
302: $groupslist = &get_groupslist();
303: }
304: my $javascript_validations =
305: &javascript_validations('upload',$krbdefdom,$password_choice,undef,
306: $env{'request.role.domain'},$context,
307: $groupslist);
308: my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
309: $r->print(&mt('Total number of records found in file: <b>[_1]</b>.',$distotal).
310: "<br />\n");
311: $r->print('<div class="LC_left_float"><h3>'.
312: &mt('Identify fields in uploaded list')."</h3>\n");
313: $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");
314: $r->print(&hidden_input('action','upload').
315: &hidden_input('state','got_file').
316: &hidden_input('associate','').
317: &hidden_input('datatoken',$datatoken).
318: &hidden_input('fileupload',$env{'form.fileupload'}).
319: &hidden_input('upfiletype',$env{'form.upfiletype'}).
320: &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
321: $r->print('<br /><input type="button" value="Reverse Association" '.
322: 'name="'.&mt('Reverse Association').'" '.
323: 'onClick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
324: $r->print('<label><input type="checkbox" name="noFirstLine"'.$checked.'/>'.
325: &mt('Ignore First Line').'</label>');
326: $r->print("<br /><br />\n".
327: '<script type="text/javascript" language="Javascript">'."\n".
328: $javascript."\n".$javascript_validations.'</script>');
329: }
330:
331: ###############################################################
332: ###############################################################
333: sub javascript_validations {
334: my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
335: $context,$groupslist)=@_;
336: my %param = (
337: kerb_def_dom => $krbdefdom,
338: curr_authtype => $curr_authtype,
339: );
340: if ($mode eq 'upload') {
341: $param{'formname'} = 'studentform';
342: } elsif ($mode eq 'createcourse') {
343: $param{'formname'} = 'ccrs';
344: } elsif ($mode eq 'modifycourse') {
345: $param{'formname'} = 'cmod';
346: $param{'mode'} = 'modifycourse',
347: $param{'curr_autharg'} = $curr_authfield;
348: }
349:
350: my ($setsection_call,$setsections_js);
351: my $finish = " vf.submit();\n";
352: if ($mode eq 'upload') {
353: if (($context eq 'course') || ($context eq 'domain')) {
354: if ($context eq 'course') {
355: if ($env{'request.course.sec'} eq '') {
356: $setsection_call = 'setSections(document.'.$param{'formname'}.');';
357: $setsections_js =
358: &setsections_javascript($param{'formname'},$groupslist,
359: $mode);
360: } else {
361: $setsection_call = "'ok'";
362: }
363: } elsif ($context eq 'domain') {
364: $setsection_call = 'setCourse()';
365: $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context);
366: }
367: $finish = " var checkSec = $setsection_call\n".
368: " if (checkSec == 'ok') {\n".
369: " vf.submit();\n".
370: " }\n";
371: }
372: }
373: my $authheader = &Apache::loncommon::authform_header(%param);
374:
375: my %alert = &Apache::lonlocal::texthash
376: (username => 'You need to specify the username field.',
377: authen => 'You must choose an authentication type.',
378: krb => 'You need to specify the Kerberos domain.',
379: ipass => 'You need to specify the initial password.',
380: name => 'The optional name field was not specified.',
381: snum => 'The optional ID number field was not specified.',
382: section => 'The optional section field was not specified.',
383: email => 'The optional email address field was not specified.',
384: role => 'The optional role field was not specified.',
385: continue => 'Continue adding users?',
386: );
387: my $function_name = <<"END";
388: $setsections_js
389:
390: function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
391: END
392: my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
393: my $auth_checks;
394: if ($mode eq 'createcourse') {
395: $auth_checks .= (<<END);
396: if (vf.autoadds[0].checked == true) {
397: if (current.radiovalue == null || current.radiovalue == 'nochange') {
398: alert('$alert{'authen'}');
399: return;
400: }
401: }
402: END
403: } else {
404: $auth_checks .= (<<END);
405: var foundatype=0;
406: if (founduname==0) {
407: alert('$alert{'username'}');
408: return;
409: }
410:
411: END
412: if ($authnum > 1) {
413: $auth_checks .= (<<END);
414: if (current.radiovalue == null || current.radiovalue == '' || current.radiovalue == 'nochange') {
415: // They did not check any of the login radiobuttons.
416: alert('$alert{'authen'}');
417: return;
418: }
419: END
420: }
421: }
422: if ($mode eq 'createcourse') {
423: $auth_checks .= "
424: if ( (vf.autoadds[0].checked == true) &&
425: (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') ) {
426: ";
427: } elsif ($mode eq 'modifycourse') {
428: $auth_checks .= "
429: if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
430: ";
431: }
432: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
433: $auth_checks .= (<<END);
434: var alertmsg = '';
435: switch (current.radiovalue) {
436: case 'krb':
437: alertmsg = '$alert{'krb'}';
438: break;
439: default:
440: alertmsg = '';
441: }
442: if (alertmsg != '') {
443: alert(alertmsg);
444: return;
445: }
446: }
447: END
448: } else {
449: $auth_checks .= (<<END);
450: foundatype=1;
451: if (current.argfield == null || current.argfield == '') {
452: var alertmsg = '';
453: switch (current.radiovalue) {
454: case 'krb':
455: alertmsg = '$alert{'krb'}';
456: break;
457: case 'loc':
458: case 'fsys':
459: alertmsg = '$alert{'ipass'}';
460: break;
461: case 'fsys':
462: alertmsg = '';
463: break;
464: default:
465: alertmsg = '';
466: }
467: if (alertmsg != '') {
468: alert(alertmsg);
469: return;
470: }
471: }
472: END
473: }
474: my $section_checks;
475: my $optional_checks = '';
476: if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
477: $optional_checks = (<<END);
478: vf.submit();
479: }
480: END
481: } else {
482: $section_checks = §ion_check_js();
483: $optional_checks = (<<END);
484: var message='';
485: if (foundname==0) {
486: message='$alert{'name'}';
487: }
488: if (foundid==0) {
489: if (message!='') {
490: message+='\\n';
491: }
492: message+='$alert{'snum'}';
493: }
494: if (foundsec==0) {
495: if (message!='') {
496: message+='\\n';
497: }
498: }
499: if (foundemail==0) {
500: if (message!='') {
501: message+='\\n';
502: }
503: message+='$alert{'email'}';
504: }
505: if (message!='') {
506: message+= '\\n$alert{'continue'}';
507: if (confirm(message)) {
508: vf.state.value='enrolling';
509: $finish
510: }
511: } else {
512: vf.state.value='enrolling';
513: $finish
514: }
515: }
516: END
517: }
518: my $result = $function_name.$auth_checks.$optional_checks."\n".
519: $section_checks.$authheader;
520: return $result;
521: }
522: ###############################################################
523: ###############################################################
524: sub upload_manager_javascript_forward_associate {
525: return(<<ENDPICK);
526: function verify(vf,sec_caller) {
527: var founduname=0;
528: var foundpwd=0;
529: var foundname=0;
530: var foundid=0;
531: var foundsec=0;
532: var foundemail=0;
533: var foundrole=0;
534: var tw;
535: for (i=0;i<=vf.nfields.value;i++) {
536: tw=eval('vf.f'+i+'.selectedIndex');
537: if (tw==1) { founduname=1; }
538: if ((tw>=2) && (tw<=6)) { foundname=1; }
539: if (tw==7) { foundid=1; }
540: if (tw==8) { foundsec=1; }
541: if (tw==9) { foundpwd=1; }
542: if (tw==10) { foundemail=1; }
543: if (tw==11) { foundrole=1; }
544: }
545: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole);
546: }
547:
548: //
549: // vf = this.form
550: // tf = column number
551: //
552: // values of nw
553: //
554: // 0 = none
555: // 1 = username
556: // 2 = names (lastname, firstnames)
557: // 3 = fname (firstname)
558: // 4 = mname (middlename)
559: // 5 = lname (lastname)
560: // 6 = gen (generation)
561: // 7 = id
562: // 8 = section
563: // 9 = ipwd (password)
564: // 10 = email address
565: // 11 = role
566:
567: function flip(vf,tf) {
568: var nw=eval('vf.f'+tf+'.selectedIndex');
569: var i;
570: // make sure no other columns are labeled the same as this one
571: for (i=0;i<=vf.nfields.value;i++) {
572: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
573: eval('vf.f'+i+'.selectedIndex=0;')
574: }
575: }
576: // If we set this to 'lastname, firstnames', clear out all the ones
577: // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
578: if (nw==2) {
579: for (i=0;i<=vf.nfields.value;i++) {
580: if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
581: (eval('vf.f'+i+'.selectedIndex')<=6)) {
582: eval('vf.f'+i+'.selectedIndex=0;')
583: }
584: }
585: }
586: // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
587: // clear out any that are set to 'lastname, firstnames' (2)
588: if ((nw>=3) && (nw<=6)) {
589: for (i=0;i<=vf.nfields.value;i++) {
590: if (eval('vf.f'+i+'.selectedIndex')==2) {
591: eval('vf.f'+i+'.selectedIndex=0;')
592: }
593: }
594: }
595: // If we set the password, make the password form below correspond to
596: // the new value.
597: if (nw==9) {
598: changed_radio('int',document.studentform);
599: set_auth_radio_buttons('int',document.studentform);
600: vf.intarg.value='';
601: vf.krbarg.value='';
602: vf.locarg.value='';
603: }
604: }
605:
606: function clearpwd(vf) {
607: var i;
608: for (i=0;i<=vf.nfields.value;i++) {
609: if (eval('vf.f'+i+'.selectedIndex')==9) {
610: eval('vf.f'+i+'.selectedIndex=0;')
611: }
612: }
613: }
614:
615: ENDPICK
616: }
617:
618: ###############################################################
619: ###############################################################
620: sub upload_manager_javascript_reverse_associate {
621: return(<<ENDPICK);
622: function verify(vf,sec_caller) {
623: var founduname=0;
624: var foundpwd=0;
625: var foundname=0;
626: var foundid=0;
627: var foundsec=0;
628: var foundrole=0;
629: var tw;
630: for (i=0;i<=vf.nfields.value;i++) {
631: tw=eval('vf.f'+i+'.selectedIndex');
632: if (i==0 && tw!=0) { founduname=1; }
633: if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
634: if (i==6 && tw!=0) { foundid=1; }
635: if (i==7 && tw!=0) { foundsec=1; }
636: if (i==8 && tw!=0) { foundpwd=1; }
637: if (i==9 && tw!=0) { foundrole=1; }
638: }
639: verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole);
640: }
641:
642: function flip(vf,tf) {
643: var nw=eval('vf.f'+tf+'.selectedIndex');
644: var i;
645: // picked the all one name field, reset the other name ones to blank
646: if (tf==1 && nw!=0) {
647: for (i=2;i<=5;i++) {
648: eval('vf.f'+i+'.selectedIndex=0;')
649: }
650: }
651: //picked one of the piecewise name fields, reset the all in
652: //one field to blank
653: if ((tf>=2) && (tf<=5) && (nw!=0)) {
654: eval('vf.f1.selectedIndex=0;')
655: }
656: // intial password specified, pick internal authentication
657: if (tf==8 && nw!=0) {
658: changed_radio('int',document.studentform);
659: set_auth_radio_buttons('int',document.studentform);
660: vf.krbarg.value='';
661: vf.intarg.value='';
662: vf.locarg.value='';
663: }
664: }
665:
666: function clearpwd(vf) {
667: var i;
668: if (eval('vf.f8.selectedIndex')!=0) {
669: eval('vf.f8.selectedIndex=0;')
670: }
671: }
672: ENDPICK
673: }
674:
675: ###############################################################
676: ###############################################################
677: sub print_upload_manager_footer {
678: my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission) = @_;
679: my $form = 'document.studentform';
680: my $formname = 'studentform';
681: my ($krbdef,$krbdefdom) =
682: &Apache::loncommon::get_kerberos_defaults($defdom);
683: my %param = ( formname => $form,
684: kerb_def_dom => $krbdefdom,
685: kerb_def_auth => $krbdef
686: );
687: if (exists($env{'form.ipwd_choice'}) &&
688: defined($env{'form.ipwd_choice'}) &&
689: $env{'form.ipwd_choice'} ne '') {
690: $param{'curr_authtype'} = 'int';
691: }
692: my $krbform = &Apache::loncommon::authform_kerberos(%param);
693: my $intform = &Apache::loncommon::authform_internal(%param);
694: my $locform = &Apache::loncommon::authform_local(%param);
695: my $date_table = &date_setting_table(undef,undef,$context,undef,
696: $formname,$permission);
697: my $Str = "\n".'<div class="LC_left_float">';
698: $Str .= &hidden_input('nfields',$i);
699: $Str .= &hidden_input('keyfields',$keyfields);
700: $Str .= "<h3>".&mt('Login Type')."</h3>\n";
701: if ($context eq 'domain') {
702: $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>';
703: } else {
704: $Str .= "<p>\n".
705: &mt('Note: this will not take effect if the user already exists').
706: &Apache::loncommon::help_open_topic('Auth_Options').
707: "</p>\n";
708: }
709: $Str .= &set_login($defdom,$krbform,$intform,$locform);
710: my ($home_server_pick,$numlib) =
711: &Apache::loncommon::home_server_form_item($defdom,'lcserver',
712: 'default','hide');
713: if ($numlib > 1) {
714: $Str .= '<h3>'.&mt('LON-CAPA Home Server for New Users')."</h3>\n".
715: &mt('LON-CAPA domain: [_1] with home server: [_2]',$defdom,
716: $home_server_pick).'<br />';
717: } else {
718: $Str .= $home_server_pick;
719: }
720: $Str .= '<h3>'.&mt('Starting and Ending Dates').
721: "</h3>\n";
722: $Str .= "<p>\n".$date_table."</p>\n";
723: if ($context eq 'domain') {
724: $Str .= '<h3>'.&mt('Settings for assigning roles:').'</h3>'."\n".
725: &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>';
726: }
727: if ($context eq 'author') {
728: $Str .= '<h3>'.&mt('Default role')."</h3>\n".
729: &mt('Choose the role to assign to users without a value specified in the uploaded file');
730: } elsif ($context eq 'course') {
731: $Str .= '<h3>'.&mt('Default role and section')."</h3>\n".
732: &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
733: } else {
734: $Str .= '<br /><br /><b>'.&mt('Default role and/or section(s)')."</b><br />\n".
735: &mt('Role and/or section(s) for users without values specified in the uploaded file.');
736: }
737: $Str .= '<br />';
738: if (($context eq 'domain') || ($context eq 'author')) {
739: my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
740: if ($context eq 'domain') {
741: $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;
742: } elsif ($context eq 'author') {
743: $Str .= $options;
744: }
745: } else {
746: my ($cnum,$cdom) = &get_course_identity();
747: my $rowtitle = &mt('section');
748: my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,
749: $permission,$context,'upload');
750: $Str .= $secbox."<h3>".&mt('Full Update')."</h3>\n".
751: '<p><label><input type="checkbox" name="fullup" value="yes">'.
752: ' '.&mt('Display students with current/future access who are not in the uploaded file.').'</label><br />'.&mt('Students selected from this list can be dropped.').'</p>'."\n";
753: }
754: if ($context eq 'course' || $context eq 'domain') {
755: $Str .= &forceid_change($context);
756: }
757: $Str .= '</div><div class="LC_clear_float_footer"><br /><input type="button"'.
758: 'onClick="javascript:verify(this.form,this.form.csec)" '.
759: 'value="Update Users" />'."<br />\n";
760: if ($context eq 'course') {
761: $Str .= &mt('Note: for large courses, this operation may be time '.
762: 'consuming');
763: }
764: $Str .= '</div>';
765: $r->print($Str);
766: return;
767: }
768:
769: sub forceid_change {
770: my ($context) = @_;
771: my $output =
772: "<h3>".&mt('ID/Student Number')."</h3>\n".
773: "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">'.
774: &mt('Disable ID/Student Number Safeguard and Force Change '.
775: 'of Conflicting IDs').'</label><br />'."\n".
776: &mt('(only do if you know what you are doing.)')."\n";
777: if ($context eq 'domain') {
778: $output .= '<br /><label><input type="checkbox" name="recurseid"'.
779: ' value="yes">'.
780: &mt('Update ID/Student Number in courses in which user is Active/Future student,<br />(if forcing change).').
781: '</label>'."\n";
782: }
783: $output .= '</p>';
784: return $output;
785: }
786:
787: ###############################################################
788: ###############################################################
789: sub print_upload_manager_form {
790: my ($r,$context,$permission) = @_;
791: my $firstLine;
792: my $datatoken;
793: if (!$env{'form.datatoken'}) {
794: $datatoken=&Apache::loncommon::upfile_store($r);
795: } else {
796: $datatoken=$env{'form.datatoken'};
797: &Apache::loncommon::load_tmp_file($r);
798: }
799: my @records=&Apache::loncommon::upfile_record_sep();
800: if($env{'form.noFirstLine'}){
801: $firstLine=shift(@records);
802: }
803: my $total=$#records;
804: my $distotal=$total+1;
805: my $today=time;
806: my $halfyear=$today+15552000;
807: #
808: # Restore memorized settings
809: my $col_setting_names = { 'username_choice' => 'scalar', # column settings
810: 'names_choice' => 'scalar',
811: 'fname_choice' => 'scalar',
812: 'mname_choice' => 'scalar',
813: 'lname_choice' => 'scalar',
814: 'gen_choice' => 'scalar',
815: 'id_choice' => 'scalar',
816: 'sec_choice' => 'scalar',
817: 'ipwd_choice' => 'scalar',
818: 'email_choice' => 'scalar',
819: 'role_choice' => 'scalar',
820: };
821: my $defdom = $env{'request.role.domain'};
822: if ($context eq 'course') {
823: &Apache::loncommon::restore_course_settings('enrollment_upload',
824: $col_setting_names);
825: } else {
826: &Apache::loncommon::restore_settings($context,'user_upload',
827: $col_setting_names);
828: }
829: #
830: # Determine kerberos parameters as appropriate
831: my ($krbdef,$krbdefdom) =
832: &Apache::loncommon::get_kerberos_defaults($defdom);
833: #
834: &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
835: $permission);
836: my $i;
837: my $keyfields;
838: if ($total>=0) {
839: my @field=
840: (['username',&mt('Username'), $env{'form.username_choice'}],
841: ['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
842: ['fname',&mt('First Name'), $env{'form.fname_choice'}],
843: ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
844: ['lname',&mt('Last Name'), $env{'form.lname_choice'}],
845: ['gen', &mt('Generation'), $env{'form.gen_choice'}],
846: ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
847: ['sec', &mt('Section'), $env{'form.sec_choice'}],
848: ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
849: ['email',&mt('E-mail Address'), $env{'form.email_choice'}],
850: ['role',&mt('Role'), $env{'form.role_choice'}]);
851: if ($env{'form.upfile_associate'} eq 'reverse') {
852: &Apache::loncommon::csv_print_samples($r,\@records);
853: $i=&Apache::loncommon::csv_print_select_table($r,\@records,
854: \@field);
855: foreach (@field) {
856: $keyfields.=$_->[0].',';
857: }
858: chop($keyfields);
859: } else {
860: unshift(@field,['none','']);
861: $i=&Apache::loncommon::csv_samples_select_table($r,\@records,
862: \@field);
863: my %sone=&Apache::loncommon::record_sep($records[0]);
864: $keyfields=join(',',sort(keys(%sone)));
865: }
866: }
867: $r->print('</div>');
868: &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
869: $context,$permission);
870: }
871:
872: sub setup_date_selectors {
873: my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
874: if ($formname eq '') {
875: $formname = 'studentform';
876: }
877: if (! defined($starttime)) {
878: $starttime = time;
879: unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
880: if (exists($env{'course.'.$env{'request.course.id'}.
881: '.default_enrollment_start_date'})) {
882: $starttime = $env{'course.'.$env{'request.course.id'}.
883: '.default_enrollment_start_date'};
884: }
885: }
886: }
887: if (! defined($endtime)) {
888: $endtime = time+(6*30*24*60*60); # 6 months from now, approx
889: unless ($mode eq 'createcourse') {
890: if (exists($env{'course.'.$env{'request.course.id'}.
891: '.default_enrollment_end_date'})) {
892: $endtime = $env{'course.'.$env{'request.course.id'}.
893: '.default_enrollment_end_date'};
894: }
895: }
896: }
897:
898: my $startdateform =
899: &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
900: undef,undef,undef,undef,undef,undef,undef,$nolink);
901:
902: my $enddateform =
903: &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
904: undef,undef,undef,undef,undef,undef,undef,$nolink);
905:
906: if ($mode eq 'create_enrolldates') {
907: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
908: 'startenroll',
909: $starttime);
910: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
911: 'endenroll',
912: $endtime);
913: }
914: if ($mode eq 'create_defaultdates') {
915: $startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
916: 'startaccess',
917: $starttime);
918: $enddateform = &Apache::lonhtmlcommon::date_setter('ccrs',
919: 'endaccess',
920: $endtime);
921: }
922: return ($startdateform,$enddateform);
923: }
924:
925:
926: sub get_dates_from_form {
927: my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
928: my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
929: if ($env{'form.no_end_date'}) {
930: $enddate = 0;
931: }
932: return ($startdate,$enddate);
933: }
934:
935: sub date_setting_table {
936: my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_;
937: my $nolink;
938: if ($bulkaction) {
939: $nolink = 1;
940: }
941: my ($startform,$endform) =
942: &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
943: my $dateDefault;
944: if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
945: $dateDefault = ' ';
946: } elsif ($mode ne 'author' && $mode ne 'domain') {
947: if (($bulkaction eq 'reenable') ||
948: ($bulkaction eq 'activate') ||
949: ($bulkaction eq 'chgdates') ||
950: ($env{'form.action'} eq 'upload')) {
951: if ($env{'request.course.sec'} eq '') {
952: $dateDefault = '<span class="LC_nobreak">'.
953: '<label><input type="checkbox" name="makedatesdefault" value="1" /> '.
954: &mt('make these dates the default access dates for future student enrollment').
955: '</label></span>';
956: }
957: }
958: }
959: my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
960: if (defined($endtime) && $endtime == 0) {
961: $perpetual .= ' checked';
962: }
963: $perpetual.= ' /> '.&mt('no ending date').'</label></span>';
964: if ($mode eq 'create_enrolldates') {
965: $perpetual = ' ';
966: }
967: my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
968: $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
969: 'LC_oddrow_value')."\n".
970: $startform."\n".
971: &Apache::lonhtmlcommon::row_closure(1).
972: &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
973: 'LC_oddrow_value')."\n".
974: $endform.' '.$perpetual.
975: &Apache::lonhtmlcommon::row_closure(1).
976: &Apache::lonhtmlcommon::end_pick_box();
977: if ($dateDefault) {
978: $result .= $dateDefault.'<br />'."\n";
979: }
980: return $result;
981: }
982:
983: sub make_dates_default {
984: my ($startdate,$enddate,$context) = @_;
985: my $result = '';
986: if ($context eq 'course') {
987: my ($cnum,$cdom) = &get_course_identity();
988: my $put_result = &Apache::lonnet::put('environment',
989: {'default_enrollment_start_date'=>$startdate,
990: 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
991: if ($put_result eq 'ok') {
992: $result .= &mt('Set default start and end access dates for course.').
993: '<br />'."\n";
994: #
995: # Refresh the course environment
996: &Apache::lonnet::coursedescription($env{'request.course.id'},
997: {'freshen_cache' => 1});
998: } else {
999: $result .= &mt('Unable to set default access dates for course.').":".$put_result.
1000: '<br />';
1001: }
1002: }
1003: return $result;
1004: }
1005:
1006: sub default_role_selector {
1007: my ($context,$checkpriv) = @_;
1008: my %customroles;
1009: my ($options,$coursepick,$cb_jscript);
1010: if ($context ne 'author') {
1011: %customroles = &my_custom_roles();
1012: }
1013:
1014: my %lt=&Apache::lonlocal::texthash(
1015: 'rol' => "Role",
1016: 'grs' => "Section",
1017: 'exs' => "Existing sections",
1018: 'new' => "New section",
1019: );
1020: $options = '<select name="defaultrole">'."\n".
1021: ' <option value="">'.&mt('Please select').'</option>'."\n";
1022: if ($context eq 'course') {
1023: $options .= &default_course_roles($context,$checkpriv,%customroles);
1024: } elsif ($context eq 'author') {
1025: my @roles = &construction_space_roles($checkpriv);
1026: foreach my $role (@roles) {
1027: my $plrole=&Apache::lonnet::plaintext($role);
1028: $options .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1029: }
1030: } elsif ($context eq 'domain') {
1031: my @roles = &domain_roles($checkpriv);
1032: foreach my $role (@roles) {
1033: my $plrole=&Apache::lonnet::plaintext($role);
1034: $options .= ' <option value="'.$role.'">'.$plrole.'</option>';
1035: }
1036: my $courseform = &Apache::loncommon::selectcourse_link
1037: ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
1038: $cb_jscript =
1039: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
1040: $coursepick = &Apache::loncommon::start_data_table().
1041: &Apache::loncommon::start_data_table_header_row().
1042: '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
1043: '<th>'.$lt{'grs'}.'</th>'.
1044: &Apache::loncommon::end_data_table_header_row().
1045: &Apache::loncommon::start_data_table_row()."\n".
1046: '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
1047: '<td><select name="courserole">'."\n".
1048: &default_course_roles($context,$checkpriv,%customroles)."\n".
1049: '</select></td><td>'.
1050: '<table class="LC_createuser">'.
1051: '<tr class="LC_section_row"><td valign"top">'.
1052: $lt{'exs'}.'<br /><select name="currsec">'.
1053: ' <option value=""><--'.&mt('Pick course first').
1054: '</select></td>'.
1055: '<td> </td>'.
1056: '<td valign="top">'.$lt{'new'}.'<br />'.
1057: '<input type="text" name="newsec" value="" size="5" />'.
1058: '<input type="hidden" name="groups" value="" />'.
1059: '<input type="hidden" name="sections" value="" />'.
1060: '<input type="hidden" name="origdom" value="'.
1061: $env{'request.role.domain'}.'" />'.
1062: '<input type="hidden" name="dccourse" value="" />'.
1063: '<input type="hidden" name="dcdomain" value="" />'.
1064: '</td></tr></table></td>'.
1065: &Apache::loncommon::end_data_table_row().
1066: &Apache::loncommon::end_data_table()."\n";
1067: }
1068: $options .= '</select>';
1069: return ($options,$cb_jscript,$coursepick);
1070: }
1071:
1072: sub default_course_roles {
1073: my ($context,$checkpriv,%customroles) = @_;
1074: my $output;
1075: my $custom = 1;
1076: my @roles = &course_roles($context,$checkpriv,$custom);
1077: foreach my $role (@roles) {
1078: if ($role ne 'cr') {
1079: my $plrole=&Apache::lonnet::plaintext($role);
1080: $output .= ' <option value="'.$role.'">'.$plrole.'</option>';
1081: }
1082: }
1083: if (keys(%customroles) > 0) {
1084: if (grep(/^cr$/,@roles)) {
1085: foreach my $cust (sort(keys(%customroles))) {
1086: my $custrole='cr_'.$env{'user.domain'}.
1087: '_'.$env{'user.name'}.'_'.$cust;
1088: $output .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1089: }
1090: }
1091: }
1092: return $output;
1093: }
1094:
1095: sub construction_space_roles {
1096: my ($checkpriv) = @_;
1097: my @allroles = &roles_by_context('author');
1098: my @roles;
1099: if ($checkpriv) {
1100: foreach my $role (@allroles) {
1101: if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
1102: push(@roles,$role);
1103: }
1104: }
1105: return @roles;
1106: } else {
1107: return @allroles;
1108: }
1109: }
1110:
1111: sub domain_roles {
1112: my ($checkpriv) = @_;
1113: my @allroles = &roles_by_context('domain');
1114: my @roles;
1115: if ($checkpriv) {
1116: foreach my $role (@allroles) {
1117: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
1118: push(@roles,$role);
1119: }
1120: }
1121: return @roles;
1122: } else {
1123: return @allroles;
1124: }
1125: }
1126:
1127: sub course_roles {
1128: my ($context,$checkpriv,$custom) = @_;
1129: my @allroles = &roles_by_context('course',$custom);
1130: my @roles;
1131: if ($context eq 'domain') {
1132: @roles = @allroles;
1133: } elsif ($context eq 'course') {
1134: if ($env{'request.course.id'}) {
1135: if ($checkpriv) {
1136: foreach my $role (@allroles) {
1137: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
1138: push(@roles,$role);
1139: } else {
1140: if ($role ne 'cc' && $env{'request.course.sec'} ne '') {
1141: if (&Apache::lonnet::allowed('c'.$role,
1142: $env{'request.course.id'}.'/'.
1143: $env{'request.course.sec'})) {
1144: push(@roles,$role);
1145: }
1146: }
1147: }
1148: }
1149: } else {
1150: @roles = @allroles;
1151: }
1152: }
1153: }
1154: return @roles;
1155: }
1156:
1157: sub curr_role_permissions {
1158: my ($context,$setting,$checkpriv) = @_;
1159: my $custom = 1;
1160: my @roles;
1161: if ($context eq 'author') {
1162: @roles = &construction_space_roles($checkpriv);
1163: } elsif ($context eq 'domain') {
1164: if ($setting eq 'course') {
1165: @roles = &course_roles($context,$checkpriv,$custom);
1166: } else {
1167: @roles = &domain_roles($checkpriv);
1168: }
1169: } elsif ($context eq 'course') {
1170: @roles = &course_roles($context,$checkpriv,$custom);
1171: }
1172: return @roles;
1173: }
1174:
1175: # ======================================================= Existing Custom Roles
1176:
1177: sub my_custom_roles {
1178: my %returnhash=();
1179: my %rolehash=&Apache::lonnet::dump('roles');
1180: foreach my $key (keys %rolehash) {
1181: if ($key=~/^rolesdef\_(\w+)$/) {
1182: $returnhash{$1}=$1;
1183: }
1184: }
1185: return %returnhash;
1186: }
1187:
1188: sub print_userlist {
1189: my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
1190: $idlist,$idlist_titles) = @_;
1191: my $format = $env{'form.output'};
1192: if (! exists($env{'form.sortby'})) {
1193: $env{'form.sortby'} = 'username';
1194: }
1195: if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1196: $env{'form.Status'} = 'Active';
1197: }
1198: my $status_select = &Apache::lonhtmlcommon::StatusOptions
1199: ($env{'form.Status'});
1200:
1201: if ($env{'form.showrole'} eq '') {
1202: if ($context eq 'course') {
1203: $env{'form.showrole'} = 'st';
1204: } else {
1205: $env{'form.showrole'} = 'Any';
1206: }
1207: }
1208: if (! defined($env{'form.output'}) ||
1209: $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
1210: $env{'form.output'} = 'html';
1211: }
1212:
1213: my @statuses;
1214: if ($env{'form.Status'} eq 'Any') {
1215: @statuses = ('previous','active','future');
1216: } elsif ($env{'form.Status'} eq 'Expired') {
1217: @statuses = ('previous');
1218: } elsif ($env{'form.Status'} eq 'Active') {
1219: @statuses = ('active');
1220: } elsif ($env{'form.Status'} eq 'Future') {
1221: @statuses = ('future');
1222: }
1223:
1224: # if ($context eq 'course') {
1225: # $r->print(&display_adv_courseroles());
1226: # }
1227: #
1228: # Interface output
1229: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
1230: '<input type="hidden" name="action" value="'.
1231: $env{'form.action'}.'" />');
1232: $r->print("<p>\n");
1233: if ($env{'form.action'} ne 'modifystudent') {
1234: my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
1235: 'excel' => "Excel",
1236: 'html' => 'HTML');
1237: my $output_selector = '<select size="1" name="output" >';
1238: foreach my $outputformat ('html','csv','excel') {
1239: my $option = '<option value="'.$outputformat.'" ';
1240: if ($outputformat eq $env{'form.output'}) {
1241: $option .= 'selected ';
1242: }
1243: $option .='>'.$lt{$outputformat}.'</option>';
1244: $output_selector .= "\n".$option;
1245: }
1246: $output_selector .= '</select>';
1247: $r->print('<label>'.&mt('Output Format: [_1]',$output_selector).'</label>'.(' 'x3));
1248: }
1249: $r->print('<label>'.&mt('User Status: [_1]',$status_select).'</label>'.(' 'x3)."\n");
1250: my $roleselected = '';
1251: if ($env{'form.showrole'} eq 'Any') {
1252: $roleselected = ' selected="selected" ';
1253: }
1254: my ($role_select,$cnum,$cdom);
1255: if ($context eq 'domain') {
1256: $role_select = &domain_roles_select();
1257: $r->print('<label>'.&mt('Role Type: [_1]',$role_select).'</label>');
1258: } else {
1259: $role_select = '<select name="showrole">'."\n".
1260: '<option value="Any" '.$roleselected.'>'.
1261: &mt('Any role').'</option>';
1262: my @poss_roles = &curr_role_permissions($context);
1263: foreach my $role (@poss_roles) {
1264: $roleselected = '';
1265: if ($role eq $env{'form.showrole'}) {
1266: $roleselected = ' selected="selected" ';
1267: }
1268: my $plrole;
1269: if ($role eq 'cr') {
1270: $plrole = &mt('Custom role');
1271: } else {
1272: $plrole=&Apache::lonnet::plaintext($role);
1273: }
1274: $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
1275: }
1276: $role_select .= '</select>';
1277: $r->print('<label>'.&mt('Role: [_1]',$role_select).'</label>');
1278: if ($context eq 'course') {
1279: ($cnum,$cdom) = &get_course_identity();
1280: $r->print(§ion_group_filter($cnum,$cdom));
1281: }
1282: }
1283: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1284: $r->print(' '.&list_submit_button(&mt('Update Display')).
1285: "\n</p>\n");
1286: }
1287: my ($indexhash,$keylist) = &make_keylist_array();
1288: my (%userlist,%userinfo);
1289: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
1290: my $courseform =
1291: &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
1292: $codetitles,$idlist,$idlist_titles);
1293: $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
1294: &Apache::lonhtmlcommon::start_pick_box()."\n".
1295: &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
1296: 'LC_oddrow_value')."\n".
1297: $courseform."\n".
1298: &Apache::lonhtmlcommon::row_closure(1).
1299: &Apache::lonhtmlcommon::end_pick_box().'</p>'.
1300: '<p>'.&list_submit_button(&mt('Update Display')).
1301: "\n".'</p><span class="LC_warning">'.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').'</span>'."\n");
1302: if ($env{'form.coursepick'}) {
1303: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1304: }
1305: } else {
1306: $r->print('<hr />'.&mt('Searching').' ...<br /> <br />');
1307: }
1308: $r->rflush();
1309: if ($context eq 'course') {
1310: my $classlist = &Apache::loncoursedata::get_classlist();
1311: %userlist = %{$classlist};
1312: if ($env{'form.showrole'} ne 'st') {
1313: my $showroles;
1314: if ($env{'form.showrole'} ne 'Any') {
1315: $showroles = [$env{'form.showrole'}];
1316: } else {
1317: $showroles = undef;
1318: }
1319: my $withsec = 1;
1320: my $hidepriv = 1;
1321: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
1322: \@statuses,$showroles,undef,$withsec,$hidepriv);
1323: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1324: \%advrolehash,$permission);
1325: }
1326: } else {
1327: my (%cstr_roles,%dom_roles);
1328: if ($context eq 'author') {
1329: # List co-authors and assistant co-authors
1330: my @possroles = &roles_by_context($context);
1331: %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
1332: \@statuses,\@possroles);
1333: &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
1334: \%cstr_roles,$permission);
1335: } elsif ($context eq 'domain') {
1336: if ($env{'form.roletype'} eq 'domain') {
1337: %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
1338: foreach my $key (keys(%dom_roles)) {
1339: if (ref($dom_roles{$key}) eq 'HASH') {
1340: &gather_userinfo($context,$format,\%userlist,$indexhash,
1341: \%userinfo,$dom_roles{$key},$permission);
1342: }
1343: }
1344: } elsif ($env{'form.roletype'} eq 'author') {
1345: my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
1346: my %coauthors;
1347: foreach my $key (keys(%dom_roles)) {
1348: if (ref($dom_roles{$key}) eq 'HASH') {
1349: if ($env{'form.showrole'} eq 'au') {
1350: &gather_userinfo($context,$format,\%userlist,$indexhash,
1351: \%userinfo,$dom_roles{$key},$permission);
1352: } else {
1353: my @possroles;
1354: if ($env{'form.showrole'} eq 'Any') {
1355: @possroles = &roles_by_context('author');
1356: } else {
1357: @possroles = ($env{'form.showrole'});
1358: }
1359: foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
1360: my ($role,$authorname,$authordom) = split(/:/,$author,-1);
1361: my $extent = '/'.$authordom.'/'.$authorname;
1362: %{$coauthors{$extent}} =
1363: &Apache::lonnet::get_my_roles($authorname,
1364: $authordom,undef,\@statuses,\@possroles);
1365: }
1366: &gather_userinfo($context,$format,\%userlist,
1367: $indexhash,\%userinfo,\%coauthors,$permission);
1368: }
1369: }
1370: }
1371: } elsif ($env{'form.roletype'} eq 'course') {
1372: if ($env{'form.coursepick'}) {
1373: my %courses = &process_coursepick();
1374: my %allusers;
1375: my $hidepriv = 1;
1376: foreach my $cid (keys(%courses)) {
1377: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
1378: next if ($cnum eq '' || $cdom eq '');
1379: my $custom = 1;
1380: my (@roles,@sections,%access,%users,%userdata,
1381: %statushash);
1382: if ($env{'form.showrole'} eq 'Any') {
1383: @roles = &course_roles($context,undef,$custom);
1384: } else {
1385: @roles = ($env{'form.showrole'});
1386: }
1387: foreach my $role (@roles) {
1388: %{$users{$role}} = ();
1389: }
1390: foreach my $type (@statuses) {
1391: $access{$type} = $type;
1392: }
1393: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
1394: foreach my $user (keys(%userdata)) {
1395: next if (ref($userinfo{$user}) eq 'HASH');
1396: foreach my $item ('fullname','id') {
1397: $userinfo{$user}{$item} = $userdata{$user}[$indexhash->{$item}];
1398: }
1399: }
1400: foreach my $role (keys(%users)) {
1401: foreach my $user (keys(%{$users{$role}})) {
1402: my $uniqid = $user.':'.$role;
1403: $allusers{$uniqid}{$cid} = { desc => $cdesc,
1404: secs => $statushash{$user}{$role},
1405: };
1406: }
1407: }
1408: }
1409: &gather_userinfo($context,$format,\%userlist,$indexhash,
1410: \%userinfo,\%allusers,$permission);
1411: } else {
1412: $r->print('<input type="hidden" name="phase" value="'.
1413: $env{'form.phase'}.'" /></form>');
1414: return;
1415: }
1416: }
1417: }
1418: }
1419: if (keys(%userlist) == 0) {
1420: if ($context eq 'author') {
1421: $r->print(&mt('There are no co-authors to display.')."\n");
1422: } elsif ($context eq 'domain') {
1423: if ($env{'form.roletype'} eq 'domain') {
1424: $r->print(&mt('There are no users with domain roles to display.')."\n");
1425: } elsif ($env{'form.roletype'} eq 'author') {
1426: $r->print(&mt('There are no authors or co-authors to display.')."\n");
1427: } elsif ($env{'form.roletype'} eq 'course') {
1428: $r->print(&mt('There are no course users to display')."\n");
1429: }
1430: } elsif ($context eq 'course') {
1431: $r->print(&mt('There are no course users to display.')."\n");
1432: }
1433: } else {
1434: # Print out the available choices
1435: my $usercount;
1436: if ($env{'form.action'} eq 'modifystudent') {
1437: ($usercount) = &show_users_list($r,$context,'view',$permission,
1438: $env{'form.Status'},\%userlist,$keylist);
1439: } else {
1440: ($usercount) = &show_users_list($r,$context,$env{'form.output'},
1441: $permission,$env{'form.Status'},\%userlist,$keylist);
1442: }
1443: if (!$usercount) {
1444: $r->print('<br />'.&mt('There are no users matching the search criteria.'));
1445: }
1446: }
1447: $r->print('<input type="hidden" name="phase" value="'.
1448: $env{'form.phase'}.'" /></form>');
1449: }
1450:
1451: sub section_group_filter {
1452: my ($cnum,$cdom) = @_;
1453: my @filters;
1454: if ($env{'request.course.sec'} eq '') {
1455: @filters = ('sec');
1456: }
1457: push(@filters,'grp');
1458: my %name = (
1459: sec => 'secfilter',
1460: grp => 'grpfilter',
1461: );
1462: my %title = &Apache::lonlocal::texthash (
1463: sec => 'Section(s)',
1464: grp => 'Group(s)',
1465: all => 'all',
1466: none => 'none',
1467: );
1468: my ($output,@options);
1469: foreach my $item (@filters) {
1470: my $markup;
1471: if ($env{'form.'.$name{$item}} eq '') {
1472: $env{'form.'.$name{$item}} = 'all';
1473: }
1474: if ($item eq 'sec') {
1475: if ($env{'form.showrole'} eq 'cc') {
1476: $env{'form.'.$name{$item}} = 'none';
1477: }
1478: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
1479: @options = sort(keys(%sections_count));
1480: } elsif ($item eq 'grp') {
1481: my %curr_groups = &Apache::longroup::coursegroups();
1482: @options = sort(keys(%curr_groups));
1483: }
1484: if (@options > 0) {
1485: my $currsel;
1486: $markup = '<select name="'.$name{$item}.'" />'."\n";
1487: foreach my $option ('all','none',@options) {
1488: $currsel = '';
1489: if ($env{'form.'.$name{$item}} eq $option) {
1490: $currsel = ' selected="selected" ';
1491: }
1492: $markup .= ' <option value="'.$option.'"'.$currsel.'>';
1493: if (($option eq 'all') || ($option eq 'none')) {
1494: $markup .= $title{$option};
1495: } else {
1496: $markup .= $option;
1497: }
1498: $markup .= '</option>'."\n";
1499: }
1500: $markup .= '</select>'."\n";
1501: $output .= (' 'x3).'<label>'.$title{$item}.': '.$markup.'</label>';
1502: }
1503: }
1504: return $output;
1505: }
1506:
1507: sub list_submit_button {
1508: my ($text) = @_;
1509: return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
1510: }
1511:
1512: sub gather_userinfo {
1513: my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
1514: foreach my $item (keys(%{$rolehash})) {
1515: my %userdata;
1516: if ($context eq 'author') {
1517: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1518: split(/:/,$item);
1519: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1520: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1521: $item,$userlist);
1522: } elsif ($context eq 'course') {
1523: my $viewablesec = &viewable_section($permission);
1524: ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
1525: $userdata{'section'}) = split(/:/,$item,-1);
1526: ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
1527: if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
1528: next if ($viewablesec ne $userdata{'section'});
1529: }
1530: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1531: $item,$userlist);
1532: } elsif ($context eq 'domain') {
1533: if ($env{'form.roletype'} eq 'domain') {
1534: ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
1535: split(/:/,$item);
1536: ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
1537: &build_user_record($context,\%userdata,$userinfo,$indexhash,
1538: $item,$userlist);
1539: } elsif ($env{'form.roletype'} eq 'author') {
1540: if (ref($rolehash->{$item}) eq 'HASH') {
1541: $userdata{'extent'} = $item;
1542: foreach my $key (keys(%{$rolehash->{$item}})) {
1543: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$key);
1544: ($userdata{'start'},$userdata{'end'}) =
1545: split(/:/,$rolehash->{$item}{$key});
1546: my $uniqid = $key.':'.$item;
1547: &build_user_record($context,\%userdata,$userinfo,
1548: $indexhash,$uniqid,$userlist);
1549: }
1550: }
1551: } elsif ($env{'form.roletype'} eq 'course') {
1552: ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
1553: split(/:/,$item);
1554: if (ref($rolehash->{$item}) eq 'HASH') {
1555: my $numcids = keys(%{$rolehash->{$item}});
1556: foreach my $cid (sort(keys(%{$rolehash->{$item}}))) {
1557: if (ref($rolehash->{$item}{$cid}) eq 'HASH') {
1558: my $spanstart = '';
1559: my $spanend = '; ';
1560: my $space = ', ';
1561: if ($format eq 'html' || $format eq 'view') {
1562: $spanstart = '<span class="LC_nobreak">';
1563: # FIXME: actions on courses disabled for now
1564: # if ($permission->{'cusr'}) {
1565: # if ($numcids > 1) {
1566: # $spanstart .= '<input type="radio" name="'.$item.'" value="'.$cid.'" /> ';
1567: # } else {
1568: # $spanstart .= '<input type="hidden" name="'.$item.'" value="'.$cid.'" /> ';
1569: # }
1570: # }
1571: $spanend = '</span><br />';
1572: $space = ', ';
1573: }
1574: $userdata{'extent'} .= $spanstart.
1575: $rolehash->{$item}{$cid}{'desc'}.$space;
1576: if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
1577: foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
1578: if (($env{'form.Status'} eq 'Any') ||
1579: ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
1580: $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
1581: $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
1582: }
1583: }
1584: }
1585: }
1586: }
1587: }
1588: if ($userdata{'status'} ne '') {
1589: &build_user_record($context,\%userdata,$userinfo,
1590: $indexhash,$item,$userlist);
1591: }
1592: }
1593: }
1594: }
1595: return;
1596: }
1597:
1598: sub build_user_record {
1599: my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
1600: next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
1601: if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
1602: &process_date_info($userdata);
1603: }
1604: my $username = $userdata->{'username'};
1605: my $domain = $userdata->{'domain'};
1606: if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
1607: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1608: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1609: } else {
1610: &aggregate_user_info($domain,$username,$userinfo);
1611: $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
1612: $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
1613: }
1614: foreach my $key (keys(%{$indexhash})) {
1615: if (defined($userdata->{$key})) {
1616: $userlist->{$record_key}[$indexhash->{$key}] = $userdata->{$key};
1617: }
1618: }
1619: return;
1620: }
1621:
1622: sub courses_selector {
1623: my ($cdom,$formname) = @_;
1624: my %coursecodes = ();
1625: my %codes = ();
1626: my @codetitles = ();
1627: my %cat_titles = ();
1628: my %cat_order = ();
1629: my %idlist = ();
1630: my %idnums = ();
1631: my %idlist_titles = ();
1632: my $caller = 'global';
1633: my $format_reply;
1634: my $jscript = '';
1635:
1636: my $totcodes = 0;
1637: $totcodes =
1638: &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
1639: $cdom,$totcodes);
1640: if ($totcodes > 0) {
1641: $format_reply =
1642: &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
1643: \%codes,\@codetitles,\%cat_titles,\%cat_order);
1644: if ($format_reply eq 'ok') {
1645: my $numtypes = @codetitles;
1646: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
1647: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
1648: my $longtitles_str = join('","',@{$longtitles});
1649: my $allidlist = $idlist{$codetitles[0]};
1650: $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
1651: $jscript .= $scripttext;
1652: $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
1653: }
1654: }
1655: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
1656:
1657: my %elements = (
1658: Year => 'selectbox',
1659: coursepick => 'radio',
1660: coursetotal => 'text',
1661: courselist => 'text',
1662: );
1663: $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
1664: if ($env{'form.coursepick'} eq 'category') {
1665: $jscript .= qq|
1666: function setCourseCat(formname) {
1667: if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
1668: return;
1669: }
1670: courseSet('Year');
1671: for (var j=0; j<formname.Semester.length; j++) {
1672: if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
1673: formname.Semester.options[j].selected = true;
1674: }
1675: }
1676: if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
1677: return;
1678: }
1679: courseSet('Semester');
1680: for (var j=0; j<formname.Department.length; j++) {
1681: if (formname.Department.options[j].value == "$env{'form.Department'}") { formname.Department.options[j].selected = true;
1682: }
1683: }
1684: if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
1685: return;
1686: }
1687: courseSet('Department');
1688: for (var j=0; j<formname.Number.length; j++) {
1689: if (formname.Number.options[j].value == "$env{'form.Number'}") {
1690: formname.Number.options[j].selected = true;
1691: }
1692: }
1693: }
1694: |;
1695: }
1696: return ($cb_jscript,$jscript,$totcodes,\@codetitles,\%idlist,
1697: \%idlist_titles);
1698: }
1699:
1700: sub course_selector_loadcode {
1701: my ($formname) = @_;
1702: my $loadcode;
1703: if ($env{'form.coursepick'} ne '') {
1704: $loadcode = 'javascript:setFormElements(document.'.$formname.')';
1705: if ($env{'form.coursepick'} eq 'category') {
1706: $loadcode .= ';javascript:setCourseCat(document.'.$formname.')';
1707: }
1708: }
1709: return $loadcode;
1710: }
1711:
1712: sub process_coursepick {
1713: my $coursefilter = $env{'form.coursepick'};
1714: my $cdom = $env{'request.role.domain'};
1715: my %courses;
1716: if ($coursefilter eq 'all') {
1717: %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
1718: undef,undef,'Course');
1719: } elsif ($coursefilter eq 'category') {
1720: my $instcode = &instcode_from_coursefilter();
1721: %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
1722: undef,undef,'Course');
1723: } elsif ($coursefilter eq 'specific') {
1724: if ($env{'form.coursetotal'} > 1) {
1725: my @course_ids = split(/&&/,$env{'form.courselist'});
1726: foreach my $cid (@course_ids) {
1727: $courses{$cid} = '';
1728: }
1729: } else {
1730: $courses{$env{'form.courselist'}} = '';
1731: }
1732: }
1733: return %courses;
1734: }
1735:
1736: sub instcode_from_coursefilter {
1737: my $instcode = '';
1738: my @cats = ('Semester','Year','Department','Number');
1739: foreach my $category (@cats) {
1740: if (defined($env{'form.'.$category})) {
1741: unless ($env{'form.'.$category} eq '-1') {
1742: $instcode .= $env{'form.'.$category};
1743: }
1744: }
1745: }
1746: if ($instcode eq '') {
1747: $instcode = '.';
1748: }
1749: return $instcode;
1750: }
1751:
1752: sub display_adv_courseroles {
1753: my $output;
1754: #
1755: # List course personnel
1756: my %coursepersonnel =
1757: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});
1758: #
1759: $output = '<br />'.&Apache::loncommon::start_data_table();
1760: foreach my $role (sort(keys(%coursepersonnel))) {
1761: next if ($role =~ /^\s*$/);
1762: $output .= &Apache::loncommon::start_data_table_row().
1763: '<td>'.$role.'</td><td>';
1764: foreach my $user (split(',',$coursepersonnel{$role})) {
1765: my ($puname,$pudom)=split(':',$user);
1766: $output .= ' '.&Apache::loncommon::aboutmewrapper(
1767: &Apache::loncommon::plainname($puname,$pudom),
1768: $puname,$pudom);
1769: }
1770: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
1771: }
1772: $output .= &Apache::loncommon::end_data_table();
1773: }
1774:
1775: sub make_keylist_array {
1776: my ($index,$keylist);
1777: $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
1778: $index->{'username'} = &Apache::loncoursedata::CL_SNAME();
1779: $index->{'end'} = &Apache::loncoursedata::CL_END();
1780: $index->{'start'} = &Apache::loncoursedata::CL_START();
1781: $index->{'id'} = &Apache::loncoursedata::CL_ID();
1782: $index->{'section'} = &Apache::loncoursedata::CL_SECTION();
1783: $index->{'fullname'} = &Apache::loncoursedata::CL_FULLNAME();
1784: $index->{'status'} = &Apache::loncoursedata::CL_STATUS();
1785: $index->{'type'} = &Apache::loncoursedata::CL_TYPE();
1786: $index->{'lockedtype'} = &Apache::loncoursedata::CL_LOCKEDTYPE();
1787: $index->{'groups'} = &Apache::loncoursedata::CL_GROUP();
1788: $index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
1789: $index->{'role'} = &Apache::loncoursedata::CL_ROLE();
1790: $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
1791: $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
1792: foreach my $key (keys(%{$index})) {
1793: $keylist->[$index->{$key}] = $key;
1794: }
1795: return ($index,$keylist);
1796: }
1797:
1798: sub aggregate_user_info {
1799: my ($udom,$uname,$userinfo) = @_;
1800: my %info=&Apache::lonnet::get('environment',
1801: ['firstname','middlename',
1802: 'lastname','generation','id'],
1803: $udom,$uname);
1804: my ($tmp) = keys(%info);
1805: my ($fullname,$id);
1806: if ($tmp =~/^(con_lost|error|no_such_host)/i) {
1807: $fullname = 'not available';
1808: $id = 'not available';
1809: &Apache::lonnet::logthis('unable to retrieve environment '.
1810: 'for '.$uname.':'.$udom);
1811: } else {
1812: $fullname = &Apache::lonnet::format_name(@info{qw/firstname middlename lastname generation/},'lastname');
1813: $id = $info{'id'};
1814: }
1815: $userinfo->{$uname.':'.$udom} = {
1816: fullname => $fullname,
1817: id => $id,
1818: };
1819: return;
1820: }
1821:
1822: sub process_date_info {
1823: my ($userdata) = @_;
1824: my $now = time;
1825: $userdata->{'status'} = 'Active';
1826: if ($userdata->{'start'} > 0) {
1827: if ($now < $userdata->{'start'}) {
1828: $userdata->{'status'} = 'Future';
1829: }
1830: }
1831: if ($userdata->{'end'} > 0) {
1832: if ($now > $userdata->{'end'}) {
1833: $userdata->{'status'} = 'Expired';
1834: }
1835: }
1836: return;
1837: }
1838:
1839: sub show_users_list {
1840: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
1841: #
1842: # Variables for excel output
1843: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1844: #
1845: # Variables for csv output
1846: my ($CSVfile,$CSVfilename);
1847: #
1848: my $sortby = $env{'form.sortby'};
1849: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1850: if ($context eq 'course') {
1851: push(@sortable,('section','groups','type'));
1852: } else {
1853: push(@sortable,'extent');
1854: }
1855: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1856: $sortby = 'username';
1857: }
1858: my $setting = $env{'form.roletype'};
1859: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1860: if ($context eq 'course') {
1861: $cid = $env{'request.course.id'};
1862: ($cnum,$cdom) = &get_course_identity($cid);
1863: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1864: $userlist,$keylist,$cdom,$cnum);
1865: if ($mode eq 'autoenroll') {
1866: $env{'form.showrole'} = 'st';
1867: } else {
1868: if (! exists($env{'form.displayphotos'})) {
1869: $env{'form.displayphotos'} = 'off';
1870: }
1871: $displayphotos = $env{'form.displayphotos'};
1872: if (! exists($env{'form.displayclickers'})) {
1873: $env{'form.displayclickers'} = 'off';
1874: }
1875: $displayclickers = $env{'form.displayclickers'};
1876: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1877: $r->print('
1878: <script type="text/javascript">
1879: function photowindow(photolink) {
1880: var title = "Photo_Viewer";
1881: var options = "scrollbars=1,resizable=1,menubar=0";
1882: options += ",width=240,height=240";
1883: stdeditbrowser = open(photolink,title,options,"1");
1884: stdeditbrowser.focus();
1885: }
1886: </script>
1887: ');
1888: }
1889: $r->print(<<END);
1890: <input type="hidden" name="displayphotos" value="$displayphotos" />
1891: <input type="hidden" name="displayclickers" value="$displayclickers" />
1892: END
1893: }
1894: }
1895: if ($mode ne 'autoenroll') {
1896: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1897: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
1898: my $singconfirm = &mt(' for a single user?');
1899: my $multconfirm = &mt(' for multiple users?');
1900: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1901: my %lt = &Apache::lonlocal::texthash(
1902: acwi => 'Access will be set to start immediately',
1903: asyo => 'as you did not select an end date in the pop-up window',
1904: accw => 'Access will be set to continue indefinitely',
1905: asyd => 'as you did not select an end date in the pop-up window',
1906: sewi => "Sections will be switched to 'No section'",
1907: ayes => "as you either selected the 'No section' option",
1908: oryo => 'or you did not select a section in the pop-up window',
1909: arol => 'A role with no section will be added',
1910: swbs => 'Sections will be switched to:',
1911: rwba => 'Roles will be added for section(s):',
1912: );
1913: $r->print(<<END);
1914:
1915: <script type="text/javascript" language="Javascript">
1916: $check_uncheck_js
1917:
1918: function verify_action (field) {
1919: var numchecked = 0;
1920: var singconf = '$singconfirm';
1921: var multconf = '$multconfirm';
1922: if (field.length > 0) {
1923: for (i = 0; i < field.length; i++) {
1924: if (field[i].checked == true) {
1925: numchecked ++;
1926: }
1927: }
1928: } else {
1929: if (field.checked == true) {
1930: numchecked ++;
1931: }
1932: }
1933: if (numchecked == 0) {
1934: alert("$alert");
1935: }
1936: else {
1937: var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
1938: var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value;
1939: if (numchecked == 1) {
1940: message += singconf;
1941: }
1942: else {
1943: message += multconf;
1944: }
1945: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
1946: var datemsg = '';
1947: if ((document.studentform.startdate_month.value == '') &&
1948: (document.studentform.startdate_day.value == '') &&
1949: (document.studentform.startdate_year.value == '')) {
1950: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
1951: }
1952: if ((document.studentform.enddate_month.value == '') &&
1953: (document.studentform.enddate_day.value == '') &&
1954: (document.studentform.enddate_year.value == '')) {
1955: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
1956: }
1957: if (datemsg != '') {
1958: message += "\\n"+datemsg;
1959: }
1960: }
1961: if (choice == 'chgsec') {
1962: var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value;
1963: var retained = document.studentform.retainsec.value;
1964: var secshow = document.studentform.newsecs.value;
1965: if (secshow == '') {
1966: if (rolefilter == 'st' || retained == 0 || retained == "") {
1967: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
1968: } else {
1969: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
1970: }
1971: } else {
1972: if (rolefilter == 'st' || retained == 0 || retained == "") {
1973: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
1974: } else {
1975: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
1976: }
1977: }
1978: }
1979: if (confirm(message)) {
1980: document.studentform.phase.value = 'bulkchange';
1981: document.studentform.submit();
1982: }
1983: }
1984: }
1985:
1986: function username_display_launch(username,domain) {
1987: var target;
1988: for (var i=0; i<document.studentform.usernamelink.length; i++) {
1989: if (document.studentform.usernamelink[i].checked) {
1990: target = document.studentform.usernamelink[i].value;
1991: }
1992: }
1993: if (target == 'modify') {
1994: document.studentform.srchterm.value=username;
1995: document.studentform.srchdomain.value=domain;
1996: document.studentform.phase.value='get_user_info';
1997: document.studentform.action.value = 'singleuser';
1998: document.studentform.submit();
1999: }
2000: else {
2001: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
2002: }
2003: }
2004: </script>
2005: $date_sec_selector
2006: <input type="hidden" name="state" value="$env{'form.state'}" />
2007: END
2008: }
2009: $r->print(<<END);
2010: <input type="hidden" name="sortby" value="$sortby" />
2011: END
2012:
2013: my %lt=&Apache::lonlocal::texthash(
2014: 'username' => "username",
2015: 'domain' => "domain",
2016: 'id' => 'ID',
2017: 'fullname' => "name",
2018: 'section' => "section",
2019: 'groups' => "active groups",
2020: 'start' => "start date",
2021: 'end' => "end date",
2022: 'status' => "status",
2023: 'role' => "role",
2024: 'type' => "enroll type/action",
2025: 'email' => "email address",
2026: 'clicker' => "clicker id",
2027: 'photo' => "photo",
2028: 'extent' => "extent",
2029: 'go' => "go",
2030: 'pr' => "Proceed",
2031: 'ca' => "check all",
2032: 'ua' => "uncheck all",
2033: 'ac' => "Action to take for selected users",
2034: 'link' => "Behavior of username links",
2035: 'aboutme' => "Display a user's personal page",
2036: 'modify' => "Modify a user's information",
2037: );
2038: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2039: $lt{'extent'} = &mt('Course(s): description, section(s), status');
2040: } elsif ($context eq 'author') {
2041: $lt{'extent'} = &mt('Author');
2042: }
2043: my @cols = ('username','domain','id','fullname');
2044: if ($context eq 'course') {
2045: push(@cols,'section');
2046: }
2047: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
2048: push(@cols,('start','end'));
2049: }
2050: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
2051: push(@cols,'role');
2052: }
2053: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
2054: $env{'form.roletype'} eq 'course')) {
2055: push (@cols,'extent');
2056: }
2057: if (($statusmode eq 'Any') &&
2058: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
2059: push(@cols,'status');
2060: }
2061: if ($context eq 'course') {
2062: push(@cols,'groups');
2063: }
2064: push(@cols,'email');
2065:
2066: my $rolefilter = $env{'form.showrole'};
2067: if ($env{'form.showrole'} eq 'cr') {
2068: $rolefilter = &mt('custom');
2069: } elsif ($env{'form.showrole'} ne 'Any') {
2070: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
2071: }
2072: my $results_description;
2073: if ($mode ne 'autoenroll') {
2074: $results_description = &results_header_row($rolefilter,$statusmode,
2075: $context,$permission,$mode);
2076: $r->print('<b>'.$results_description.'</b><br />');
2077: }
2078: my ($output,$actionselect,%canchange,%canchangesec);
2079: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
2080: if ($mode ne 'autoenroll') {
2081: if ($permission->{'cusr'}) {
2082: $actionselect = &select_actions($context,$setting,$statusmode);
2083: }
2084: $r->print(<<END);
2085: <input type="hidden" name="srchby" value="uname" />
2086: <input type="hidden" name="srchin" value="dom" />
2087: <input type="hidden" name="srchtype" value="exact" />
2088: <input type="hidden" name="srchterm" value="" />
2089: <input type="hidden" name="srchdomain" value="" />
2090: END
2091: $output = '<p>';
2092: my @linkdests = ('aboutme');
2093: if ($permission->{'cusr'}) {
2094: push (@linkdests,'modify');
2095: $output .= '<span class="LC_nobreak">'.$lt{'link'}.': ';
2096: my $usernamelink = $env{'form.usernamelink'};
2097: if ($usernamelink eq '') {
2098: $usernamelink = 'aboutme';
2099: }
2100: foreach my $item (@linkdests) {
2101: my $checkedstr = '';
2102: if ($item eq $usernamelink) {
2103: $checkedstr = ' checked="checked" ';
2104: }
2105: $output .= '<label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'> '.$lt{$item}.'</label> ';
2106: }
2107: $output .= '</span><br />';
2108: } else {
2109: $output .= &mt("Click on a username to view the user's personal page.").'<br />';
2110: }
2111: if ($actionselect) {
2112: $output .= <<"END";
2113: $lt{'ac'}: $actionselect <input type="button" value="$lt{'go'}" onclick="javascript:opendatebrowser(this.form,'studentform','go')" /></p>
2114: <p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.actionlist)" />
2115: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.actionlist)" /><br /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.studentform.actionlist)" />
2116: END
2117: my @allroles;
2118: if ($env{'form.showrole'} eq 'Any') {
2119: my $custom = 1;
2120: if ($context eq 'domain') {
2121: @allroles = &roles_by_context($setting,$custom);
2122: } else {
2123: @allroles = &roles_by_context($context,$custom);
2124: }
2125: } else {
2126: @allroles = ($env{'form.showrole'});
2127: }
2128: foreach my $role (@allroles) {
2129: if ($context eq 'domain') {
2130: if ($setting eq 'domain') {
2131: if (&Apache::lonnet::allowed('c'.$role,
2132: $env{'request.role.domain'})) {
2133: $canchange{$role} = 1;
2134: }
2135: } elsif ($setting eq 'author') {
2136: if (&Apache::lonnet::allowed('c'.$role,
2137: $env{'request.role.domain'})) {
2138: $canchange{$role} = 1;
2139: }
2140: }
2141: } elsif ($context eq 'author') {
2142: if (&Apache::lonnet::allowed('c'.$role,
2143: $env{'user.domain'}.'/'.$env{'user.name'})) {
2144: $canchange{$role} = 1;
2145: }
2146: } elsif ($context eq 'course') {
2147: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2148: $canchange{$role} = 1;
2149: } elsif ($env{'request.course.sec'} ne '') {
2150: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2151: $canchangesec{$role} = $env{'request.course.sec'};
2152: }
2153: }
2154: }
2155: }
2156: }
2157: }
2158: $output .= "\n<p>\n".
2159: &Apache::loncommon::start_data_table().
2160: &Apache::loncommon::start_data_table_header_row();
2161: if ($mode eq 'autoenroll') {
2162: $output .= "
2163: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
2164: ";
2165: } else {
2166: $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
2167: if ($actionselect) {
2168: $output .= '<th>'.&mt('Select').'</th>'."\n";
2169: }
2170: }
2171: foreach my $item (@cols) {
2172: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
2173: }
2174: my %role_types = &role_type_names();
2175: if ($context eq 'course' && $mode ne 'autoenroll') {
2176: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2177: # Clicker display on or off?
2178: my %clicker_options = &Apache::lonlocal::texthash(
2179: 'on' => 'Show',
2180: 'off' => 'Hide',
2181: );
2182: my $clickerchg = 'on';
2183: if ($displayclickers eq 'on') {
2184: $clickerchg = 'off';
2185: }
2186: $output .= ' <th>'."\n".' '.
2187: '<a href="javascript:document.studentform.displayclickers.value='.
2188: "'".$clickerchg."'".';document.studentform.submit();">'.
2189: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
2190: ' </th>'."\n";
2191:
2192: # Photo display on or off?
2193: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2194: my %photo_options = &Apache::lonlocal::texthash(
2195: 'on' => 'Show',
2196: 'off' => 'Hide',
2197: );
2198: my $photochg = 'on';
2199: if ($displayphotos eq 'on') {
2200: $photochg = 'off';
2201: }
2202: $output .= ' <th>'."\n".' '.
2203: '<a href="javascript:document.studentform.displayphotos.value='.
2204: "'".$photochg."'".';document.studentform.submit();">'.
2205: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
2206: ' </th>'."\n";
2207: }
2208: }
2209: }
2210: $output .= &Apache::loncommon::end_data_table_header_row();
2211: # Done with the HTML header line
2212: } elsif ($mode eq 'csv') {
2213: #
2214: # Open a file
2215: $CSVfilename = '/prtspool/'.
2216: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2217: time.'_'.rand(1000000000).'.csv';
2218: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2219: $r->log_error("Couldn't open $CSVfilename for output $!");
2220: $r->print("Problems occured in writing the csv file. ".
2221: "This error has been logged. ".
2222: "Please alert your LON-CAPA administrator.");
2223: $CSVfile = undef;
2224: }
2225: #
2226: # Write headers and data to file
2227: print $CSVfile '"'.$results_description.'"'."\n";
2228: print $CSVfile '"'.join('","',map {
2229: &Apache::loncommon::csv_translate($lt{$_})
2230: } (@cols)).'"'."\n";
2231: } elsif ($mode eq 'excel') {
2232: # Create the excel spreadsheet
2233: ($excel_workbook,$excel_filename,$format) =
2234: &Apache::loncommon::create_workbook($r);
2235: return if (! defined($excel_workbook));
2236: $excel_sheet = $excel_workbook->addworksheet('userlist');
2237: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
2238: #
2239: my @colnames = map {$lt{$_}} (@cols);
2240: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2241: }
2242:
2243: # Done with header lines in all formats
2244:
2245: my %index;
2246: my $i;
2247: foreach my $idx (@$keylist) {
2248: $index{$idx} = $i++;
2249: }
2250: my $usercount = 0;
2251: my ($secfilter,$grpfilter);
2252: if ($context eq 'course') {
2253: $secfilter = $env{'form.secfilter'};
2254: $grpfilter = $env{'form.grpfilter'};
2255: if ($secfilter eq '') {
2256: $secfilter = 'all';
2257: }
2258: if ($grpfilter eq '') {
2259: $grpfilter = 'all';
2260: }
2261: }
2262: # Get groups, role, permanent e-mail so we can sort on them if
2263: # necessary.
2264: foreach my $user (keys(%{$userlist})) {
2265: if ($user eq '' ) {
2266: delete($userlist->{$user});
2267: next;
2268: }
2269: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2270: delete($userlist->{$user});
2271: next;
2272: }
2273: my ($uname,$udom,$role,$groups,$email);
2274: if (($statusmode ne 'Any') &&
2275: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2276: delete($userlist->{$user});
2277: next;
2278: }
2279: if ($context eq 'domain') {
2280: if ($env{'form.roletype'} eq 'domain') {
2281: ($role,$uname,$udom) = split(/:/,$user);
2282: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2283: ($udom eq $env{'request.role.domain'})) {
2284: delete($userlist->{$user});
2285: next;
2286: }
2287: } elsif ($env{'form.roletype'} eq 'author') {
2288: ($uname,$udom,$role) = split(/:/,$user,-1);
2289: } elsif ($env{'form.roletype'} eq 'course') {
2290: ($uname,$udom,$role) = split(/:/,$user);
2291: }
2292: } else {
2293: ($uname,$udom,$role) = split(/:/,$user,-1);
2294: if (($context eq 'course') && $role eq '') {
2295: $role = 'st';
2296: }
2297: }
2298: $userlist->{$user}->[$index{'role'}] = $role;
2299: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2300: delete($userlist->{$user});
2301: next;
2302: }
2303: if ($context eq 'course') {
2304: my @ac_groups;
2305: if (ref($classgroups) eq 'HASH') {
2306: $groups = $classgroups->{$user};
2307: }
2308: if (ref($groups->{'active'}) eq 'HASH') {
2309: @ac_groups = keys(%{$groups->{'active'}});
2310: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
2311: }
2312: if ($mode ne 'autoenroll') {
2313: my $section = $userlist->{$user}->[$index{'section'}];
2314: if (($env{'request.course.sec'} ne '') &&
2315: ($section ne $env{'request.course.sec'})) {
2316: if ($role eq 'st') {
2317: delete($userlist->{$user});
2318: next;
2319: }
2320: }
2321: if ($secfilter eq 'none') {
2322: if ($section ne '') {
2323: delete($userlist->{$user});
2324: next;
2325: }
2326: } elsif ($secfilter ne 'all') {
2327: if ($section ne $secfilter) {
2328: delete($userlist->{$user});
2329: next;
2330: }
2331: }
2332: if ($grpfilter eq 'none') {
2333: if (@ac_groups > 0) {
2334: delete($userlist->{$user});
2335: next;
2336: }
2337: } elsif ($grpfilter ne 'all') {
2338: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
2339: delete($userlist->{$user});
2340: next;
2341: }
2342: }
2343: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2344: if (($displayphotos eq 'on') && ($role eq 'st')) {
2345: $userlist->{$user}->[$index{'photo'}] =
2346: &Apache::lonnet::retrievestudentphoto($udom,$uname,
2347: 'gif','thumbnail');
2348: }
2349: }
2350: }
2351: }
2352: my %emails = &Apache::loncommon::getemails($uname,$udom);
2353: if ($emails{'permanentemail'} =~ /\S/) {
2354: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2355: }
2356: $usercount ++;
2357: }
2358: my $autocount = 0;
2359: my $manualcount = 0;
2360: my $lockcount = 0;
2361: my $unlockcount = 0;
2362: if ($usercount) {
2363: $r->print($output);
2364: } else {
2365: if ($mode eq 'autoenroll') {
2366: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2367: } else {
2368: return;
2369: }
2370: }
2371: #
2372: # Sort the users
2373: my $index = $index{$sortby};
2374: my $second = $index{'username'};
2375: my $third = $index{'domain'};
2376: my @sorted_users = sort {
2377: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
2378: ||
2379: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2380: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2381: } (keys(%$userlist));
2382: my $rowcount = 0;
2383: foreach my $user (@sorted_users) {
2384: my %in;
2385: my $sdata = $userlist->{$user};
2386: $rowcount ++;
2387: foreach my $item (@{$keylist}) {
2388: $in{$item} = $sdata->[$index{$item}];
2389: }
2390: my $role = $in{'role'};
2391: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
2392: if (! defined($in{'start'}) || $in{'start'} == 0) {
2393: $in{'start'} = &mt('none');
2394: } else {
2395: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2396: }
2397: if (! defined($in{'end'}) || $in{'end'} == 0) {
2398: $in{'end'} = &mt('none');
2399: } else {
2400: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2401: }
2402: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2403: $r->print(&Apache::loncommon::start_data_table_row());
2404: my $checkval;
2405: if ($mode eq 'autoenroll') {
2406: my $cellentry;
2407: if ($in{'type'} eq 'auto') {
2408: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label>';
2409: $autocount ++;
2410: } else {
2411: $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><nobr><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label></nobr></td></tr><tr><td><nobr>';
2412: $manualcount ++;
2413: if ($in{'lockedtype'}) {
2414: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Unlock').'</label>';
2415: $unlockcount ++;
2416: } else {
2417: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Lock').'</label>';
2418: $lockcount ++;
2419: }
2420: $cellentry .= '</nobr></td></tr></table>';
2421: }
2422: $r->print("<td>$cellentry</td>\n");
2423: } else {
2424: $r->print("<td>$rowcount</td>\n");
2425: if ($actionselect) {
2426: my $showcheckbox;
2427: if ($role =~ /^cr\//) {
2428: $showcheckbox = $canchange{'cr'};
2429: } else {
2430: $showcheckbox = $canchange{$role};
2431: }
2432: if (!$showcheckbox) {
2433: if ($context eq 'course') {
2434: if ($canchangesec{$role} ne '') {
2435: if ($canchangesec{$role} eq $in{'section'}) {
2436: $showcheckbox = 1;
2437: }
2438: }
2439: }
2440: }
2441: if ($showcheckbox) {
2442: $checkval = $user;
2443: if ($context eq 'course') {
2444: if ($role eq 'st') {
2445: $checkval .= ':st';
2446: }
2447: $checkval .= ':'.$in{'section'};
2448: if ($role eq 'st') {
2449: $checkval .= ':'.$in{'type'}.':'.
2450: $in{'lockedtype'};
2451: }
2452: }
2453: $r->print('<td><input type="checkbox" name="'.
2454: 'actionlist" value="'.$checkval.'"></td>');
2455: } else {
2456: $r->print('<td> </td>');
2457: }
2458: }
2459: }
2460: foreach my $item (@cols) {
2461: if ($item eq 'username') {
2462: $r->print('<td>'.&print_username_link($mode,$permission,
2463: \%in).'</td>');
2464: } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
2465: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
2466: } else {
2467: $r->print('<td>'.$in{$item}.'</td>'."\n");
2468: }
2469: }
2470: if (($context eq 'course') && ($mode ne 'autoenroll')) {
2471: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2472: if ($displayclickers eq 'on') {
2473: my $clickers =
2474: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
2475: if ($clickers!~/\w/) { $clickers='-'; }
2476: $r->print('<td>'.$clickers.'</td>');
2477: } else {
2478: $r->print(' <td> </td> ');
2479: }
2480: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2481: if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
2482: $r->print(' <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$in{'photo'}.'" border="1"></a></td>');
2483: } else {
2484: $r->print(' <td> </td> ');
2485: }
2486: }
2487: }
2488: }
2489: $r->print(&Apache::loncommon::end_data_table_row());
2490: } elsif ($mode eq 'csv') {
2491: next if (! defined($CSVfile));
2492: # no need to bother with $linkto
2493: if (! defined($in{'start'}) || $in{'start'} == 0) {
2494: $in{'start'} = &mt('none');
2495: } else {
2496: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2497: }
2498: if (! defined($in{'end'}) || $in{'end'} == 0) {
2499: $in{'end'} = &mt('none');
2500: } else {
2501: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2502: }
2503: my @line = ();
2504: foreach my $item (@cols) {
2505: push @line,&Apache::loncommon::csv_translate($in{$item});
2506: }
2507: print $CSVfile '"'.join('","',@line).'"'."\n";
2508: } elsif ($mode eq 'excel') {
2509: my $col = 0;
2510: foreach my $item (@cols) {
2511: if ($item eq 'start' || $item eq 'end') {
2512: if (defined($item) && $item != 0) {
2513: $excel_sheet->write($row,$col++,
2514: &Apache::lonstathelpers::calc_serial($in{item}),
2515: $format->{'date'});
2516: } else {
2517: $excel_sheet->write($row,$col++,'none');
2518: }
2519: } else {
2520: $excel_sheet->write($row,$col++,$in{$item});
2521: }
2522: }
2523: $row++;
2524: }
2525: }
2526: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2527: $r->print(&Apache::loncommon::end_data_table().'<br />');
2528: } elsif ($mode eq 'excel') {
2529: $excel_workbook->close();
2530: $r->print('<p><a href="'.$excel_filename.'">'.
2531: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2532: } elsif ($mode eq 'csv') {
2533: close($CSVfile);
2534: $r->print('<a href="'.$CSVfilename.'">'.
2535: &mt('Your CSV file').'</a> is ready for download.'.
2536: "\n");
2537: $r->rflush();
2538: }
2539: if ($mode eq 'autoenroll') {
2540: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2541: } else {
2542: return ($usercount);
2543: }
2544: }
2545:
2546: sub print_username_link {
2547: my ($mode,$permission,$in) = @_;
2548: my $output;
2549: if ($mode eq 'autoenroll') {
2550: $output = $in->{'username'};
2551: } elsif (!$permission->{'cusr'}) {
2552: $output = &Apache::loncommon::aboutmewrapper($in->{'username'},
2553: $in->{'username'},
2554: $in->{'domain'});
2555: } else {
2556: $output = '<a href="javascript:username_display_launch('.
2557: "'$in->{'username'}','$in->{'domain'}'".')" />'.
2558: $in->{'username'}.'</a>';
2559: }
2560: return $output;
2561: }
2562:
2563: sub role_type_names {
2564: my %lt = &Apache::lonlocal::texthash (
2565: 'domain' => 'Domain Roles',
2566: 'author' => 'Co-Author Roles',
2567: 'course' => 'Course Roles',
2568: );
2569: return %lt;
2570: }
2571:
2572: sub select_actions {
2573: my ($context,$setting,$statusmode) = @_;
2574: my %lt = &Apache::lonlocal::texthash(
2575: revoke => "Revoke user roles",
2576: delete => "Delete user roles",
2577: reenable => "Re-enable expired user roles",
2578: activate => "Make future user roles active now",
2579: chgdates => "Change starting/ending dates",
2580: chgsec => "Change section associated with user roles",
2581: );
2582: my ($output,$options,%choices);
2583: # FIXME Disable actions for now for roletype=course in domain context
2584: if ($context eq 'domain' && $setting eq 'course') {
2585: return;
2586: }
2587: if ($context eq 'course') {
2588: if ($env{'form.showrole'} ne 'Any') {
2589: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
2590: $env{'request.course.id'})) {
2591: if ($env{'request.course.sec'} eq '') {
2592: return;
2593: } else {
2594: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2595: return;
2596: }
2597: }
2598: }
2599: }
2600: }
2601: if ($statusmode eq 'Any') {
2602: $options .= '
2603: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
2604: $choices{'dates'} = 1;
2605: } else {
2606: if ($statusmode eq 'Future') {
2607: $options .= '
2608: <option value="activate">'.$lt{'activate'}.'</option>';
2609: $choices{'dates'} = 1;
2610: } elsif ($statusmode eq 'Expired') {
2611: $options .= '
2612: <option value="reenable">'.$lt{'reenable'}.'</option>';
2613: $choices{'dates'} = 1;
2614: }
2615: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
2616: $options .= '
2617: <option value="chgdates">'.$lt{'chgdates'}.'</option>
2618: <option value="revoke">'.$lt{'revoke'}.'</option>';
2619: $choices{'dates'} = 1;
2620: }
2621: }
2622: if ($context eq 'domain') {
2623: $options .= '
2624: <option value="delete">'.$lt{'delete'}.'</option>';
2625: }
2626: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2627: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
2628: $options .= '
2629: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
2630: $choices{'sections'} = 1;
2631: }
2632: }
2633: if ($options) {
2634: $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'studentform','change'".')" />'."\n".
2635: '<option value="" selected="selected">'.
2636: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
2637: if ($choices{'dates'}) {
2638: $output .=
2639: '<input type="hidden" name="startdate_month" value="" />'."\n".
2640: '<input type="hidden" name="startdate_day" value="" />'."\n".
2641: '<input type="hidden" name="startdate_year" value="" />'."\n".
2642: '<input type="hidden" name="startdate_hour" value="" />'."\n".
2643: '<input type="hidden" name="startdate_minute" value="" />'."\n".
2644: '<input type="hidden" name="startdate_second" value="" />'."\n".
2645: '<input type="hidden" name="enddate_month" value="" />'."\n".
2646: '<input type="hidden" name="enddate_day" value="" />'."\n".
2647: '<input type="hidden" name="enddate_year" value="" />'."\n".
2648: '<input type="hidden" name="enddate_hour" value="" />'."\n".
2649: '<input type="hidden" name="enddate_minute" value="" />'."\n".
2650: '<input type="hidden" name="enddate_second" value="" />'."\n";
2651: if ($context eq 'course') {
2652: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
2653: }
2654: }
2655: if ($choices{'sections'}) {
2656: $output .= '<input type="hidden" name="retainsec" value= "" />'."\n".
2657: '<input type="hidden" name="newsecs" value= "" />'."\n";
2658: }
2659: }
2660: return $output;
2661: }
2662:
2663: sub date_section_javascript {
2664: my ($context,$setting) = @_;
2665: my $title;
2666: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
2667: $title = &mt('Date and Section selector');
2668: } else {
2669: $title = &mt('Date selector');
2670: }
2671: my %nopopup = &Apache::lonlocal::texthash (
2672: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
2673: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
2674: none => "Choose an action to take for selected users",
2675: );
2676: my $output = '
2677: <script type="text/javascript">
2678: var stdeditbrowser;'."\n";
2679: $output .= <<"ENDONE";
2680: function opendatebrowser(callingform,formname,calledby) {
2681: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
2682: if (bulkaction == 'revoke' || bulkaction == 'delete' || bulkaction == '') {
2683: if (calledby == 'go') {
2684: if (bulkaction == 'revoke') {
2685: alert("$nopopup{'revoke'}");
2686: }
2687: if (bulkaction == 'delete') {
2688: alert("$nopopup{'delete'}");
2689: }
2690: if (bulkaction == '') {
2691: alert("$nopopup{'none'}");
2692: }
2693: }
2694: return;
2695: }
2696: var url = '/adm/createuser?';
2697: var type = '';
2698: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
2699: ENDONE
2700: if ($context eq 'domain') {
2701: $output .= '
2702: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
2703: ';
2704: }
2705: my $width= '700';
2706: my $height = '400';
2707: $output .= <<"ENDTWO";
2708: url += 'action=dateselect&callingform=' + formname +
2709: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
2710: var title = '$title';
2711: var options = 'scrollbars=1,resizable=1,menubar=0';
2712: options += ',width=$width,height=$height';
2713: stdeditbrowser = open(url,title,options,'1');
2714: stdeditbrowser.focus();
2715: }
2716: </script>
2717: ENDTWO
2718: return $output;
2719: }
2720:
2721: sub date_section_selector {
2722: my ($context,$permission) = @_;
2723: my $callingform = $env{'form.callingform'};
2724: my $formname = 'dateselect';
2725: my $groupslist = &get_groupslist();
2726: my $sec_js = &setsections_javascript($formname,$groupslist);
2727: my $output = <<"END";
2728: <script type="text/javascript">
2729:
2730: $sec_js
2731:
2732: function saveselections(formname) {
2733:
2734: END
2735: if ($env{'form.bulkaction'} eq 'chgsec') {
2736: $output .= <<"END";
2737: if (formname.retainsec.length > 1) {
2738: for (var i=0; i<formname.retainsec.length; i++) {
2739: if (formname.retainsec[i].checked == true) {
2740: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
2741: }
2742: }
2743: } else {
2744: opener.document.$callingform.retainsec.value = formname.retainsec.value;
2745: }
2746: setSections(formname);
2747: if (seccheck == 'ok') {
2748: opener.document.$callingform.newsecs.value = formname.sections.value;
2749: window.close();
2750: }
2751: return;
2752: END
2753: } else {
2754: if ($context eq 'course') {
2755: if (($env{'form.bulkaction'} eq 'reenable') ||
2756: ($env{'form.bulkaction'} eq 'activate') ||
2757: ($env{'form.bulkaction'} eq 'chgdates')) {
2758: if ($env{'request.course.sec'} eq '') {
2759: $output .= <<"END";
2760:
2761: if (formname.makedatesdefault.checked == true) {
2762: opener.document.$callingform.makedatesdefault.value = 1;
2763: }
2764: else {
2765: opener.document.$callingform.makedatesdefault.value = 0;
2766: }
2767:
2768: END
2769: }
2770: }
2771: }
2772: $output .= <<"END";
2773: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
2774: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
2775: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
2776: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
2777: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
2778: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
2779: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
2780: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
2781: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
2782: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
2783: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
2784: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
2785: window.close();
2786: END
2787: }
2788: $output .= '
2789: }
2790: </script>
2791: ';
2792: my %lt = &Apache::lonlocal::texthash (
2793: chac => 'Access dates to apply for selected users',
2794: chse => 'Changes in section affiliation to apply to selected users',
2795: fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
2796: forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
2797: reta => "Retain each user's current section affiliations?",
2798: dnap => '(Does not apply to student roles).',
2799: );
2800: my ($date_items,$headertext);
2801: if ($env{'form.bulkaction'} eq 'chgsec') {
2802: $headertext = $lt{'chse'};
2803: } else {
2804: $headertext = $lt{'chac'};
2805: my $starttime;
2806: if (($env{'form.bulkaction'} eq 'activate') ||
2807: ($env{'form.bulkaction'} eq 'reenable')) {
2808: $starttime = time;
2809: }
2810: $date_items = &date_setting_table($starttime,undef,$context,
2811: $env{'form.bulkaction'},$formname,
2812: $permission);
2813: }
2814: $output .= '<h3>'.$headertext.'</h3>'.
2815: '<form name="'.$formname.'" method="post">'."\n".
2816: $date_items;
2817: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
2818: my ($cnum,$cdom) = &get_course_identity();
2819: my $info;
2820: if ($env{'form.showrole'} eq 'st') {
2821: $output .= '<p>'.$lt{'fors'}.'</p>';
2822: } elsif ($env{'form.showrole'} eq 'Any') {
2823: $output .= '<p>'.$lt{'fors'}.'</p>'.
2824: '<p>'.$lt{'forn'}.' ';
2825: $info = $lt{'reta'};
2826: } else {
2827: $output .= '<p>'.$lt{'forn'}.' ';
2828: $info = $lt{'reta'};
2829: }
2830: if ($info) {
2831: $info .= '<span class="LC_nobreak">'.
2832: '<label><input type="radio" name="retainsec" value="1" '.
2833: 'checked="checked" />'.&mt('Yes').'</label> '.
2834: '<label><input type="radio" name="retainsec" value="0" />'.
2835: &mt('No').'</label></span>';
2836: if ($env{'form.showrole'} eq 'Any') {
2837: $info .= '<br />'.$lt{'dnap'};
2838: }
2839: $info .= '</p>';
2840: } else {
2841: $info = '<input type="hidden" name="retainsec" value="0" />';
2842: }
2843: my $rowtitle = &mt('New section to assign');
2844: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
2845: $output .= $info.$secbox;
2846: }
2847: $output .= '<p>'.
2848: &mt('Use "Save" to update the main window with your selections.').'<br /><br />'.
2849: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
2850: '</form>';
2851: return $output;
2852: }
2853:
2854: sub section_picker {
2855: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
2856: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2857: my $sections_select .= &course_sections(\%sections_count,$role);
2858: my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
2859: if ($mode eq 'upload') {
2860: my ($options,$cb_script,$coursepick) =
2861: &default_role_selector($context,1);
2862: $secbox .= &Apache::lonhtmlcommon::row_title('role','LC_oddrow_value').
2863: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
2864: }
2865: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
2866: if ($env{'request.course.sec'} eq '') {
2867: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
2868: '<td align="center">'.&mt('Existing sections')."\n".
2869: '<br />'.$sections_select.'</td><td align="center">'.
2870: &mt('New section').'<br />'."\n".
2871: '<input type="text" name="newsec" size="15" />'."\n".
2872: '<input type="hidden" name="sections" value="" />'."\n".
2873: '</td></tr></table>'."\n";
2874: } else {
2875: $secbox .= '<input type="hidden" name="sections" value="'.
2876: $env{'request.course.sec'}.'" />'.
2877: $env{'request.course.sec'};
2878: }
2879: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
2880: &Apache::lonhtmlcommon::end_pick_box().'</p>';
2881: return $secbox;
2882: }
2883:
2884: sub results_header_row {
2885: my ($rolefilter,$statusmode,$context,$permission,$mode) = @_;
2886: my ($description,$showfilter);
2887: if ($rolefilter ne 'Any') {
2888: $showfilter = $rolefilter;
2889: }
2890: if ($context eq 'course') {
2891: if ($mode eq 'csv' || $mode eq 'excel') {
2892: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
2893: }
2894: if ($statusmode eq 'Expired') {
2895: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
2896: } elsif ($statusmode eq 'Future') {
2897: $description .= &mt('Users in course with future [_1] roles',$showfilter);
2898: } elsif ($statusmode eq 'Active') {
2899: $description .= &mt('Users in course with active [_1] roles',$showfilter);
2900: } else {
2901: if ($rolefilter eq 'Any') {
2902: $description .= &mt('All users in course');
2903: } else {
2904: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2905: }
2906: }
2907: my $constraint;
2908: my $viewablesec = &viewable_section($permission);
2909: if ($viewablesec ne '') {
2910: if ($env{'form.showrole'} eq 'st') {
2911: $constraint = &mt('only users in section "[_1]"',$viewablesec);
2912: } elsif ($env{'form.showrole'} ne 'cc') {
2913: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
2914: }
2915: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
2916: if ($env{'form.grpfilter'} eq 'none') {
2917: $constraint .= &mt(' and not in any group');
2918: } else {
2919: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
2920: }
2921: }
2922: } else {
2923: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
2924: if ($env{'form.secfilter'} eq 'none') {
2925: $constraint = &mt('only users affiliated with no section');
2926: } else {
2927: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
2928: }
2929: }
2930: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
2931: if ($env{'form.grpfilter'} eq 'none') {
2932: if ($constraint eq '') {
2933: $constraint = &mt('only users not in any group');
2934: } else {
2935: $constraint .= &mt(' and also not in any group');
2936: }
2937: } else {
2938: if ($constraint eq '') {
2939: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
2940: } else {
2941: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
2942: }
2943: }
2944: }
2945: }
2946: if ($constraint ne '') {
2947: $description .= ' ('.$constraint.')';
2948: }
2949: } elsif ($context eq 'author') {
2950: $description =
2951: &mt('Author space for <span class="LC_cusr_emph">[_1]</span>',
2952: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})).': ';
2953: if ($statusmode eq 'Expired') {
2954: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
2955: } elsif ($statusmode eq 'Future') {
2956: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
2957: } elsif ($statusmode eq 'Active') {
2958: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
2959: } else {
2960: if ($rolefilter eq 'Any') {
2961: $description .= &mt('All co-authors');
2962: } else {
2963: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2964: }
2965: }
2966: } elsif ($context eq 'domain') {
2967: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
2968: $description = &mt('Domain - ').$domdesc.': ';
2969: if ($env{'form.roletype'} eq 'domain') {
2970: if ($statusmode eq 'Expired') {
2971: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
2972: } elsif ($statusmode eq 'Future') {
2973: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
2974: } elsif ($statusmode eq 'Active') {
2975: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
2976: } else {
2977: if ($rolefilter eq 'Any') {
2978: $description .= &mt('All users in domain');
2979: } else {
2980: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
2981: }
2982: }
2983: } elsif ($env{'form.roletype'} eq 'author') {
2984: if ($statusmode eq 'Expired') {
2985: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
2986: } elsif ($statusmode eq 'Future') {
2987: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
2988: } elsif ($statusmode eq 'Active') {
2989: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
2990: } else {
2991: if ($rolefilter eq 'Any') {
2992: $description .= &mt('All users with co-author roles in domain',$showfilter);
2993: } else {
2994: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
2995: }
2996: }
2997: } elsif ($env{'form.roletype'} eq 'course') {
2998: my $coursefilter = $env{'form.coursepick'};
2999: if ($coursefilter eq 'category') {
3000: my $instcode = &instcode_from_coursefilter();
3001: if ($instcode eq '.') {
3002: $description .= &mt('All courses in domain').' - ';
3003: } else {
3004: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3005: }
3006: } elsif ($coursefilter eq 'selected') {
3007: $description .= &mt('Selected courses in domain').' - ';
3008: } elsif ($coursefilter eq 'all') {
3009: $description .= &mt('All courses in domain').' - ';
3010: }
3011: if ($statusmode eq 'Expired') {
3012: $description .= &mt('users with expired [_1] roles',$showfilter);
3013: } elsif ($statusmode eq 'Future') {
3014: $description .= &mt('users with future [_1] roles',$showfilter);
3015: } elsif ($statusmode eq 'Active') {
3016: $description .= &mt('users with active [_1] roles',$showfilter);
3017: } else {
3018: if ($rolefilter eq 'Any') {
3019: $description .= &mt('all users');
3020: } else {
3021: $description .= &mt('users with [_1] roles',$rolefilter);
3022: }
3023: }
3024: }
3025: }
3026: return $description;
3027: }
3028:
3029: sub viewable_section {
3030: my ($permission) = @_;
3031: my $viewablesec;
3032: if (ref($permission) eq 'HASH') {
3033: if (exists($permission->{'view_section'})) {
3034: $viewablesec = $permission->{'view_section'};
3035: } elsif (exists($permission->{'cusr_section'})) {
3036: $viewablesec = $permission->{'cusr_section'};
3037: }
3038: }
3039: return $viewablesec;
3040: }
3041:
3042:
3043: #################################################
3044: #################################################
3045: sub show_drop_list {
3046: my ($r,$classlist,$nosort,$permission) = @_;
3047: my $cid = $env{'request.course.id'};
3048: my ($cnum,$cdom) = &get_course_identity($cid);
3049: if (! exists($env{'form.sortby'})) {
3050: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3051: ['sortby']);
3052: }
3053: my $sortby = $env{'form.sortby'};
3054: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
3055: $sortby = 'username';
3056: }
3057: my $action = "drop";
3058: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
3059: $r->print(<<END);
3060: <input type="hidden" name="sortby" value="$sortby" />
3061: <input type="hidden" name="action" value="$action" />
3062: <input type="hidden" name="state" value="done" />
3063: <script type="text/javascript" language="Javascript">
3064: $check_uncheck_js
3065: </script>
3066: <p>
3067: <input type="hidden" name="phase" value="four">
3068: END
3069: my ($indexhash,$keylist) = &make_keylist_array();
3070: my $studentcount = 0;
3071: if (ref($classlist) eq 'HASH') {
3072: foreach my $student (keys(%{$classlist})) {
3073: my $sdata = $classlist->{$student};
3074: my $status = $sdata->[$indexhash->{'status'}];
3075: my $section = $sdata->[$indexhash->{'section'}];
3076: if ($status ne 'Active') {
3077: delete($classlist->{$student});
3078: next;
3079: }
3080: if ($env{'request.course.sec'} ne '') {
3081: if ($section ne $env{'request.course.sec'}) {
3082: delete($classlist->{$student});
3083: next;
3084: }
3085: }
3086: $studentcount ++;
3087: }
3088: }
3089: if (!$studentcount) {
3090: $r->print(&mt('There are no students to drop.'));
3091: return;
3092: }
3093: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3094: $classlist,$keylist,$cdom,$cnum);
3095: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
3096: 'dom' => "domain",
3097: 'sn' => "student name",
3098: 'sec' => "section",
3099: 'start' => "start date",
3100: 'end' => "end date",
3101: 'groups' => "active groups",
3102: );
3103: if ($nosort) {
3104: $r->print(&Apache::loncommon::start_data_table().
3105: &Apache::loncommon::start_data_table_header_row());
3106: $r->print(<<END);
3107: <th> </th>
3108: <th>$lt{'usrn'}</th>
3109: <th>$lt{'dom'}</th>
3110: <th>ID</th>
3111: <th>$lt{'sn'}</th>
3112: <th>$lt{'sec'}</th>
3113: <th>$lt{'start'}</th>
3114: <th>$lt{'end'}</th>
3115: <th>$lt{'groups'}</th>
3116: END
3117: $r->print(&Apache::loncommon::end_data_table_header_row());
3118: } else {
3119: $r->print(&Apache::loncommon::start_data_table().
3120: &Apache::loncommon::start_data_table_header_row());
3121: $r->print(<<END);
3122: <th> </th>
3123: <th>
3124: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
3125: </th><th>
3126: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
3127: </th><th>
3128: <a href="/adm/createuser?action=$action&sortby=id">ID</a>
3129: </th><th>
3130: <a href="/adm/createuser?action=$action&sortby=fullname">$lt{'sn'}</a>
3131: </th><th>
3132: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
3133: </th><th>
3134: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
3135: </th><th>
3136: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
3137: </th><th>
3138: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
3139: </th>
3140: END
3141: $r->print(&Apache::loncommon::end_data_table_header_row());
3142: }
3143: #
3144: # Sort the students
3145: my $index = $indexhash->{$sortby};
3146: my $second = $indexhash->{'username'};
3147: my $third = $indexhash->{'domain'};
3148: my @Sorted_Students = sort {
3149: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
3150: ||
3151: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
3152: ||
3153: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
3154: } (keys(%{$classlist}));
3155: foreach my $student (@Sorted_Students) {
3156: my $error;
3157: my $sdata = $classlist->{$student};
3158: my $username = $sdata->[$indexhash->{'username'}];
3159: my $domain = $sdata->[$indexhash->{'domain'}];
3160: my $section = $sdata->[$indexhash->{'section'}];
3161: my $name = $sdata->[$indexhash->{'fullname'}];
3162: my $id = $sdata->[$indexhash->{'id'}];
3163: my $start = $sdata->[$indexhash->{'start'}];
3164: my $end = $sdata->[$indexhash->{'end'}];
3165: my $groups = $classgroups->{$student};
3166: my $active_groups;
3167: if (ref($groups->{active}) eq 'HASH') {
3168: $active_groups = join(', ',keys(%{$groups->{'active'}}));
3169: }
3170: if (! defined($start) || $start == 0) {
3171: $start = &mt('none');
3172: } else {
3173: $start = &Apache::lonlocal::locallocaltime($start);
3174: }
3175: if (! defined($end) || $end == 0) {
3176: $end = &mt('none');
3177: } else {
3178: $end = &Apache::lonlocal::locallocaltime($end);
3179: }
3180: my $studentkey = $student.':'.$section;
3181: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
3182: #
3183: $r->print(&Apache::loncommon::start_data_table_row());
3184: $r->print(<<"END");
3185: <td><input type="checkbox" name="droplist" value="$studentkey"></td>
3186: <td>$username</td>
3187: <td>$domain</td>
3188: <td>$id</td>
3189: <td>$name</td>
3190: <td>$section</td>
3191: <td>$start $startitem</td>
3192: <td>$end</td>
3193: <td>$active_groups</td>
3194: END
3195: $r->print(&Apache::loncommon::end_data_table_row());
3196: }
3197: $r->print(&Apache::loncommon::end_data_table().'<br />');
3198: %lt=&Apache::lonlocal::texthash(
3199: 'dp' => "Drop Students",
3200: 'ca' => "check all",
3201: 'ua' => "uncheck all",
3202: );
3203: $r->print(<<"END");
3204: </p><p>
3205: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
3206: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
3207: <p><input type=submit value="$lt{'dp'}"></p>
3208: END
3209: return;
3210: }
3211:
3212: #
3213: # Print out the initial form to get the file containing a list of users
3214: #
3215: sub print_first_users_upload_form {
3216: my ($r,$context) = @_;
3217: my $str;
3218: $str = '<input type="hidden" name="phase" value="two">';
3219: $str .= '<input type="hidden" name="action" value="upload" />';
3220: $str .= '<input type="hidden" name="state" value="got_file" />';
3221: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
3222: $str .= &Apache::loncommon::upfile_select_html();
3223: $str .= "<p>\n";
3224: $str .= '<input type="submit" name="fileupload" value="'.
3225: &mt('Upload file of users').'">'."\n";
3226: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
3227: &mt('Ignore First Line')."</label></p>\n";
3228: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
3229: &mt("How do I create a users list from a spreadsheet")).
3230: "<br />\n";
3231: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3232: &mt("How do I create a CSV file from a spreadsheet")).
3233: "<br />\n";
3234: $str .= &Apache::loncommon::end_page();
3235: $r->print($str);
3236: return;
3237: }
3238:
3239: # ================================================= Drop/Add from uploaded file
3240: sub upfile_drop_add {
3241: my ($r,$context,$permission) = @_;
3242: &Apache::loncommon::load_tmp_file($r);
3243: my @userdata=&Apache::loncommon::upfile_record_sep();
3244: if($env{'form.noFirstLine'}){shift(@userdata);}
3245: my @keyfields = split(/\,/,$env{'form.keyfields'});
3246: my %fields=();
3247: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3248: if ($env{'form.upfile_associate'} eq 'reverse') {
3249: if ($env{'form.f'.$i} ne 'none') {
3250: $fields{$keyfields[$i]}=$env{'form.f'.$i};
3251: }
3252: } else {
3253: $fields{$env{'form.f'.$i}}=$keyfields[$i];
3254: }
3255: }
3256: if ($env{'form.fullup'} ne 'yes') {
3257: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
3258: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
3259: }
3260: #
3261: # Store the field choices away
3262: foreach my $field (qw/username names
3263: fname mname lname gen id sec ipwd email role/) {
3264: $env{'form.'.$field.'_choice'}=$fields{$field};
3265: }
3266: &Apache::loncommon::store_course_settings('enrollment_upload',
3267: { 'username_choice' => 'scalar',
3268: 'names_choice' => 'scalar',
3269: 'fname_choice' => 'scalar',
3270: 'mname_choice' => 'scalar',
3271: 'lname_choice' => 'scalar',
3272: 'gen_choice' => 'scalar',
3273: 'id_choice' => 'scalar',
3274: 'sec_choice' => 'scalar',
3275: 'ipwd_choice' => 'scalar',
3276: 'email_choice' => 'scalar',
3277: 'role_choice' => 'scalar' });
3278: #
3279: my ($startdate,$enddate) = &get_dates_from_form();
3280: if ($env{'form.makedatesdefault'}) {
3281: $r->print(&make_dates_default($startdate,$enddate,$context));
3282: }
3283: # Determine domain and desired host (home server)
3284: my $domain=$env{'request.role.domain'};
3285: my $desiredhost = $env{'form.lcserver'};
3286: if (lc($desiredhost) eq 'default') {
3287: $desiredhost = undef;
3288: } else {
3289: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
3290: if (! exists($home_servers{$desiredhost})) {
3291: $r->print('<span class="LC_error">'.&mt('Error').
3292: &mt('Invalid home server specified').'</span>');
3293: $r->print(&Apache::loncommon::end_page());
3294: return;
3295: }
3296: }
3297: # Determine authentication mechanism
3298: my $changeauth;
3299: if ($context eq 'domain') {
3300: $changeauth = $env{'form.changeauth'};
3301: }
3302: my $amode = '';
3303: my $genpwd = '';
3304: if ($env{'form.login'} eq 'krb') {
3305: $amode='krb';
3306: $amode.=$env{'form.krbver'};
3307: $genpwd=$env{'form.krbarg'};
3308: } elsif ($env{'form.login'} eq 'int') {
3309: $amode='internal';
3310: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
3311: $genpwd=$env{'form.intarg'};
3312: }
3313: } elsif ($env{'form.login'} eq 'loc') {
3314: $amode='localauth';
3315: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
3316: $genpwd=$env{'form.locarg'};
3317: }
3318: }
3319: if ($amode =~ /^krb/) {
3320: if (! defined($genpwd) || $genpwd eq '') {
3321: $r->print('<span class="Error">'.
3322: &mt('Unable to enroll users').' '.
3323: &mt('No Kerberos domain was specified.').'</span></p>');
3324: $amode = ''; # This causes the loop below to be skipped
3325: }
3326: }
3327: my ($cid,$defaultsec,$defaultrole,$setting);
3328: if ($context eq 'domain') {
3329: $setting = $env{'form.roleaction'};
3330: if ($setting eq 'domain') {
3331: $defaultrole = $env{'form.defaultrole'};
3332: } elsif ($setting eq 'course') {
3333: $defaultrole = $env{'form.courserole'};
3334: $defaultsec = $env{'form.sections'};
3335: }
3336: } elsif ($context eq 'author') {
3337: $defaultrole = $env{'form.defaultrole'};
3338: } elsif ($context eq 'course') {
3339: $defaultrole = $env{'form.defaultrole'};
3340: $defaultsec = $env{'form.sections'};
3341: }
3342: if ($env{'request.course.id'} ne '') {
3343: $cid = $env{'request.course.id'};
3344: } elsif ($setting eq 'course') {
3345: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
3346: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
3347: }
3348: }
3349: # Check to see if user information can be changed
3350: my @userinfo = ('firstname','middlename','lastname','generation',
3351: 'permanentemail','id');
3352: my %canmodify;
3353: if (&Apache::lonnet::allowed('mau',$domain)) {
3354: foreach my $field (@userinfo) {
3355: $canmodify{$field} = 1;
3356: }
3357: }
3358: my (%userlist,%modifiable_fields,@poss_roles);
3359: my $secidx = &Apache::loncoursedata::CL_SECTION();
3360: my @courseroles = &roles_by_context('course',1);
3361: if (!&Apache::lonnet::allowed('mau',$domain)) {
3362: if ($context eq 'course' || $context eq 'author') {
3363: @poss_roles = &curr_role_permissions($context);
3364: my @statuses = ('active','future');
3365: my ($indexhash,$keylist) = &make_keylist_array();
3366: my %info;
3367: foreach my $role (@poss_roles) {
3368: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
3369: \@userinfo,[$role]);
3370: }
3371: if ($context eq 'course') {
3372: my ($cnum,$cdom) = &get_course_identity();
3373: my $roster = &Apache::loncoursedata::get_classlist();
3374: %userlist = %{$roster};
3375: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
3376: \@statuses,\@poss_roles);
3377: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3378: \%advrolehash,$permission);
3379: } elsif ($context eq 'author') {
3380: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
3381: \@statuses,\@poss_roles);
3382: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3383: \%cstr_roles,$permission);
3384:
3385: }
3386: }
3387: }
3388: if ( $domain eq &LONCAPA::clean_domain($domain)
3389: && ($amode ne '')) {
3390: #######################################
3391: ## Add/Modify Users ##
3392: #######################################
3393: if ($context eq 'course') {
3394: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
3395: } elsif ($context eq 'author') {
3396: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
3397: } else {
3398: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
3399: }
3400: my %counts = (
3401: user => 0,
3402: auth => 0,
3403: role => 0,
3404: );
3405: my $flushc=0;
3406: my %student=();
3407: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
3408: my %userchg;
3409: if ($context eq 'course' || $setting eq 'course') {
3410: if ($context eq 'course') {
3411: # Get information about course groups
3412: %curr_groups = &Apache::longroup::coursegroups();
3413: } elsif ($setting eq 'course') {
3414: if ($cid) {
3415: %curr_groups =
3416: &Apache::longroup::coursegroups($env{'form.dcdomain'},
3417: $env{'form.dccourse'});
3418: }
3419: }
3420: # determine section number
3421: if ($defaultsec =~ /,/) {
3422: push(@sections,split(/,/,$defaultsec));
3423: } else {
3424: push(@sections,$defaultsec);
3425: }
3426: # remove non alphanumeric values from section
3427: foreach my $item (@sections) {
3428: $item =~ s/\W//g;
3429: if ($item eq "none" || $item eq 'all') {
3430: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
3431: } elsif ($item ne '' && exists($curr_groups{$item})) {
3432: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
3433: } elsif ($item ne '') {
3434: push(@cleansec,$item);
3435: }
3436: }
3437: if ($defaultwarn) {
3438: $r->print($defaultwarn.'<br />');
3439: }
3440: if ($groupwarn) {
3441: $r->print($groupwarn.'<br />');
3442: }
3443: }
3444: my (%curr_rules,%got_rules,%alerts);
3445: my %customroles = &my_custom_roles();
3446: my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
3447: # Get new users list
3448: foreach my $line (@userdata) {
3449: my @secs;
3450: my %entries=&Apache::loncommon::record_sep($line);
3451: # Determine user name
3452: unless (($entries{$fields{'username'}} eq '') ||
3453: (!defined($entries{$fields{'username'}}))) {
3454: my ($fname, $mname, $lname,$gen) = ('','','','');
3455: if (defined($fields{'names'})) {
3456: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
3457: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
3458: } else {
3459: if (defined($fields{'fname'})) {
3460: $fname=$entries{$fields{'fname'}};
3461: }
3462: if (defined($fields{'mname'})) {
3463: $mname=$entries{$fields{'mname'}};
3464: }
3465: if (defined($fields{'lname'})) {
3466: $lname=$entries{$fields{'lname'}};
3467: }
3468: if (defined($fields{'gen'})) {
3469: $gen=$entries{$fields{'gen'}};
3470: }
3471: }
3472: if ($entries{$fields{'username'}}
3473: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
3474: $r->print('<br />'.
3475: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
3476: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
3477: '</b>');
3478: next;
3479: } else {
3480: my $username = $entries{$fields{'username'}};
3481: if (defined($fields{'sec'})) {
3482: if (defined($entries{$fields{'sec'}})) {
3483: $entries{$fields{'sec'}} =~ s/\W//g;
3484: my $item = $entries{$fields{'sec'}};
3485: if ($item eq "none" || $item eq 'all') {
3486: $r->print('<br />'.&mt('<b>[_1]</b>: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',$username,$fname,$mname,$lname,$gen,$item));
3487: next;
3488: } elsif (exists($curr_groups{$item})) {
3489: $r->print('<br />'.&mt('<b>[_1]</b>: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',$username,$fname,$mname,$lname,$gen,$item).' '.&mt('Section names and group names must be distinct.'));
3490: next;
3491: } else {
3492: push(@secs,$item);
3493: }
3494: }
3495: }
3496: if ($env{'request.course.sec'} ne '') {
3497: @secs = ($env{'request.course.sec'});
3498: if (ref($userlist{$username.':'.$domain}) eq 'ARRAY') {
3499: my $currsec = $userlist{$username.':'.$domain}[$secidx];
3500: if ($currsec ne $env{'request.course.sec'}) {
3501: $r->print('<br />'.&mt('<b>[_1]</b>: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',$username,$fname,$mname,$lname,$gen,$secs[0]).'<br />');
3502: if ($currsec eq '') {
3503: $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
3504:
3505: } else {
3506: $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
3507: }
3508: $r->print('<br />'.&mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$secs[0]).'<br />');
3509: next;
3510: }
3511: }
3512: } elsif ($context eq 'course' || $setting eq 'course') {
3513: if (@secs == 0) {
3514: @secs = @cleansec;
3515: }
3516: }
3517: # determine id number
3518: my $id='';
3519: if (defined($fields{'id'})) {
3520: if (defined($entries{$fields{'id'}})) {
3521: $id=$entries{$fields{'id'}};
3522: }
3523: $id=~tr/A-Z/a-z/;
3524: }
3525: # determine email address
3526: my $email='';
3527: if (defined($fields{'email'})) {
3528: if (defined($entries{$fields{'email'}})) {
3529: $email=$entries{$fields{'email'}};
3530: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
3531: }
3532: # determine user password
3533: my $password = $genpwd;
3534: if (defined($fields{'ipwd'})) {
3535: if ($entries{$fields{'ipwd'}}) {
3536: $password=$entries{$fields{'ipwd'}};
3537: }
3538: }
3539: # determine user role
3540: my $role = '';
3541: if (defined($fields{'role'})) {
3542: if ($entries{$fields{'role'}}) {
3543: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
3544: if ($entries{$fields{'role'}} ne '') {
3545: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
3546: $role = $entries{$fields{'role'}};
3547: }
3548: }
3549: if ($role eq '') {
3550: my $rolestr = join(', ',@permitted_roles);
3551: $r->print('<br />'.
3552: &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");
3553: next;
3554: }
3555: }
3556: }
3557: if ($role eq '') {
3558: $role = $defaultrole;
3559: }
3560: # Clean up whitespace
3561: foreach (\$domain,\$username,\$id,\$fname,\$mname,
3562: \$lname,\$gen) {
3563: $$_ =~ s/(\s+$|^\s+)//g;
3564: }
3565: # check against rules
3566: my $checkid = 0;
3567: my $newuser = 0;
3568: my (%rulematch,%inst_results,%idinst_results);
3569: my $uhome=&Apache::lonnet::homeserver($username,$domain);
3570: if ($uhome eq 'no_host') {
3571: $checkid = 1;
3572: $newuser = 1;
3573: my $checkhash;
3574: my $checks = { 'username' => 1 };
3575: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3576: &Apache::loncommon::user_rule_check($checkhash,$checks,
3577: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3578: \%got_rules);
3579: if (ref($alerts{'username'}) eq 'HASH') {
3580: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3581: next if ($alerts{'username'}{$domain}{$username});
3582: }
3583: }
3584: } else {
3585: if ($context eq 'course' || $context eq 'author') {
3586: if ($role eq '') {
3587: my @checkroles;
3588: foreach my $role (@poss_roles) {
3589: my $endkey;
3590: if ($role ne 'st') {
3591: $endkey = ':'.$role;
3592: }
3593: if (exists($userlist{$username.':'.$domain.$endkey})) {
3594: if (!grep(/^\Q$role\E$/,@checkroles)) {
3595: push(@checkroles,$role);
3596: }
3597: }
3598: }
3599: if (@checkroles > 0) {
3600: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
3601: }
3602: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
3603: %canmodify = %{$modifiable_fields{$role}};
3604: }
3605: }
3606: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
3607: for (my $i=0; $i<@userinfo; $i++) {
3608: if (${$newinfo[$i]} ne '') {
3609: if (!$canmodify{$userinfo[$i]}) {
3610: ${$newinfo[$i]} = '';
3611: }
3612: }
3613: }
3614: }
3615: if ($id ne '') {
3616: if (!$newuser) {
3617: my %idhash = &Apache::lonnet::idrget($domain,($username));
3618: if ($idhash{$username} ne $id) {
3619: $checkid = 1;
3620: }
3621: }
3622: if ($checkid) {
3623: my $checkhash;
3624: my $checks = { 'id' => 1 };
3625: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
3626: 'id' => $id };
3627: &Apache::loncommon::user_rule_check($checkhash,$checks,
3628: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3629: \%got_rules);
3630: if (ref($alerts{'id'}) eq 'HASH') {
3631: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
3632: next if ($alerts{'id'}{$domain}{$id});
3633: }
3634: }
3635: }
3636: }
3637: if ($password || $env{'form.login'} eq 'loc') {
3638: my $multiple = 0;
3639: my ($userresult,$authresult,$roleresult,$idresult);
3640: my (%userres,%authres,%roleres,%idres);
3641: my $singlesec = '';
3642: if ($role eq 'st') {
3643: my $sec;
3644: if (@secs > 0) {
3645: $sec = $secs[0];
3646: }
3647: &modifystudent($domain,$username,$cid,$sec,
3648: $desiredhost);
3649: $roleresult =
3650: &Apache::lonnet::modifystudent
3651: ($domain,$username,$id,$amode,$password,
3652: $fname,$mname,$lname,$gen,$sec,$enddate,
3653: $startdate,$env{'form.forceid'},
3654: $desiredhost,$email,'manual','',$cid);
3655: $userresult = $roleresult;
3656: } else {
3657: if ($role ne '') {
3658: if ($context eq 'course' || $setting eq 'course') {
3659: if ($customroles{$role}) {
3660: $role = 'cr_'.$env{'user.domain'}.'_'.
3661: $env{'user.name'}.'_'.$role;
3662: }
3663: if ($role ne 'cc') {
3664: if (@secs > 1) {
3665: $multiple = 1;
3666: foreach my $sec (@secs) {
3667: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
3668: &modifyuserrole($context,$setting,
3669: $changeauth,$cid,$domain,$username,
3670: $id,$amode,$password,$fname,
3671: $mname,$lname,$gen,$sec,
3672: $env{'form.forceid'},$desiredhost,
3673: $email,$role,$enddate,
3674: $startdate,$checkid);
3675: }
3676: } elsif (@secs > 0) {
3677: $singlesec = $secs[0];
3678: }
3679: }
3680: }
3681: }
3682: if (!$multiple) {
3683: ($userresult,$authresult,$roleresult,$idresult) =
3684: &modifyuserrole($context,$setting,
3685: $changeauth,$cid,$domain,$username,
3686: $id,$amode,$password,$fname,
3687: $mname,$lname,$gen,$singlesec,
3688: $env{'form.forceid'},$desiredhost,
3689: $email,$role,$enddate,$startdate,$checkid);
3690: }
3691: }
3692: if ($multiple) {
3693: foreach my $sec (sort(keys(%userres))) {
3694: $flushc =
3695: &user_change_result($r,$userres{$sec},$authres{$sec},
3696: $roleres{$sec},$idres{$sec},\%counts,$flushc,
3697: $username,\%userchg);
3698:
3699: }
3700: } else {
3701: $flushc =
3702: &user_change_result($r,$userresult,$authresult,
3703: $roleresult,$idresult,\%counts,$flushc,
3704: $username,\%userchg);
3705: }
3706: } else {
3707: if ($context eq 'course') {
3708: $r->print('<br />'.
3709: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
3710: );
3711: } elsif ($context eq 'author') {
3712: $r->print('<br />'.
3713: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
3714: );
3715: } else {
3716: $r->print('<br />'.
3717: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
3718: );
3719: }
3720: }
3721: }
3722: }
3723: } # end of foreach (@userdata)
3724: # Flush the course logs so reverse user roles immediately updated
3725: &Apache::lonnet::flushcourselogs();
3726: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
3727: "</p>\n");
3728: if ($counts{'role'} > 0) {
3729: $r->print("<p>\n".
3730: &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."</p>\n");
3731: } else {
3732: $r->print('<p>'.&mt('No roles added').'</p>');
3733: }
3734: if ($counts{'auth'} > 0) {
3735: $r->print("<p>\n".
3736: &mt('Authentication changed for [_1] existing users.',
3737: $counts{'auth'})."</p>\n");
3738: }
3739: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
3740: #####################################
3741: # Display list of students to drop #
3742: #####################################
3743: if ($env{'form.fullup'} eq 'yes') {
3744: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
3745: # Get current classlist
3746: my $classlist = &Apache::loncoursedata::get_classlist();
3747: if (! defined($classlist)) {
3748: $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
3749: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
3750: &mt('There are no students with current/future access to the course.').
3751: '</form>'."\n");
3752: } else {
3753: # Remove the students we just added from the list of students.
3754: foreach my $line (@userdata) {
3755: my %entries=&Apache::loncommon::record_sep($line);
3756: unless (($entries{$fields{'username'}} eq '') ||
3757: (!defined($entries{$fields{'username'}}))) {
3758: delete($classlist->{$entries{$fields{'username'}}.
3759: ':'.$domain});
3760: }
3761: }
3762: # Print out list of dropped students.
3763: &show_drop_list($r,$classlist,'nosort',$permission);
3764: }
3765: }
3766: } # end of unless
3767: if ($env{'form.fullup'} ne 'yes') {
3768: $r->print('</form>');
3769: }
3770: }
3771:
3772: sub print_namespacing_alerts {
3773: my ($domain,$alerts,$curr_rules) = @_;
3774: my $output;
3775: if (ref($alerts) eq 'HASH') {
3776: if (keys(%{$alerts}) > 0) {
3777: if (ref($alerts->{'username'}) eq 'HASH') {
3778: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
3779: my $count;
3780: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
3781: $count = keys(%{$alerts->{'username'}{$dom}});
3782: }
3783: my $domdesc = &Apache::lonnet::domain($domain,'description');
3784: if (ref($curr_rules->{$dom}) eq 'HASH') {
3785: $output .= &Apache::loncommon::instrule_disallow_msg(
3786: 'username',$domdesc,$count,'upload');
3787: }
3788: $output .= &Apache::loncommon::user_rule_formats($dom,
3789: $domdesc,$curr_rules->{$dom}{'username'},
3790: 'username');
3791: }
3792: }
3793: if (ref($alerts->{'id'}) eq 'HASH') {
3794: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
3795: my $count;
3796: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
3797: $count = keys(%{$alerts->{'id'}{$dom}});
3798: }
3799: my $domdesc = &Apache::lonnet::domain($domain,'description');
3800: if (ref($curr_rules->{$dom}) eq 'HASH') {
3801: $output .= &Apache::loncommon::instrule_disallow_msg(
3802: 'id',$domdesc,$count,'upload');
3803: }
3804: $output .= &Apache::loncommon::user_rule_formats($dom,
3805: $domdesc,$curr_rules->{$dom}{'id'},'id');
3806: }
3807: }
3808: }
3809: }
3810: }
3811:
3812: sub user_change_result {
3813: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
3814: $username,$userchg) = @_;
3815: my $okresult = 0;
3816: if ($userresult ne 'ok') {
3817: if ($userresult =~ /^error:(.+)$/) {
3818: my $error = $1;
3819: $r->print('<br />'.
3820: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
3821: }
3822: } else {
3823: $counts->{'user'} ++;
3824: $okresult = 1;
3825: }
3826: if ($authresult ne 'ok') {
3827: if ($authresult =~ /^error:(.+)$/) {
3828: my $error = $1;
3829: $r->print('<br />'.
3830: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
3831: }
3832: } else {
3833: $counts->{'auth'} ++;
3834: $okresult = 1;
3835: }
3836: if ($roleresult ne 'ok') {
3837: if ($roleresult =~ /^error:(.+)$/) {
3838: my $error = $1;
3839: $r->print('<br />'.
3840: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
3841: }
3842: } else {
3843: $counts->{'role'} ++;
3844: $okresult = 1;
3845: }
3846: if ($okresult) {
3847: $flushc++;
3848: $userchg->{$username}=1;
3849: $r->print('. ');
3850: if ($flushc>15) {
3851: $r->rflush;
3852: $flushc=0;
3853: }
3854: }
3855: if ($idresult) {
3856: $r->print($idresult);
3857: }
3858: return $flushc;
3859: }
3860:
3861: # ========================================================= Menu Phase Two Drop
3862: sub print_drop_menu {
3863: my ($r,$context,$permission) = @_;
3864: $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
3865: '<form name="studentform" method="post">'."\n");
3866: my $classlist = &Apache::loncoursedata::get_classlist();
3867: if (! defined($classlist)) {
3868: $r->print(&mt('There are no students currently enrolled.')."\n");
3869: } else {
3870: &show_drop_list($r,$classlist,'nosort',$permission);
3871: }
3872: $r->print('</form>'. &Apache::loncommon::end_page());
3873: return;
3874: }
3875:
3876: # ================================================================== Phase four
3877:
3878: sub update_user_list {
3879: my ($r,$context,$setting,$choice) = @_;
3880: my $now = time;
3881: my $count=0;
3882: my @changelist;
3883: if ($choice eq 'drop') {
3884: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
3885: } else {
3886: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
3887: }
3888: my %result_text = ( ok => { 'revoke' => 'Revoked',
3889: 'delete' => 'Deleted',
3890: 'reenable' => 'Re-enabled',
3891: 'activate' => 'Activated',
3892: 'chgdates' => 'Changed Access Dates for',
3893: 'chgsec' => 'Changed section for',
3894: 'drop' => 'Dropped',
3895: },
3896: error => {'revoke' => 'revoking',
3897: 'delete' => 'deleting',
3898: 'reenable' => 're-enabling',
3899: 'activate' => 'activating',
3900: 'chgdates' => 'changing access dates for',
3901: 'chgsec' => 'changing section for',
3902: 'drop' => 'dropping',
3903: },
3904: );
3905: my ($startdate,$enddate);
3906: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
3907: ($startdate,$enddate) = &get_dates_from_form();
3908: }
3909: foreach my $item (@changelist) {
3910: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
3911: $scopestem);
3912: if ($choice eq 'drop') {
3913: ($uname,$udom,$sec) = split(/:/,$item,-1);
3914: $role = 'st';
3915: $cid = $env{'request.course.id'};
3916: $scopestem = '/'.$cid;
3917: $scopestem =~s/\_/\//g;
3918: if ($sec eq '') {
3919: $scope = $scopestem;
3920: } else {
3921: $scope = $scopestem.'/'.$sec;
3922: }
3923: } elsif ($context eq 'course') {
3924: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
3925: $cid = $env{'request.course.id'};
3926: $scopestem = '/'.$cid;
3927: $scopestem =~s/\_/\//g;
3928: if ($sec eq '') {
3929: $scope = $scopestem;
3930: } else {
3931: $scope = $scopestem.'/'.$sec;
3932: }
3933: } elsif ($context eq 'author') {
3934: ($uname,$udom,$role) = split(/\:/,$item,-1);
3935: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
3936: } elsif ($context eq 'domain') {
3937: if ($setting eq 'domain') {
3938: ($role,$uname,$udom) = split(/\:/,$item,-1);
3939: $scope = '/'.$env{'request.role.domain'}.'/';
3940: } elsif ($setting eq 'author') {
3941: ($uname,$udom,$role,$scope) = split(/\:/,$item);
3942: } elsif ($setting eq 'course') {
3943: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
3944: split(/\:/,$item);
3945: $scope = '/'.$cid;
3946: $scope =~s/\_/\//g;
3947: if ($sec ne '') {
3948: $scope .= '/'.$sec;
3949: }
3950: }
3951: }
3952: my $plrole = &Apache::lonnet::plaintext($role);
3953: my $start = $env{'form.'.$item.'_start'};
3954: my $end = $env{'form.'.$item.'_end'};
3955: if ($choice eq 'drop') {
3956: # drop students
3957: $end = $now;
3958: $type = 'manual';
3959: $result =
3960: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3961: } elsif ($choice eq 'revoke') {
3962: # revoke or delete user role
3963: $end = $now;
3964: if ($role eq 'st') {
3965: $result =
3966: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3967: } else {
3968: $result =
3969: &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
3970: }
3971: } elsif ($choice eq 'delete') {
3972: if ($role eq 'st') {
3973: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid);
3974: }
3975: $result =
3976: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
3977: $start,1);
3978: } else {
3979: #reenable, activate, change access dates or change section
3980: if ($choice ne 'chgsec') {
3981: $start = $startdate;
3982: $end = $enddate;
3983: }
3984: if ($choice eq 'reenable') {
3985: if ($role eq 'st') {
3986: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3987: } else {
3988: $result =
3989: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3990: $now);
3991: }
3992: } elsif ($choice eq 'activate') {
3993: if ($role eq 'st') {
3994: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
3995: } else {
3996: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
3997: $now);
3998: }
3999: } elsif ($choice eq 'chgdates') {
4000: if ($role eq 'st') {
4001: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
4002: } else {
4003: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
4004: $start);
4005: }
4006: } elsif ($choice eq 'chgsec') {
4007: my (@newsecs,$revresult,$nochg,@retained);
4008: if ($role ne 'cc') {
4009: @newsecs = split(/,/,$env{'form.newsecs'});
4010: }
4011: # remove existing section if not to be retained.
4012: if (!$env{'form.retainsec'}) {
4013: if ($sec eq '') {
4014: if (@newsecs == 0) {
4015: $result = &mt('No change in section assignment (none)');
4016: $nochg = 1;
4017: } else {
4018: $revresult =
4019: &Apache::lonnet::revokerole($udom,$uname,
4020: $scope,$role);
4021: }
4022: } else {
4023: if (@newsecs > 0) {
4024: if (grep(/^\Q$sec\E$/,@newsecs)) {
4025: push(@retained,$sec);
4026: } else {
4027: $revresult =
4028: &Apache::lonnet::revokerole($udom,$uname,
4029: $scope,$role);
4030: }
4031: } else {
4032: $revresult =
4033: &Apache::lonnet::revokerole($udom,$uname,
4034: $scope,$role);
4035: }
4036: }
4037: } else {
4038: if ($sec eq '') {
4039: $nochg = 1;
4040: } else {
4041: push(@retained,$sec);
4042: }
4043: }
4044: # add new sections
4045: if (@newsecs == 0) {
4046: if (!$nochg) {
4047: if ($role eq 'st') {
4048: $result =
4049: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
4050: } else {
4051: my $newscope = $scopestem;
4052: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
4053: }
4054: }
4055: } else {
4056: foreach my $newsec (@newsecs) {
4057: if (!grep(/^\Q$newsec\E$/,@retained)) {
4058: if ($role eq 'st') {
4059: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid);
4060: } else {
4061: my $newscope = $scopestem;
4062: if ($newsec ne '') {
4063: $newscope .= '/'.$newsec;
4064: }
4065: $result = &Apache::lonnet::assignrole($udom,$uname,
4066: $newscope,$role,$end,$start);
4067: }
4068: }
4069: }
4070: }
4071: }
4072: }
4073: my $extent = $scope;
4074: if ($choice eq 'drop' || $context eq 'course') {
4075: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
4076: if ($cdesc) {
4077: $extent = $cdesc;
4078: }
4079: }
4080: if ($result eq 'ok' || $result eq 'ok:') {
4081: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
4082: $plrole,$extent,$uname.':'.$udom).'<br />');
4083: $count++;
4084: } else {
4085: $r->print(
4086: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
4087: $plrole,$extent,$uname.':'.$udom,$result).'<br />');
4088: }
4089: }
4090: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
4091: if ($choice eq 'drop') {
4092: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
4093: '<input type="hidden" name="Status" value="Active" />'."\n".
4094: '<input type="hidden" name="showrole" value="st" />'."\n");
4095: } else {
4096: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
4097: if ($env{'form.'.$item} ne '') {
4098: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
4099: '" />'."\n");
4100: }
4101: }
4102: }
4103: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
4104: if ($count > 0) {
4105: if ($choice eq 'revoke' || $choice eq 'drop') {
4106: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>'));
4107: }
4108: # Flush the course logs so reverse user roles immediately updated
4109: &Apache::lonnet::flushcourselogs();
4110: }
4111: if ($env{'form.makedatesdefault'}) {
4112: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
4113: $r->print(&make_dates_default($startdate,$enddate,$context));
4114: }
4115: }
4116: my $linktext = &mt('Display User Lists');
4117: if ($choice eq 'drop') {
4118: $linktext = &mt('Display current class roster');
4119: }
4120: $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
4121: }
4122:
4123: sub classlist_drop {
4124: my ($scope,$uname,$udom,$now) = @_;
4125: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
4126: if (&Apache::lonnet::is_course($cdom,$cnum)) {
4127: my $user = $uname.':'.$udom;
4128: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
4129: my $result =
4130: &Apache::lonnet::cput('classlist',
4131: { $user => $now },$cdom,$cnum);
4132: return &mt('Drop from classlist: [_1]',
4133: '<b>'.$result.'</b>').'<br />';
4134: }
4135: }
4136: }
4137:
4138: sub active_student_roles {
4139: my ($cnum,$cdom,$uname,$udom) = @_;
4140: my %roles =
4141: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
4142: ['future','active'],['st']);
4143: return exists($roles{"$cnum:$cdom:st"});
4144: }
4145:
4146: sub section_check_js {
4147: my $groupslist= &get_groupslist();
4148: return <<"END";
4149: function validate(caller) {
4150: var groups = new Array($groupslist);
4151: var secname = caller.value;
4152: if ((secname == 'all') || (secname == 'none')) {
4153: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
4154: return 'error';
4155: }
4156: if (secname != '') {
4157: for (var k=0; k<groups.length; k++) {
4158: if (secname == groups[k]) {
4159: 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.");
4160: return 'error';
4161: }
4162: }
4163: }
4164: return 'ok';
4165: }
4166: END
4167: }
4168:
4169: sub set_login {
4170: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
4171: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4172: my $response;
4173: my ($authnum,%can_assign) =
4174: &Apache::loncommon::get_assignable_auth($dom);
4175: if ($authnum) {
4176: $response = &Apache::loncommon::start_data_table();
4177: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
4178: $response .= &Apache::loncommon::start_data_table_row().
4179: '<td>'.$authformkrb.'</td>'.
4180: &Apache::loncommon::end_data_table_row()."\n";
4181: }
4182: if ($can_assign{'int'}) {
4183: $response .= &Apache::loncommon::start_data_table_row().
4184: '<td>'.$authformint.'</td>'.
4185: &Apache::loncommon::end_data_table_row()."\n"
4186: }
4187: if ($can_assign{'loc'}) {
4188: $response .= &Apache::loncommon::start_data_table_row().
4189: '<td>'.$authformloc.'</td>'.
4190: &Apache::loncommon::end_data_table_row()."\n";
4191: }
4192: $response .= &Apache::loncommon::end_data_table();
4193: }
4194: return $response;
4195: }
4196:
4197: sub course_sections {
4198: my ($sections_count,$role) = @_;
4199: my $output = '';
4200: my @sections = (sort {$a <=> $b} keys %{$sections_count});
4201: my $numsec = scalar(@sections);
4202: if ($numsec <= 1) {
4203: $output = '<select name="currsec_'.$role.'" >'."\n".
4204: ' <option value="">'.&mt('Select').'</option>'."\n".
4205: ' <option value="">'.&mt('No section').'</option>'."\n";
4206: if ($numsec == 1) {
4207: $output .=
4208: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
4209: }
4210: } else {
4211: $output = '<select name="currsec_'.$role.'" ';
4212: my $multiple = 4;
4213: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
4214: if ($role eq 'st') {
4215: $output .= '>'."\n".
4216: ' <option value="">'.&mt('Select').'</option>'."\n".
4217: ' <option value="">'.&mt('No section')."</option>\n";
4218: } else {
4219: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
4220: }
4221: foreach my $sec (@sections) {
4222: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
4223: }
4224: }
4225: $output .= '</select>';
4226: return $output;
4227: }
4228:
4229: sub get_groupslist {
4230: my $groupslist;
4231: my %curr_groups = &Apache::longroup::coursegroups();
4232: if (%curr_groups) {
4233: $groupslist = join('","',sort(keys(%curr_groups)));
4234: $groupslist = '"'.$groupslist.'"';
4235: }
4236: return $groupslist;
4237: }
4238:
4239: sub setsections_javascript {
4240: my ($formname,$groupslist,$mode,$checkauth) = @_;
4241: my ($checkincluded,$finish,$rolecode,$setsection_js);
4242: if ($mode eq 'upload') {
4243: $checkincluded = 'formname.name == "'.$formname.'"';
4244: $finish = "return 'ok';";
4245: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
4246: } elsif ($formname eq 'cu') {
4247: $checkincluded = 'formname.elements[i-1].checked == true';
4248: if ($checkauth) {
4249: $finish = "var authcheck = auth_check();\n".
4250: " if (authcheck == 'ok') {\n".
4251: " formname.submit();\n".
4252: " }\n";
4253: } else {
4254: $finish = 'formname.submit()';
4255: }
4256: $rolecode = "var match = str.split('_');
4257: var role = match[3];\n";
4258: } elsif ($formname eq 'enrollstudent') {
4259: $checkincluded = 'formname.name == "'.$formname.'"';
4260: if ($checkauth) {
4261: $finish = "var authcheck = auth_check();\n".
4262: " if (authcheck == 'ok') {\n".
4263: " formname.submit();\n".
4264: " }\n";
4265: } else {
4266: $finish = 'formname.submit()';
4267: }
4268: $rolecode = "var match = str.split('_');
4269: var role = match[1];\n";
4270: } else {
4271: $checkincluded = 'formname.name == "'.$formname.'"';
4272: $finish = "seccheck = 'ok';";
4273: $rolecode = "var match = str.split('_');
4274: var role = match[1];\n";
4275: $setsection_js = "var seccheck = 'alert';";
4276: }
4277: my %alerts = &Apache::lonlocal::texthash(
4278: secd => 'Section designations do not apply to Course Coordinator roles.',
4279: accr => 'A course coordinator role will be added with access to all sections.',
4280: inea => 'In each course, each user may only have one student role at a time.',
4281: youh => 'You had selected ',
4282: secs => 'sections.',
4283: plmo => 'Please modify your selections so they include no more than one section.',
4284: mayn => 'may not be used as the name for a section, as it is a reserved word.',
4285: plch => 'Please choose a different section name.',
4286: mnot => 'may not be used as a section name, as it is the name of a course group.',
4287: secn => 'Section names and group names must be distinct. Please choose a different section name.',
4288: );
4289: $setsection_js .= <<"ENDSECCODE";
4290:
4291: function setSections(formname) {
4292: var re1 = /^currsec_/;
4293: var groups = new Array($groupslist);
4294: for (var i=0;i<formname.elements.length;i++) {
4295: var str = formname.elements[i].name;
4296: var checkcurr = str.match(re1);
4297: if (checkcurr != null) {
4298: if ($checkincluded) {
4299: $rolecode
4300: if (role == 'cc') {
4301: alert("$alerts{'secd'}\\n$alerts{'accr'}");
4302: }
4303: else {
4304: var sections = '';
4305: var numsec = 0;
4306: var sections;
4307: for (var j=0; j<formname.elements[i].length; j++) {
4308: if (formname.elements[i].options[j].selected == true ) {
4309: if (formname.elements[i].options[j].value != "") {
4310: if (numsec == 0) {
4311: if (formname.elements[i].options[j].value != "") {
4312: sections = formname.elements[i].options[j].value;
4313: numsec ++;
4314: }
4315: }
4316: else {
4317: sections = sections + "," + formname.elements[i].options[j].value
4318: numsec ++;
4319: }
4320: }
4321: }
4322: }
4323: if (numsec > 0) {
4324: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
4325: sections = sections + "," + formname.elements[i+1].value;
4326: }
4327: }
4328: else {
4329: sections = formname.elements[i+1].value;
4330: }
4331: var newsecs = formname.elements[i+1].value;
4332: var numsplit;
4333: if (newsecs != null && newsecs != "") {
4334: numsplit = newsecs.split(/,/g);
4335: numsec = numsec + numsplit.length;
4336: }
4337:
4338: if ((role == 'st') && (numsec > 1)) {
4339: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
4340: return;
4341: }
4342: else {
4343: if (numsplit != null) {
4344: for (var j=0; j<numsplit.length; j++) {
4345: if ((numsplit[j] == 'all') ||
4346: (numsplit[j] == 'none')) {
4347: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
4348: return;
4349: }
4350: for (var k=0; k<groups.length; k++) {
4351: if (numsplit[j] == groups[k]) {
4352: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
4353: return;
4354: }
4355: }
4356: }
4357: }
4358: formname.elements[i+2].value = sections;
4359: }
4360: }
4361: }
4362: }
4363: }
4364: $finish
4365: }
4366: ENDSECCODE
4367: return $setsection_js;
4368: }
4369:
4370: sub can_create_user {
4371: my ($dom,$context,$usertype) = @_;
4372: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4373: my $cancreate = 1;
4374: if (&Apache::lonnet::allowed('mau',$dom)) {
4375: return $cancreate;
4376: }
4377: if (ref($domconf{'usercreation'}) eq 'HASH') {
4378: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
4379: if ($context eq 'course' || $context eq 'author') {
4380: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
4381: if ($creation eq 'none') {
4382: $cancreate = 0;
4383: } elsif ($creation ne 'any') {
4384: if (defined($usertype)) {
4385: if ($creation ne $usertype) {
4386: $cancreate = 0;
4387: }
4388: }
4389: }
4390: }
4391: }
4392: }
4393: return $cancreate;
4394: }
4395:
4396: sub can_modify_userinfo {
4397: my ($context,$dom,$fields,$userroles) = @_;
4398: my %domconfig =
4399: &Apache::lonnet::get_dom('configuration',['usermodification'],
4400: $dom);
4401: my %canmodify;
4402: if (ref($fields) eq 'ARRAY') {
4403: foreach my $field (@{$fields}) {
4404: $canmodify{$field} = 0;
4405: if (&Apache::lonnet::allowed('mau',$dom)) {
4406: $canmodify{$field} = 1;
4407: } else {
4408: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4409: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
4410: if (ref($userroles) eq 'ARRAY') {
4411: foreach my $role (@{$userroles}) {
4412: my $testrole;
4413: if ($role =~ /^cr\//) {
4414: $testrole = 'cr';
4415: } else {
4416: $testrole = $role;
4417: }
4418: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
4419: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
4420: $canmodify{$field} = 1;
4421: last;
4422: }
4423: }
4424: }
4425: } else {
4426: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
4427: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
4428: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
4429: $canmodify{$field} = 1;
4430: last;
4431: }
4432: }
4433: }
4434: }
4435: }
4436: } elsif ($context eq 'course') {
4437: if (ref($userroles) eq 'ARRAY') {
4438: if (grep(/^st$/,@{$userroles})) {
4439: $canmodify{$field} = 1;
4440: }
4441: } else {
4442: $canmodify{$field} = 1;
4443: }
4444: }
4445: }
4446: }
4447: }
4448: return %canmodify;
4449: }
4450:
4451: sub check_usertype {
4452: my ($dom,$uname,$rules) = @_;
4453: my $usertype;
4454: if (ref($rules) eq 'HASH') {
4455: my @user_rules = keys(%{$rules});
4456: if (@user_rules > 0) {
4457: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
4458: if (keys(%rule_check) > 0) {
4459: $usertype = 'unofficial';
4460: foreach my $item (keys(%rule_check)) {
4461: if ($rule_check{$item}) {
4462: $usertype = 'official';
4463: last;
4464: }
4465: }
4466: }
4467: }
4468: }
4469: return $usertype;
4470: }
4471:
4472: sub roles_by_context {
4473: my ($context,$custom) = @_;
4474: my @allroles;
4475: if ($context eq 'course') {
4476: @allroles = ('st','ad','ta','ep','in','cc');
4477: if ($custom) {
4478: push(@allroles,'cr');
4479: }
4480: } elsif ($context eq 'author') {
4481: @allroles = ('ca','aa');
4482: } elsif ($context eq 'domain') {
4483: @allroles = ('li','dg','sc','au','dc');
4484: }
4485: return @allroles;
4486: }
4487:
4488: sub get_permission {
4489: my ($context,$roles) = @_;
4490: my %permission;
4491: if ($context eq 'course') {
4492: my $custom = 1;
4493: my @allroles = &roles_by_context($context,$custom);
4494: foreach my $role (@allroles) {
4495: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
4496: $permission{'cusr'} = 1;
4497: last;
4498: }
4499: }
4500: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
4501: $permission{'custom'} = 1;
4502: }
4503: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
4504: $permission{'view'} = 1;
4505: }
4506: if (!$permission{'view'}) {
4507: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4508: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
4509: if ($permission{'view'}) {
4510: $permission{'view_section'} = $env{'request.course.sec'};
4511: }
4512: }
4513: if (!$permission{'cusr'}) {
4514: if ($env{'request.course.sec'} ne '') {
4515: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4516: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
4517: if ($permission{'cusr'}) {
4518: $permission{'cusr_section'} = $env{'request.course.sec'};
4519: }
4520: }
4521: }
4522: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
4523: $permission{'grp_manage'} = 1;
4524: }
4525: } elsif ($context eq 'author') {
4526: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
4527: $permission{'view'} = $permission{'cusr'};
4528: } else {
4529: my @allroles = &roles_by_context($context);
4530: foreach my $role (@allroles) {
4531: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
4532: $permission{'cusr'} = 1;
4533: last;
4534: }
4535: }
4536: if (!$permission{'cusr'}) {
4537: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
4538: $permission{'cusr'} = 1;
4539: }
4540: }
4541: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
4542: $permission{'custom'} = 1;
4543: }
4544: $permission{'view'} = $permission{'cusr'};
4545: }
4546: my $allowed = 0;
4547: foreach my $perm (values(%permission)) {
4548: if ($perm) { $allowed=1; last; }
4549: }
4550: return (\%permission,$allowed);
4551: }
4552:
4553: # ==================================================== Figure out author access
4554:
4555: sub authorpriv {
4556: my ($auname,$audom)=@_;
4557: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
4558: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
4559: }
4560:
4561: sub roles_on_upload {
4562: my ($context,$setting,%customroles) = @_;
4563: my (@possible_roles,@permitted_roles);
4564: @possible_roles = &curr_role_permissions($context,$setting,1);
4565: foreach my $role (@possible_roles) {
4566: if ($role eq 'cr') {
4567: push(@permitted_roles,keys(%customroles));
4568: } else {
4569: push(@permitted_roles,$role);
4570: }
4571: }
4572: return @permitted_roles;
4573: }
4574:
4575: sub get_course_identity {
4576: my ($cid) = @_;
4577: my ($cnum,$cdom,$cdesc);
4578: if ($cid eq '') {
4579: $cid = $env{'request.course.id'}
4580: }
4581: if ($cid ne '') {
4582: $cnum = $env{'course.'.$cid.'.num'};
4583: $cdom = $env{'course.'.$cid.'.domain'};
4584: $cdesc = $env{'course.'.$cid.'.description'};
4585: if ($cnum eq '' || $cdom eq '') {
4586: my %coursehash =
4587: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
4588: $cdom = $coursehash{'domain'};
4589: $cnum = $coursehash{'num'};
4590: $cdesc = $coursehash{'description'};
4591: }
4592: }
4593: return ($cnum,$cdom,$cdesc);
4594: }
4595:
4596: sub dc_setcourse_js {
4597: my ($formname,$mode,$context) = @_;
4598: my ($dc_setcourse_code,$authen_check);
4599: my $cctext = &Apache::lonnet::plaintext('cc');
4600: my %alerts = §ioncheck_alerts();
4601: my $role = 'role';
4602: if ($mode eq 'upload') {
4603: $role = 'courserole';
4604: } else {
4605: $authen_check = &verify_authen($formname,$context);
4606: }
4607: $dc_setcourse_code = (<<"SCRIPTTOP");
4608: $authen_check
4609:
4610: function setCourse() {
4611: var course = document.$formname.dccourse.value;
4612: if (course != "") {
4613: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
4614: alert("$alerts{'curd'}");
4615: return;
4616: }
4617: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
4618: var section="";
4619: var numsections = 0;
4620: var newsecs = new Array();
4621: for (var i=0; i<document.$formname.currsec.length; i++) {
4622: if (document.$formname.currsec.options[i].selected == true ) {
4623: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
4624: if (numsections == 0) {
4625: section = document.$formname.currsec.options[i].value
4626: numsections = 1;
4627: }
4628: else {
4629: section = section + "," + document.$formname.currsec.options[i].value
4630: numsections ++;
4631: }
4632: }
4633: }
4634: }
4635: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
4636: if (numsections == 0) {
4637: section = document.$formname.newsec.value
4638: }
4639: else {
4640: section = section + "," + document.$formname.newsec.value
4641: }
4642: newsecs = document.$formname.newsec.value.split(/,/g);
4643: numsections = numsections + newsecs.length;
4644: }
4645: if ((userrole == 'st') && (numsections > 1)) {
4646: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
4647: return;
4648: }
4649: for (var j=0; j<newsecs.length; j++) {
4650: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
4651: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
4652: return;
4653: }
4654: if (document.$formname.groups.value != '') {
4655: var groups = document.$formname.groups.value.split(/,/g);
4656: for (var k=0; k<groups.length; k++) {
4657: if (newsecs[j] == groups[k]) {
4658: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
4659: return;
4660: }
4661: }
4662: }
4663: }
4664: if ((userrole == 'cc') && (numsections > 0)) {
4665: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
4666: section = "";
4667: }
4668: SCRIPTTOP
4669: if ($mode ne 'upload') {
4670: $dc_setcourse_code .= (<<"ENDSCRIPT");
4671: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
4672: var numcourse = getIndex(document.$formname.dccourse);
4673: if (numcourse == "-1") {
4674: alert("$alerts{'thwa'}");
4675: return;
4676: }
4677: else {
4678: document.$formname.elements[numcourse].name = "act"+coursename;
4679: var numnewsec = getIndex(document.$formname.newsec);
4680: if (numnewsec != "-1") {
4681: document.$formname.elements[numnewsec].name = "sec"+coursename;
4682: document.$formname.elements[numnewsec].value = section;
4683: }
4684: var numstart = getIndex(document.$formname.start);
4685: if (numstart != "-1") {
4686: document.$formname.elements[numstart].name = "start"+coursename;
4687: }
4688: var numend = getIndex(document.$formname.end);
4689: if (numend != "-1") {
4690: document.$formname.elements[numend].name = "end"+coursename
4691: }
4692: }
4693: }
4694: var authcheck = auth_check();
4695: if (authcheck == 'ok') {
4696: document.$formname.submit();
4697: }
4698: }
4699: ENDSCRIPT
4700: } else {
4701: $dc_setcourse_code .= "
4702: document.$formname.sections.value = section;
4703: }
4704: return 'ok';
4705: }
4706: ";
4707: }
4708: $dc_setcourse_code .= (<<"ENDSCRIPT");
4709:
4710: function getIndex(caller) {
4711: for (var i=0;i<document.$formname.elements.length;i++) {
4712: if (document.$formname.elements[i] == caller) {
4713: return i;
4714: }
4715: }
4716: return -1;
4717: }
4718: ENDSCRIPT
4719: return $dc_setcourse_code;
4720: }
4721:
4722: sub verify_authen {
4723: my ($formname,$context) = @_;
4724: my %alerts = &authcheck_alerts();
4725: my $finish = "return 'ok';";
4726: if ($context eq 'author') {
4727: $finish = "document.$formname.submit();";
4728: }
4729: my $outcome = <<"ENDSCRIPT";
4730:
4731: function auth_check() {
4732: var logintype;
4733: if (document.$formname.login.length) {
4734: if (document.$formname.login.length > 0) {
4735: var loginpicked = 0;
4736: for (var i=0; i<document.$formname.login.length; i++) {
4737: if (document.$formname.login[i].checked == true) {
4738: loginpicked = 1;
4739: logintype = document.$formname.login[i].value;
4740: }
4741: }
4742: if (loginpicked == 0) {
4743: alert("$alerts{'authen'}");
4744: return;
4745: }
4746: }
4747: } else {
4748: logintype = document.$formname.login.value;
4749: }
4750: if (logintype == 'nochange') {
4751: return 'ok';
4752: }
4753: var argpicked = document.$formname.elements[logintype+'arg'].value;
4754: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
4755: var alertmsg = '';
4756: switch (logintype) {
4757: case 'krb':
4758: alertmsg = '$alerts{'krb'}';
4759: break;
4760: case 'int':
4761: alertmsg = '$alerts{'ipass'}';
4762: case 'fsys':
4763: alertmsg = '$alerts{'ipass'}';
4764: break;
4765: case 'loc':
4766: alertmsg = '';
4767: break;
4768: default:
4769: alertmsg = '';
4770: }
4771: if (alertmsg != '') {
4772: alert(alertmsg);
4773: return;
4774: }
4775: }
4776: $finish
4777: }
4778: ENDSCRIPT
4779: }
4780:
4781: sub sectioncheck_alerts {
4782: my %alerts = &Apache::lonlocal::texthash(
4783: curd => 'You must select a course in the current domain',
4784: inea => 'In each course, each user may only have one student role at a time',
4785: youh => 'You had selected',
4786: sect => 'sections',
4787: plsm => 'Please modify your selections so they include no more than one section',
4788: mayn => 'may not be used as the name for a section, as it is a reserved word',
4789: plsc => 'Please choose a different section name',
4790: mayt => 'may not be used as the name for a section, as it is the name of a course group',
4791: secn => 'Section names and group names must be distinct',
4792: secd => 'Section designations do not apply to ',
4793: role => 'roles',
4794: accr => 'role will be added with access to all sections',
4795: thwa => 'There was a problem with your course selection'
4796: );
4797: return %alerts;
4798: }
4799:
4800: sub authcheck_alerts {
4801: my %alerts =
4802: &Apache::lonlocal::texthash(
4803: authen => 'You must choose an authentication type.',
4804: krb => 'You need to specify the Kerberos domain.',
4805: ipass => 'You need to specify the initial password.',
4806: );
4807: return %alerts;
4808: }
4809:
4810: 1;
4811:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>