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