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