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