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