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