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