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