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