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