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