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