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