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