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