Annotation of loncom/interface/lonuserutils.pm, revision 1.88
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.88 ! bisitz 4: # $Id: lonuserutils.pm,v 1.87 2009/04/22 16:44:36 bisitz Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ###############################################################
30:
31: package Apache::lonuserutils;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon;
37: use Apache::lonlocal;
1.8 raeburn 38: use Apache::longroup;
39: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 40:
41: ###############################################################
42: ###############################################################
43: # Drop student from all sections of a course, except optional $csec
44: sub modifystudent {
1.52 raeburn 45: my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
1.1 raeburn 46: # if $csec is undefined, drop the student from all the courses matching
47: # this one. If $csec is defined, drop them from all other sections of
48: # this course and add them to section $csec
1.17 raeburn 49: my ($cnum,$cdom) = &get_course_identity($courseid);
1.1 raeburn 50: my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
51: my ($tmp) = keys(%roles);
52: # Bail out if we were unable to get the students roles
53: return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
54: # Go through the roles looking for enrollment in this course
55: my $result = '';
56: foreach my $course (keys(%roles)) {
57: if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
58: # We are in this course
59: my $section=$1;
60: $section='' if ($course eq "/$cdom/$cnum".'_st');
61: if (defined($csec) && $section eq $csec) {
62: $result .= 'ok:';
63: } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
64: my (undef,$end,$start)=split(/\_/,$roles{$course});
65: my $now=time;
66: # if this is an active role
67: if (!($start && ($now<$start)) || !($end && ($now>$end))) {
68: my $reply=&Apache::lonnet::modifystudent
69: # dom name id mode pass f m l g
70: ($udom,$unam,'', '', '',undef,undef,undef,undef,
1.22 raeburn 71: $section,time,undef,undef,$desiredhost,'','manual',
1.52 raeburn 72: '',$courseid,'',$context);
1.1 raeburn 73: $result .= $reply.':';
74: }
75: }
76: }
77: }
78: if ($result eq '') {
1.37 raeburn 79: $result = &mt('Unable to find section for this student');
1.1 raeburn 80: } else {
81: $result =~ s/(ok:)+/ok/g;
82: }
83: return $result;
84: }
85:
86: sub modifyuserrole {
87: my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
88: $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
1.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.86 bisitz 344: $r->print('<br /><label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
1.73 bisitz 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".
1.86 bisitz 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.86 bisitz 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.86 bisitz 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) {
1.86 bisitz 2215: $checkedstr = ' checked="checked"';
1.56 raeburn 2216: }
1.86 bisitz 2217: $output .= '<span class="LC_nobreak"><label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.' /> '.$lt{$item}.'</label></span><br />';
1.56 raeburn 2218: }
2219: my $checkwin;
2220: if ($env{'form.userwin'}) {
1.86 bisitz 2221: $checkwin = ' checked="checked"';
1.56 raeburn 2222: }
1.86 bisitz 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="'.
1.86 bisitz 2540: 'actionlist" value="'.$checkval.'" /></td>');
1.26 raeburn 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>
1.86 bisitz 3262: <input type="hidden" name="phase" value="four" />
1.1 raeburn 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.86 bisitz 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>
1.86 bisitz 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)" />
1.88 ! bisitz 3402: <p><input type="submit" value="$lt{'dp'}" /></p>
1.1 raeburn 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;
1.86 bisitz 3413: $str = '<input type="hidden" name="phase" value="two" />';
1.1 raeburn 3414: $str .= '<input type="hidden" name="action" value="upload" />';
3415: $str .= '<input type="hidden" name="state" value="got_file" />';
1.85 bisitz 3416: $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
3417: $str .= '<p class="LC_info">'
3418: .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')
3419: .'</p>'."\n";
1.1 raeburn 3420: $str .= &Apache::loncommon::upfile_select_html();
1.73 bisitz 3421: $str .= '<p>';
1.1 raeburn 3422: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
3423: &mt("How do I create a users list from a spreadsheet")).
3424: "<br />\n";
3425: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.73 bisitz 3426: &mt("How do I create a CSV file from a spreadsheet"));
3427: $str .= "</p>\n";
3428: $str .= "<p>\n";
3429: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
3430: &mt('Ignore First Line')."</label></p>\n";
3431: $str .= '<input type="submit" name="fileupload" value="'.
1.86 bisitz 3432: &mt('Next').'" />'."<br />\n";
1.1 raeburn 3433: $str .= &Apache::loncommon::end_page();
3434: $r->print($str);
3435: return;
3436: }
3437:
3438: # ================================================= Drop/Add from uploaded file
3439: sub upfile_drop_add {
1.21 raeburn 3440: my ($r,$context,$permission) = @_;
1.1 raeburn 3441: &Apache::loncommon::load_tmp_file($r);
3442: my @userdata=&Apache::loncommon::upfile_record_sep();
3443: if($env{'form.noFirstLine'}){shift(@userdata);}
3444: my @keyfields = split(/\,/,$env{'form.keyfields'});
3445: my %fields=();
3446: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3447: if ($env{'form.upfile_associate'} eq 'reverse') {
3448: if ($env{'form.f'.$i} ne 'none') {
3449: $fields{$keyfields[$i]}=$env{'form.f'.$i};
3450: }
3451: } else {
3452: $fields{$env{'form.f'.$i}}=$keyfields[$i];
3453: }
3454: }
1.29 raeburn 3455: if ($env{'form.fullup'} ne 'yes') {
3456: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
3457: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
3458: }
1.1 raeburn 3459: #
3460: # Store the field choices away
3461: foreach my $field (qw/username names
1.57 raeburn 3462: fname mname lname gen id sec ipwd email role domain/) {
1.1 raeburn 3463: $env{'form.'.$field.'_choice'}=$fields{$field};
3464: }
3465: &Apache::loncommon::store_course_settings('enrollment_upload',
3466: { 'username_choice' => 'scalar',
3467: 'names_choice' => 'scalar',
3468: 'fname_choice' => 'scalar',
3469: 'mname_choice' => 'scalar',
3470: 'lname_choice' => 'scalar',
3471: 'gen_choice' => 'scalar',
3472: 'id_choice' => 'scalar',
3473: 'sec_choice' => 'scalar',
3474: 'ipwd_choice' => 'scalar',
3475: 'email_choice' => 'scalar',
1.57 raeburn 3476: 'role_choice' => 'scalar',
1.84 raeburn 3477: 'domain_choice' => 'scalar',
3478: 'inststatus_choice' => 'scalar'});
1.1 raeburn 3479: #
3480: my ($startdate,$enddate) = &get_dates_from_form();
3481: if ($env{'form.makedatesdefault'}) {
1.27 raeburn 3482: $r->print(&make_dates_default($startdate,$enddate,$context));
1.1 raeburn 3483: }
3484: # Determine domain and desired host (home server)
1.57 raeburn 3485: my $defdom=$env{'request.role.domain'};
3486: my $domain;
3487: if ($env{'form.defaultdomain'} ne '') {
3488: $domain = $env{'form.defaultdomain'};
3489: } else {
3490: $domain = $defdom;
3491: }
1.1 raeburn 3492: my $desiredhost = $env{'form.lcserver'};
3493: if (lc($desiredhost) eq 'default') {
3494: $desiredhost = undef;
3495: } else {
1.57 raeburn 3496: my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
1.1 raeburn 3497: if (! exists($home_servers{$desiredhost})) {
3498: $r->print('<span class="LC_error">'.&mt('Error').
3499: &mt('Invalid home server specified').'</span>');
3500: $r->print(&Apache::loncommon::end_page());
3501: return;
3502: }
3503: }
3504: # Determine authentication mechanism
3505: my $changeauth;
3506: if ($context eq 'domain') {
3507: $changeauth = $env{'form.changeauth'};
3508: }
3509: my $amode = '';
3510: my $genpwd = '';
3511: if ($env{'form.login'} eq 'krb') {
3512: $amode='krb';
3513: $amode.=$env{'form.krbver'};
3514: $genpwd=$env{'form.krbarg'};
3515: } elsif ($env{'form.login'} eq 'int') {
3516: $amode='internal';
3517: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
3518: $genpwd=$env{'form.intarg'};
3519: }
3520: } elsif ($env{'form.login'} eq 'loc') {
3521: $amode='localauth';
3522: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
3523: $genpwd=$env{'form.locarg'};
3524: }
3525: }
3526: if ($amode =~ /^krb/) {
3527: if (! defined($genpwd) || $genpwd eq '') {
3528: $r->print('<span class="Error">'.
3529: &mt('Unable to enroll users').' '.
3530: &mt('No Kerberos domain was specified.').'</span></p>');
3531: $amode = ''; # This causes the loop below to be skipped
3532: }
3533: }
3534: my ($cid,$defaultsec,$defaultrole,$setting);
3535: if ($context eq 'domain') {
3536: $setting = $env{'form.roleaction'};
3537: if ($setting eq 'domain') {
3538: $defaultrole = $env{'form.defaultrole'};
3539: } elsif ($setting eq 'course') {
3540: $defaultrole = $env{'form.courserole'};
1.27 raeburn 3541: $defaultsec = $env{'form.sections'};
1.1 raeburn 3542: }
1.13 raeburn 3543: } elsif ($context eq 'author') {
1.1 raeburn 3544: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 3545: } elsif ($context eq 'course') {
3546: $defaultrole = $env{'form.defaultrole'};
3547: $defaultsec = $env{'form.sections'};
1.1 raeburn 3548: }
1.27 raeburn 3549: if ($env{'request.course.id'} ne '') {
3550: $cid = $env{'request.course.id'};
3551: } elsif ($setting eq 'course') {
3552: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
3553: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
1.1 raeburn 3554: }
3555: }
1.27 raeburn 3556: # Check to see if user information can be changed
3557: my @userinfo = ('firstname','middlename','lastname','generation',
3558: 'permanentemail','id');
3559: my %canmodify;
3560: if (&Apache::lonnet::allowed('mau',$domain)) {
1.84 raeburn 3561: push(@userinfo,'inststatus');
1.27 raeburn 3562: foreach my $field (@userinfo) {
3563: $canmodify{$field} = 1;
3564: }
3565: }
3566: my (%userlist,%modifiable_fields,@poss_roles);
3567: my $secidx = &Apache::loncoursedata::CL_SECTION();
3568: my @courseroles = &roles_by_context('course',1);
3569: if (!&Apache::lonnet::allowed('mau',$domain)) {
3570: if ($context eq 'course' || $context eq 'author') {
3571: @poss_roles = &curr_role_permissions($context);
3572: my @statuses = ('active','future');
3573: my ($indexhash,$keylist) = &make_keylist_array();
3574: my %info;
3575: foreach my $role (@poss_roles) {
3576: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
3577: \@userinfo,[$role]);
3578: }
3579: if ($context eq 'course') {
3580: my ($cnum,$cdom) = &get_course_identity();
3581: my $roster = &Apache::loncoursedata::get_classlist();
1.66 raeburn 3582: if (ref($roster) eq 'HASH') {
3583: %userlist = %{$roster};
3584: }
1.27 raeburn 3585: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
3586: \@statuses,\@poss_roles);
3587: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3588: \%advrolehash,$permission);
3589: } elsif ($context eq 'author') {
3590: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
3591: \@statuses,\@poss_roles);
3592: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3593: \%cstr_roles,$permission);
3594:
3595: }
3596: }
1.1 raeburn 3597: }
3598: if ( $domain eq &LONCAPA::clean_domain($domain)
3599: && ($amode ne '')) {
3600: #######################################
3601: ## Add/Modify Users ##
3602: #######################################
3603: if ($context eq 'course') {
3604: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 3605: } elsif ($context eq 'author') {
1.1 raeburn 3606: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
3607: } else {
3608: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
3609: }
1.87 bisitz 3610: $r->rflush;
3611:
1.1 raeburn 3612: my %counts = (
3613: user => 0,
3614: auth => 0,
3615: role => 0,
3616: );
3617: my $flushc=0;
3618: my %student=();
1.42 raeburn 3619: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 3620: my %userchg;
1.27 raeburn 3621: if ($context eq 'course' || $setting eq 'course') {
3622: if ($context eq 'course') {
3623: # Get information about course groups
3624: %curr_groups = &Apache::longroup::coursegroups();
3625: } elsif ($setting eq 'course') {
3626: if ($cid) {
3627: %curr_groups =
3628: &Apache::longroup::coursegroups($env{'form.dcdomain'},
3629: $env{'form.dccourse'});
3630: }
3631: }
3632: # determine section number
3633: if ($defaultsec =~ /,/) {
3634: push(@sections,split(/,/,$defaultsec));
3635: } else {
3636: push(@sections,$defaultsec);
3637: }
3638: # remove non alphanumeric values from section
3639: foreach my $item (@sections) {
3640: $item =~ s/\W//g;
3641: if ($item eq "none" || $item eq 'all') {
3642: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
3643: } elsif ($item ne '' && exists($curr_groups{$item})) {
3644: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
3645: } elsif ($item ne '') {
3646: push(@cleansec,$item);
3647: }
3648: }
3649: if ($defaultwarn) {
3650: $r->print($defaultwarn.'<br />');
3651: }
3652: if ($groupwarn) {
3653: $r->print($groupwarn.'<br />');
3654: }
1.1 raeburn 3655: }
1.5 raeburn 3656: my (%curr_rules,%got_rules,%alerts);
1.27 raeburn 3657: my %customroles = &my_custom_roles();
1.42 raeburn 3658: my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
1.1 raeburn 3659: # Get new users list
1.27 raeburn 3660: foreach my $line (@userdata) {
1.42 raeburn 3661: my @secs;
1.27 raeburn 3662: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 3663: # Determine user name
3664: unless (($entries{$fields{'username'}} eq '') ||
3665: (!defined($entries{$fields{'username'}}))) {
3666: my ($fname, $mname, $lname,$gen) = ('','','','');
3667: if (defined($fields{'names'})) {
3668: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
3669: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
3670: } else {
3671: if (defined($fields{'fname'})) {
3672: $fname=$entries{$fields{'fname'}};
3673: }
3674: if (defined($fields{'mname'})) {
3675: $mname=$entries{$fields{'mname'}};
3676: }
3677: if (defined($fields{'lname'})) {
3678: $lname=$entries{$fields{'lname'}};
3679: }
3680: if (defined($fields{'gen'})) {
3681: $gen=$entries{$fields{'gen'}};
3682: }
3683: }
3684: if ($entries{$fields{'username'}}
3685: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
3686: $r->print('<br />'.
1.74 bisitz 3687: &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
1.77 raeburn 3688: '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen));
1.27 raeburn 3689: next;
1.1 raeburn 3690: } else {
1.71 droeschl 3691: if ($entries{$fields{'domain'}}
1.57 raeburn 3692: ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
3693: $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.
1.77 raeburn 3694: '</b>: '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
1.57 raeburn 3695: next;
3696: }
1.5 raeburn 3697: my $username = $entries{$fields{'username'}};
1.57 raeburn 3698: my $userdomain = $entries{$fields{'domain'}};
3699: if ($userdomain eq '') {
3700: $userdomain = $domain;
3701: }
1.27 raeburn 3702: if (defined($fields{'sec'})) {
3703: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 3704: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 3705: my $item = $entries{$fields{'sec'}};
3706: if ($item eq "none" || $item eq 'all') {
1.74 bisitz 3707: $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 3708: next;
3709: } elsif (exists($curr_groups{$item})) {
1.74 bisitz 3710: $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 3711: next;
3712: } else {
3713: push(@secs,$item);
3714: }
3715: }
3716: }
3717: if ($env{'request.course.sec'} ne '') {
3718: @secs = ($env{'request.course.sec'});
1.57 raeburn 3719: if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
3720: my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
1.27 raeburn 3721: if ($currsec ne $env{'request.course.sec'}) {
1.74 bisitz 3722: $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 3723: if ($currsec eq '') {
3724: $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
3725:
3726: } else {
3727: $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
3728: }
3729: $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 />');
3730: next;
1.1 raeburn 3731: }
3732: }
1.27 raeburn 3733: } elsif ($context eq 'course' || $setting eq 'course') {
3734: if (@secs == 0) {
3735: @secs = @cleansec;
1.1 raeburn 3736: }
3737: }
3738: # determine id number
3739: my $id='';
3740: if (defined($fields{'id'})) {
3741: if (defined($entries{$fields{'id'}})) {
3742: $id=$entries{$fields{'id'}};
3743: }
3744: $id=~tr/A-Z/a-z/;
3745: }
3746: # determine email address
3747: my $email='';
3748: if (defined($fields{'email'})) {
3749: if (defined($entries{$fields{'email'}})) {
3750: $email=$entries{$fields{'email'}};
1.84 raeburn 3751: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
3752: }
3753: }
3754: # determine affiliation
3755: my $inststatus='';
3756: if (defined($fields{'inststatus'})) {
3757: if (defined($entries{$fields{'inststatus'}})) {
3758: $inststatus=$entries{$fields{'inststatus'}};
3759: }
1.1 raeburn 3760: }
3761: # determine user password
3762: my $password = $genpwd;
3763: if (defined($fields{'ipwd'})) {
3764: if ($entries{$fields{'ipwd'}}) {
3765: $password=$entries{$fields{'ipwd'}};
3766: }
3767: }
3768: # determine user role
3769: my $role = '';
3770: if (defined($fields{'role'})) {
3771: if ($entries{$fields{'role'}}) {
1.42 raeburn 3772: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
3773: if ($entries{$fields{'role'}} ne '') {
3774: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
3775: $role = $entries{$fields{'role'}};
1.27 raeburn 3776: }
3777: }
3778: if ($role eq '') {
3779: my $rolestr = join(', ',@permitted_roles);
1.74 bisitz 3780: $r->print('<br />'
3781: .&mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
3782: ,'<b>'.$entries{$fields{'username'}}.'</b>'
3783: ,$entries{$fields{'role'}})
3784: .'<br />'
3785: .&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n"
3786: );
1.1 raeburn 3787: next;
3788: }
3789: }
3790: }
3791: if ($role eq '') {
3792: $role = $defaultrole;
3793: }
3794: # Clean up whitespace
1.57 raeburn 3795: foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
1.1 raeburn 3796: $$_ =~ s/(\s+$|^\s+)//g;
3797: }
1.5 raeburn 3798: # check against rules
3799: my $checkid = 0;
3800: my $newuser = 0;
3801: my (%rulematch,%inst_results,%idinst_results);
1.57 raeburn 3802: my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
1.5 raeburn 3803: if ($uhome eq 'no_host') {
1.57 raeburn 3804: next if ($userdomain ne $domain);
1.5 raeburn 3805: $checkid = 1;
3806: $newuser = 1;
3807: my $checkhash;
3808: my $checks = { 'username' => 1 };
3809: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3810: &Apache::loncommon::user_rule_check($checkhash,$checks,
3811: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3812: \%got_rules);
3813: if (ref($alerts{'username'}) eq 'HASH') {
3814: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3815: next if ($alerts{'username'}{$domain}{$username});
3816: }
3817: }
1.13 raeburn 3818: } else {
1.27 raeburn 3819: if ($context eq 'course' || $context eq 'author') {
1.57 raeburn 3820: if ($userdomain eq $domain ) {
3821: if ($role eq '') {
3822: my @checkroles;
3823: foreach my $role (@poss_roles) {
3824: my $endkey;
3825: if ($role ne 'st') {
3826: $endkey = ':'.$role;
3827: }
3828: if (exists($userlist{$username.':'.$userdomain.$endkey})) {
3829: if (!grep(/^\Q$role\E$/,@checkroles)) {
3830: push(@checkroles,$role);
3831: }
3832: }
1.27 raeburn 3833: }
1.57 raeburn 3834: if (@checkroles > 0) {
3835: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
1.27 raeburn 3836: }
1.57 raeburn 3837: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
3838: %canmodify = %{$modifiable_fields{$role}};
1.27 raeburn 3839: }
3840: }
1.57 raeburn 3841: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
1.84 raeburn 3842: for (my $i=0; $i<@newinfo; $i++) {
1.57 raeburn 3843: if (${$newinfo[$i]} ne '') {
3844: if (!$canmodify{$userinfo[$i]}) {
3845: ${$newinfo[$i]} = '';
3846: }
1.27 raeburn 3847: }
3848: }
3849: }
1.5 raeburn 3850: }
3851: if ($id ne '') {
3852: if (!$newuser) {
1.57 raeburn 3853: my %idhash = &Apache::lonnet::idrget($userdomain,($username));
1.5 raeburn 3854: if ($idhash{$username} ne $id) {
3855: $checkid = 1;
3856: }
3857: }
3858: if ($checkid) {
3859: my $checkhash;
3860: my $checks = { 'id' => 1 };
1.57 raeburn 3861: $checkhash->{$username.':'.$userdomain} = { 'newuser' => $newuser,
1.5 raeburn 3862: 'id' => $id };
3863: &Apache::loncommon::user_rule_check($checkhash,$checks,
3864: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3865: \%got_rules);
3866: if (ref($alerts{'id'}) eq 'HASH') {
1.57 raeburn 3867: if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
3868: next if ($alerts{'id'}{$userdomain}{$id});
1.5 raeburn 3869: }
3870: }
3871: }
3872: }
1.1 raeburn 3873: if ($password || $env{'form.login'} eq 'loc') {
1.27 raeburn 3874: my $multiple = 0;
3875: my ($userresult,$authresult,$roleresult,$idresult);
3876: my (%userres,%authres,%roleres,%idres);
1.42 raeburn 3877: my $singlesec = '';
1.1 raeburn 3878: if ($role eq 'st') {
1.27 raeburn 3879: my $sec;
1.42 raeburn 3880: if (@secs > 0) {
3881: $sec = $secs[0];
1.27 raeburn 3882: }
1.57 raeburn 3883: &modifystudent($userdomain,$username,$cid,$sec,
1.52 raeburn 3884: $desiredhost,$context);
1.42 raeburn 3885: $roleresult =
3886: &Apache::lonnet::modifystudent
1.57 raeburn 3887: ($userdomain,$username,$id,$amode,$password,
1.42 raeburn 3888: $fname,$mname,$lname,$gen,$sec,$enddate,
3889: $startdate,$env{'form.forceid'},
1.52 raeburn 3890: $desiredhost,$email,'manual','',$cid,
1.84 raeburn 3891: '',$context,$inststatus);
1.42 raeburn 3892: $userresult = $roleresult;
1.1 raeburn 3893: } else {
1.42 raeburn 3894: if ($role ne '') {
3895: if ($context eq 'course' || $setting eq 'course') {
3896: if ($customroles{$role}) {
3897: $role = 'cr_'.$env{'user.domain'}.'_'.
3898: $env{'user.name'}.'_'.$role;
3899: }
3900: if ($role ne 'cc') {
3901: if (@secs > 1) {
3902: $multiple = 1;
3903: foreach my $sec (@secs) {
3904: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
3905: &modifyuserrole($context,$setting,
1.57 raeburn 3906: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 3907: $id,$amode,$password,$fname,
3908: $mname,$lname,$gen,$sec,
3909: $env{'form.forceid'},$desiredhost,
3910: $email,$role,$enddate,
1.84 raeburn 3911: $startdate,$checkid,$inststatus);
1.42 raeburn 3912: }
3913: } elsif (@secs > 0) {
3914: $singlesec = $secs[0];
3915: }
1.27 raeburn 3916: }
3917: }
3918: }
3919: if (!$multiple) {
1.28 raeburn 3920: ($userresult,$authresult,$roleresult,$idresult) =
1.27 raeburn 3921: &modifyuserrole($context,$setting,
1.57 raeburn 3922: $changeauth,$cid,$userdomain,$username,
1.42 raeburn 3923: $id,$amode,$password,$fname,
3924: $mname,$lname,$gen,$singlesec,
3925: $env{'form.forceid'},$desiredhost,
1.84 raeburn 3926: $email,$role,$enddate,$startdate,
3927: $checkid,$inststatus);
1.27 raeburn 3928: }
3929: }
3930: if ($multiple) {
3931: foreach my $sec (sort(keys(%userres))) {
1.42 raeburn 3932: $flushc =
1.27 raeburn 3933: &user_change_result($r,$userres{$sec},$authres{$sec},
3934: $roleres{$sec},$idres{$sec},\%counts,$flushc,
1.57 raeburn 3935: $username,$userdomain,\%userchg);
1.27 raeburn 3936:
3937: }
3938: } else {
3939: $flushc =
3940: &user_change_result($r,$userresult,$authresult,
1.28 raeburn 3941: $roleresult,$idresult,\%counts,$flushc,
1.57 raeburn 3942: $username,$userdomain,\%userchg);
1.1 raeburn 3943: }
3944: } else {
3945: if ($context eq 'course') {
3946: $r->print('<br />'.
1.74 bisitz 3947: &mt('[_1]: Unable to enroll. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 3948: );
1.13 raeburn 3949: } elsif ($context eq 'author') {
1.1 raeburn 3950: $r->print('<br />'.
1.74 bisitz 3951: &mt('[_1]: Unable to add co-author. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 3952: );
3953: } else {
3954: $r->print('<br />'.
1.74 bisitz 3955: &mt('[_1]: Unable to add user. No password specified.','<b>'.$username.'</b>')
1.1 raeburn 3956: );
3957: }
3958: }
3959: }
3960: }
3961: } # end of foreach (@userdata)
3962: # Flush the course logs so reverse user roles immediately updated
1.5 raeburn 3963: &Apache::lonnet::flushcourselogs();
1.29 raeburn 3964: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 3965: "</p>\n");
3966: if ($counts{'role'} > 0) {
3967: $r->print("<p>\n".
1.29 raeburn 3968: &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");
3969: } else {
3970: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 3971: }
3972: if ($counts{'auth'} > 0) {
3973: $r->print("<p>\n".
3974: &mt('Authentication changed for [_1] existing users.',
3975: $counts{'auth'})."</p>\n");
3976: }
1.13 raeburn 3977: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.1 raeburn 3978: #####################################
1.29 raeburn 3979: # Display list of students to drop #
1.1 raeburn 3980: #####################################
3981: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 3982: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 3983: # Get current classlist
1.30 raeburn 3984: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 3985: if (! defined($classlist)) {
1.29 raeburn 3986: $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
3987: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
3988: &mt('There are no students with current/future access to the course.').
3989: '</form>'."\n");
1.66 raeburn 3990: } elsif (ref($classlist) eq 'HASH') {
1.1 raeburn 3991: # Remove the students we just added from the list of students.
1.30 raeburn 3992: foreach my $line (@userdata) {
3993: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 3994: unless (($entries{$fields{'username'}} eq '') ||
3995: (!defined($entries{$fields{'username'}}))) {
3996: delete($classlist->{$entries{$fields{'username'}}.
3997: ':'.$domain});
3998: }
3999: }
4000: # Print out list of dropped students.
1.30 raeburn 4001: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 4002: }
4003: }
4004: } # end of unless
1.29 raeburn 4005: if ($env{'form.fullup'} ne 'yes') {
4006: $r->print('</form>');
4007: }
1.1 raeburn 4008: }
4009:
1.13 raeburn 4010: sub print_namespacing_alerts {
4011: my ($domain,$alerts,$curr_rules) = @_;
4012: my $output;
4013: if (ref($alerts) eq 'HASH') {
4014: if (keys(%{$alerts}) > 0) {
4015: if (ref($alerts->{'username'}) eq 'HASH') {
4016: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
4017: my $count;
4018: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
4019: $count = keys(%{$alerts->{'username'}{$dom}});
4020: }
4021: my $domdesc = &Apache::lonnet::domain($domain,'description');
4022: if (ref($curr_rules->{$dom}) eq 'HASH') {
4023: $output .= &Apache::loncommon::instrule_disallow_msg(
4024: 'username',$domdesc,$count,'upload');
4025: }
4026: $output .= &Apache::loncommon::user_rule_formats($dom,
4027: $domdesc,$curr_rules->{$dom}{'username'},
4028: 'username');
4029: }
4030: }
4031: if (ref($alerts->{'id'}) eq 'HASH') {
4032: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
4033: my $count;
4034: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
4035: $count = keys(%{$alerts->{'id'}{$dom}});
4036: }
4037: my $domdesc = &Apache::lonnet::domain($domain,'description');
4038: if (ref($curr_rules->{$dom}) eq 'HASH') {
4039: $output .= &Apache::loncommon::instrule_disallow_msg(
4040: 'id',$domdesc,$count,'upload');
4041: }
4042: $output .= &Apache::loncommon::user_rule_formats($dom,
4043: $domdesc,$curr_rules->{$dom}{'id'},'id');
4044: }
4045: }
4046: }
4047: }
4048: }
4049:
1.1 raeburn 4050: sub user_change_result {
1.29 raeburn 4051: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
1.57 raeburn 4052: $username,$userdomain,$userchg) = @_;
1.1 raeburn 4053: my $okresult = 0;
4054: if ($userresult ne 'ok') {
4055: if ($userresult =~ /^error:(.+)$/) {
4056: my $error = $1;
4057: $r->print('<br />'.
1.74 bisitz 4058: &mt('[_1]: Unable to add/modify: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4059: }
4060: } else {
4061: $counts->{'user'} ++;
4062: $okresult = 1;
4063: }
4064: if ($authresult ne 'ok') {
4065: if ($authresult =~ /^error:(.+)$/) {
4066: my $error = $1;
4067: $r->print('<br />'.
1.74 bisitz 4068: &mt('[_1]: Unable to modify authentication: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4069: }
4070: } else {
4071: $counts->{'auth'} ++;
4072: $okresult = 1;
4073: }
4074: if ($roleresult ne 'ok') {
4075: if ($roleresult =~ /^error:(.+)$/) {
4076: my $error = $1;
4077: $r->print('<br />'.
1.74 bisitz 4078: &mt('[_1]: Unable to add role: [_2]','<b>'.$username.':'.$userdomain.'</b>',$error));
1.1 raeburn 4079: }
4080: } else {
4081: $counts->{'role'} ++;
4082: $okresult = 1;
4083: }
4084: if ($okresult) {
4085: $flushc++;
1.57 raeburn 4086: $userchg->{$username.':'.$userdomain}=1;
1.1 raeburn 4087: $r->print('. ');
4088: if ($flushc>15) {
4089: $r->rflush;
4090: $flushc=0;
4091: }
4092: }
1.29 raeburn 4093: if ($idresult) {
4094: $r->print($idresult);
4095: }
1.1 raeburn 4096: return $flushc;
4097: }
4098:
4099: # ========================================================= Menu Phase Two Drop
1.17 raeburn 4100: sub print_drop_menu {
4101: my ($r,$context,$permission) = @_;
4102: $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
4103: '<form name="studentform" method="post">'."\n");
1.30 raeburn 4104: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 4105: if (! defined($classlist)) {
4106: $r->print(&mt('There are no students currently enrolled.')."\n");
1.30 raeburn 4107: } else {
4108: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 4109: }
1.17 raeburn 4110: $r->print('</form>'. &Apache::loncommon::end_page());
1.1 raeburn 4111: return;
4112: }
4113:
4114: # ================================================================== Phase four
4115:
1.11 raeburn 4116: sub update_user_list {
4117: my ($r,$context,$setting,$choice) = @_;
4118: my $now = time;
1.1 raeburn 4119: my $count=0;
1.11 raeburn 4120: my @changelist;
1.29 raeburn 4121: if ($choice eq 'drop') {
4122: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
4123: } else {
1.11 raeburn 4124: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
4125: }
4126: my %result_text = ( ok => { 'revoke' => 'Revoked',
4127: 'delete' => 'Deleted',
4128: 'reenable' => 'Re-enabled',
1.17 raeburn 4129: 'activate' => 'Activated',
4130: 'chgdates' => 'Changed Access Dates for',
4131: 'chgsec' => 'Changed section for',
4132: 'drop' => 'Dropped',
1.11 raeburn 4133: },
4134: error => {'revoke' => 'revoking',
4135: 'delete' => 'deleting',
4136: 'reenable' => 're-enabling',
4137: 'activate' => 'activating',
1.17 raeburn 4138: 'chgdates' => 'changing access dates for',
4139: 'chgsec' => 'changing section for',
4140: 'drop' => 'dropping',
1.11 raeburn 4141: },
4142: );
4143: my ($startdate,$enddate);
4144: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
4145: ($startdate,$enddate) = &get_dates_from_form();
4146: }
4147: foreach my $item (@changelist) {
4148: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
4149: $scopestem);
1.17 raeburn 4150: if ($choice eq 'drop') {
4151: ($uname,$udom,$sec) = split(/:/,$item,-1);
4152: $role = 'st';
4153: $cid = $env{'request.course.id'};
4154: $scopestem = '/'.$cid;
4155: $scopestem =~s/\_/\//g;
4156: if ($sec eq '') {
4157: $scope = $scopestem;
4158: } else {
4159: $scope = $scopestem.'/'.$sec;
4160: }
4161: } elsif ($context eq 'course') {
1.11 raeburn 4162: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
4163: $cid = $env{'request.course.id'};
4164: $scopestem = '/'.$cid;
4165: $scopestem =~s/\_/\//g;
4166: if ($sec eq '') {
4167: $scope = $scopestem;
4168: } else {
4169: $scope = $scopestem.'/'.$sec;
4170: }
1.13 raeburn 4171: } elsif ($context eq 'author') {
1.11 raeburn 4172: ($uname,$udom,$role) = split(/\:/,$item,-1);
4173: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
4174: } elsif ($context eq 'domain') {
4175: if ($setting eq 'domain') {
4176: ($role,$uname,$udom) = split(/\:/,$item,-1);
4177: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 4178: } elsif ($setting eq 'author') {
1.11 raeburn 4179: ($uname,$udom,$role,$scope) = split(/\:/,$item);
4180: } elsif ($setting eq 'course') {
4181: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
4182: split(/\:/,$item);
4183: $scope = '/'.$cid;
4184: $scope =~s/\_/\//g;
4185: if ($sec ne '') {
4186: $scope .= '/'.$sec;
4187: }
4188: }
4189: }
4190: my $plrole = &Apache::lonnet::plaintext($role);
4191: my $start = $env{'form.'.$item.'_start'};
4192: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 4193: if ($choice eq 'drop') {
4194: # drop students
4195: $end = $now;
4196: $type = 'manual';
4197: $result =
1.52 raeburn 4198: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 4199: } elsif ($choice eq 'revoke') {
4200: # revoke or delete user role
1.11 raeburn 4201: $end = $now;
4202: if ($role eq 'st') {
4203: $result =
1.52 raeburn 4204: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4205: } else {
4206: $result =
1.52 raeburn 4207: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
4208: '','',$context);
1.11 raeburn 4209: }
4210: } elsif ($choice eq 'delete') {
4211: if ($role eq 'st') {
1.52 raeburn 4212: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
1.29 raeburn 4213: }
4214: $result =
4215: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 4216: $start,1,'',$context);
1.11 raeburn 4217: } else {
4218: #reenable, activate, change access dates or change section
4219: if ($choice ne 'chgsec') {
4220: $start = $startdate;
4221: $end = $enddate;
4222: }
4223: if ($choice eq 'reenable') {
4224: if ($role eq 'st') {
1.52 raeburn 4225: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4226: } else {
4227: $result =
4228: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4229: $now,'','',$context);
1.11 raeburn 4230: }
4231: } elsif ($choice eq 'activate') {
4232: if ($role eq 'st') {
1.52 raeburn 4233: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4234: } else {
4235: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4236: $now,'','',$context);
1.11 raeburn 4237: }
4238: } elsif ($choice eq 'chgdates') {
4239: if ($role eq 'st') {
1.52 raeburn 4240: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4241: } else {
4242: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4243: $start,'','',$context);
1.11 raeburn 4244: }
4245: } elsif ($choice eq 'chgsec') {
4246: my (@newsecs,$revresult,$nochg,@retained);
4247: if ($role ne 'cc') {
4248: @newsecs = split(/,/,$env{'form.newsecs'});
4249: }
4250: # remove existing section if not to be retained.
4251: if (!$env{'form.retainsec'}) {
4252: if ($sec eq '') {
4253: if (@newsecs == 0) {
4254: $result = &mt('No change in section assignment (none)');
4255: $nochg = 1;
1.40 raeburn 4256: } else {
4257: $revresult =
4258: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4259: $scope,$role,
4260: '','',$context);
1.40 raeburn 4261: }
1.11 raeburn 4262: } else {
1.28 raeburn 4263: if (@newsecs > 0) {
4264: if (grep(/^\Q$sec\E$/,@newsecs)) {
4265: push(@retained,$sec);
4266: } else {
4267: $revresult =
4268: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4269: $scope,$role,
4270: '','',$context);
1.28 raeburn 4271: }
4272: } else {
1.11 raeburn 4273: $revresult =
1.28 raeburn 4274: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4275: $scope,$role,
4276: '','',$context);
1.11 raeburn 4277: }
4278: }
4279: } else {
1.28 raeburn 4280: if ($sec eq '') {
4281: $nochg = 1;
4282: } else {
4283: push(@retained,$sec);
4284: }
1.11 raeburn 4285: }
4286: # add new sections
4287: if (@newsecs == 0) {
4288: if (!$nochg) {
1.28 raeburn 4289: if ($role eq 'st') {
4290: $result =
1.52 raeburn 4291: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
1.28 raeburn 4292: } else {
4293: my $newscope = $scopestem;
1.52 raeburn 4294: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 4295: }
4296: }
4297: } else {
4298: foreach my $newsec (@newsecs) {
4299: if (!grep(/^\Q$newsec\E$/,@retained)) {
4300: if ($role eq 'st') {
1.52 raeburn 4301: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4302: } else {
4303: my $newscope = $scopestem;
4304: if ($newsec ne '') {
4305: $newscope .= '/'.$newsec;
4306: }
4307: $result = &Apache::lonnet::assignrole($udom,$uname,
4308: $newscope,$role,$end,$start);
4309: }
4310: }
4311: }
4312: }
4313: }
4314: }
1.17 raeburn 4315: my $extent = $scope;
4316: if ($choice eq 'drop' || $context eq 'course') {
4317: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
4318: if ($cdesc) {
4319: $extent = $cdesc;
4320: }
4321: }
1.1 raeburn 4322: if ($result eq 'ok' || $result eq 'ok:') {
1.11 raeburn 4323: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
1.17 raeburn 4324: $plrole,$extent,$uname.':'.$udom).'<br />');
1.1 raeburn 4325: $count++;
4326: } else {
4327: $r->print(
1.29 raeburn 4328: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
1.17 raeburn 4329: $plrole,$extent,$uname.':'.$udom,$result).'<br />');
1.11 raeburn 4330: }
4331: }
1.32 raeburn 4332: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 4333: if ($choice eq 'drop') {
4334: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
4335: '<input type="hidden" name="Status" value="Active" />'."\n".
4336: '<input type="hidden" name="showrole" value="st" />'."\n");
4337: } else {
4338: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
4339: if ($env{'form.'.$item} ne '') {
4340: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
4341: '" />'."\n");
4342: }
1.32 raeburn 4343: }
4344: }
1.29 raeburn 4345: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
1.11 raeburn 4346: if ($count > 0) {
1.17 raeburn 4347: if ($choice eq 'revoke' || $choice eq 'drop') {
1.74 bisitz 4348: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
1.11 raeburn 4349: }
4350: # Flush the course logs so reverse user roles immediately updated
4351: &Apache::lonnet::flushcourselogs();
4352: }
4353: if ($env{'form.makedatesdefault'}) {
4354: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.29 raeburn 4355: $r->print(&make_dates_default($startdate,$enddate,$context));
1.1 raeburn 4356: }
4357: }
1.33 raeburn 4358: my $linktext = &mt('Display User Lists');
4359: if ($choice eq 'drop') {
4360: $linktext = &mt('Display current class roster');
4361: }
4362: $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
1.1 raeburn 4363: }
4364:
1.8 raeburn 4365: sub classlist_drop {
1.29 raeburn 4366: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 4367: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 4368: if (&Apache::lonnet::is_course($cdom,$cnum)) {
1.8 raeburn 4369: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
1.63 raeburn 4370: my %user;
4371: my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
1.8 raeburn 4372: return &mt('Drop from classlist: [_1]',
4373: '<b>'.$result.'</b>').'<br />';
4374: }
4375: }
4376: }
4377:
4378: sub active_student_roles {
4379: my ($cnum,$cdom,$uname,$udom) = @_;
4380: my %roles =
4381: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
4382: ['future','active'],['st']);
4383: return exists($roles{"$cnum:$cdom:st"});
4384: }
4385:
1.1 raeburn 4386: sub section_check_js {
1.8 raeburn 4387: my $groupslist= &get_groupslist();
1.1 raeburn 4388: return <<"END";
4389: function validate(caller) {
1.9 raeburn 4390: var groups = new Array($groupslist);
1.1 raeburn 4391: var secname = caller.value;
4392: if ((secname == 'all') || (secname == 'none')) {
4393: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
4394: return 'error';
4395: }
4396: if (secname != '') {
4397: for (var k=0; k<groups.length; k++) {
4398: if (secname == groups[k]) {
4399: 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.");
4400: return 'error';
4401: }
4402: }
4403: }
4404: return 'ok';
4405: }
4406: END
4407: }
4408:
4409: sub set_login {
4410: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
4411: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4412: my $response;
4413: my ($authnum,%can_assign) =
4414: &Apache::loncommon::get_assignable_auth($dom);
4415: if ($authnum) {
4416: $response = &Apache::loncommon::start_data_table();
4417: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
4418: $response .= &Apache::loncommon::start_data_table_row().
4419: '<td>'.$authformkrb.'</td>'.
4420: &Apache::loncommon::end_data_table_row()."\n";
4421: }
4422: if ($can_assign{'int'}) {
4423: $response .= &Apache::loncommon::start_data_table_row().
4424: '<td>'.$authformint.'</td>'.
4425: &Apache::loncommon::end_data_table_row()."\n"
4426: }
4427: if ($can_assign{'loc'}) {
4428: $response .= &Apache::loncommon::start_data_table_row().
4429: '<td>'.$authformloc.'</td>'.
4430: &Apache::loncommon::end_data_table_row()."\n";
4431: }
4432: $response .= &Apache::loncommon::end_data_table();
4433: }
4434: return $response;
4435: }
4436:
1.8 raeburn 4437: sub course_sections {
1.51 raeburn 4438: my ($sections_count,$role,$current_sec) = @_;
1.8 raeburn 4439: my $output = '';
4440: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.29 raeburn 4441: my $numsec = scalar(@sections);
1.51 raeburn 4442: my $is_selected = ' selected="selected" ';
1.29 raeburn 4443: if ($numsec <= 1) {
1.8 raeburn 4444: $output = '<select name="currsec_'.$role.'" >'."\n".
1.51 raeburn 4445: ' <option value="">'.&mt('Select').'</option>'."\n";
4446: if ($current_sec eq 'none') {
4447: $output .=
4448: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
4449: } else {
4450: $output .=
1.29 raeburn 4451: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 4452: }
1.29 raeburn 4453: if ($numsec == 1) {
1.51 raeburn 4454: if ($current_sec eq $sections[0]) {
4455: $output .=
4456: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
4457: } else {
4458: $output .=
1.8 raeburn 4459: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 4460: }
1.29 raeburn 4461: }
1.8 raeburn 4462: } else {
4463: $output = '<select name="currsec_'.$role.'" ';
4464: my $multiple = 4;
4465: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 4466: if ($role eq 'st') {
4467: $output .= '>'."\n".
1.51 raeburn 4468: ' <option value="">'.&mt('Select').'</option>'."\n";
4469: if ($current_sec eq 'none') {
4470: $output .=
4471: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
4472: } else {
4473: $output .=
1.29 raeburn 4474: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 4475: }
1.29 raeburn 4476: } else {
4477: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
4478: }
1.8 raeburn 4479: foreach my $sec (@sections) {
1.51 raeburn 4480: if ($current_sec eq $sec) {
4481: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
4482: } else {
4483: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
4484: }
1.8 raeburn 4485: }
4486: }
4487: $output .= '</select>';
4488: return $output;
4489: }
4490:
4491: sub get_groupslist {
4492: my $groupslist;
4493: my %curr_groups = &Apache::longroup::coursegroups();
4494: if (%curr_groups) {
4495: $groupslist = join('","',sort(keys(%curr_groups)));
4496: $groupslist = '"'.$groupslist.'"';
4497: }
1.11 raeburn 4498: return $groupslist;
1.8 raeburn 4499: }
4500:
4501: sub setsections_javascript {
1.37 raeburn 4502: my ($formname,$groupslist,$mode,$checkauth) = @_;
1.28 raeburn 4503: my ($checkincluded,$finish,$rolecode,$setsection_js);
4504: if ($mode eq 'upload') {
4505: $checkincluded = 'formname.name == "'.$formname.'"';
4506: $finish = "return 'ok';";
4507: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
4508: } elsif ($formname eq 'cu') {
1.8 raeburn 4509: $checkincluded = 'formname.elements[i-1].checked == true';
1.37 raeburn 4510: if ($checkauth) {
4511: $finish = "var authcheck = auth_check();\n".
4512: " if (authcheck == 'ok') {\n".
4513: " formname.submit();\n".
4514: " }\n";
4515: } else {
4516: $finish = 'formname.submit()';
4517: }
1.28 raeburn 4518: $rolecode = "var match = str.split('_');
4519: var role = match[3];\n";
4520: } elsif ($formname eq 'enrollstudent') {
4521: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 4522: if ($checkauth) {
4523: $finish = "var authcheck = auth_check();\n".
4524: " if (authcheck == 'ok') {\n".
4525: " formname.submit();\n".
4526: " }\n";
4527: } else {
4528: $finish = 'formname.submit()';
4529: }
1.28 raeburn 4530: $rolecode = "var match = str.split('_');
4531: var role = match[1];\n";
1.8 raeburn 4532: } else {
1.28 raeburn 4533: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 4534: $finish = "seccheck = 'ok';";
1.28 raeburn 4535: $rolecode = "var match = str.split('_');
4536: var role = match[1];\n";
1.11 raeburn 4537: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 4538: }
4539: my %alerts = &Apache::lonlocal::texthash(
4540: secd => 'Section designations do not apply to Course Coordinator roles.',
4541: accr => 'A course coordinator role will be added with access to all sections.',
4542: inea => 'In each course, each user may only have one student role at a time.',
4543: youh => 'You had selected ',
4544: secs => 'sections.',
4545: plmo => 'Please modify your selections so they include no more than one section.',
4546: mayn => 'may not be used as the name for a section, as it is a reserved word.',
4547: plch => 'Please choose a different section name.',
4548: mnot => 'may not be used as a section name, as it is the name of a course group.',
4549: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.11 raeburn 4550: );
1.8 raeburn 4551: $setsection_js .= <<"ENDSECCODE";
4552:
4553: function setSections(formname) {
4554: var re1 = /^currsec_/;
4555: var groups = new Array($groupslist);
4556: for (var i=0;i<formname.elements.length;i++) {
4557: var str = formname.elements[i].name;
4558: var checkcurr = str.match(re1);
4559: if (checkcurr != null) {
4560: if ($checkincluded) {
1.28 raeburn 4561: $rolecode
1.8 raeburn 4562: if (role == 'cc') {
4563: alert("$alerts{'secd'}\\n$alerts{'accr'}");
4564: }
4565: else {
4566: var sections = '';
4567: var numsec = 0;
4568: var sections;
4569: for (var j=0; j<formname.elements[i].length; j++) {
4570: if (formname.elements[i].options[j].selected == true ) {
4571: if (formname.elements[i].options[j].value != "") {
4572: if (numsec == 0) {
4573: if (formname.elements[i].options[j].value != "") {
4574: sections = formname.elements[i].options[j].value;
4575: numsec ++;
4576: }
4577: }
4578: else {
4579: sections = sections + "," + formname.elements[i].options[j].value
4580: numsec ++;
4581: }
4582: }
4583: }
4584: }
4585: if (numsec > 0) {
4586: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
4587: sections = sections + "," + formname.elements[i+1].value;
4588: }
4589: }
4590: else {
4591: sections = formname.elements[i+1].value;
4592: }
4593: var newsecs = formname.elements[i+1].value;
4594: var numsplit;
4595: if (newsecs != null && newsecs != "") {
4596: numsplit = newsecs.split(/,/g);
4597: numsec = numsec + numsplit.length;
4598: }
4599:
4600: if ((role == 'st') && (numsec > 1)) {
4601: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
4602: return;
4603: }
4604: else {
4605: if (numsplit != null) {
4606: for (var j=0; j<numsplit.length; j++) {
4607: if ((numsplit[j] == 'all') ||
4608: (numsplit[j] == 'none')) {
4609: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
4610: return;
4611: }
4612: for (var k=0; k<groups.length; k++) {
4613: if (numsplit[j] == groups[k]) {
4614: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
4615: return;
4616: }
4617: }
4618: }
4619: }
4620: formname.elements[i+2].value = sections;
4621: }
4622: }
4623: }
4624: }
4625: }
4626: $finish
4627: }
4628: ENDSECCODE
1.11 raeburn 4629: return $setsection_js;
1.8 raeburn 4630: }
4631:
1.15 raeburn 4632: sub can_create_user {
4633: my ($dom,$context,$usertype) = @_;
4634: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4635: my $cancreate = 1;
1.28 raeburn 4636: if (&Apache::lonnet::allowed('mau',$dom)) {
4637: return $cancreate;
4638: }
1.15 raeburn 4639: if (ref($domconf{'usercreation'}) eq 'HASH') {
4640: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
4641: if ($context eq 'course' || $context eq 'author') {
4642: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
4643: if ($creation eq 'none') {
4644: $cancreate = 0;
4645: } elsif ($creation ne 'any') {
4646: if (defined($usertype)) {
4647: if ($creation ne $usertype) {
4648: $cancreate = 0;
4649: }
4650: }
4651: }
4652: }
4653: }
4654: }
4655: return $cancreate;
4656: }
4657:
1.20 raeburn 4658: sub can_modify_userinfo {
4659: my ($context,$dom,$fields,$userroles) = @_;
4660: my %domconfig =
4661: &Apache::lonnet::get_dom('configuration',['usermodification'],
4662: $dom);
4663: my %canmodify;
4664: if (ref($fields) eq 'ARRAY') {
4665: foreach my $field (@{$fields}) {
4666: $canmodify{$field} = 0;
4667: if (&Apache::lonnet::allowed('mau',$dom)) {
4668: $canmodify{$field} = 1;
4669: } else {
4670: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4671: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
4672: if (ref($userroles) eq 'ARRAY') {
4673: foreach my $role (@{$userroles}) {
4674: my $testrole;
1.60 raeburn 4675: if ($context eq 'selfcreate') {
4676: $testrole = $role;
1.20 raeburn 4677: } else {
1.60 raeburn 4678: if ($role =~ /^cr\//) {
4679: $testrole = 'cr';
4680: } else {
4681: $testrole = $role;
4682: }
1.20 raeburn 4683: }
4684: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
4685: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
4686: $canmodify{$field} = 1;
4687: last;
4688: }
4689: }
4690: }
4691: } else {
4692: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
4693: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
4694: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
4695: $canmodify{$field} = 1;
4696: last;
4697: }
4698: }
4699: }
4700: }
4701: }
4702: } elsif ($context eq 'course') {
4703: if (ref($userroles) eq 'ARRAY') {
4704: if (grep(/^st$/,@{$userroles})) {
4705: $canmodify{$field} = 1;
4706: }
4707: } else {
4708: $canmodify{$field} = 1;
4709: }
4710: }
4711: }
4712: }
4713: }
4714: return %canmodify;
4715: }
4716:
1.18 raeburn 4717: sub check_usertype {
4718: my ($dom,$uname,$rules) = @_;
4719: my $usertype;
4720: if (ref($rules) eq 'HASH') {
4721: my @user_rules = keys(%{$rules});
4722: if (@user_rules > 0) {
4723: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
4724: if (keys(%rule_check) > 0) {
4725: $usertype = 'unofficial';
4726: foreach my $item (keys(%rule_check)) {
4727: if ($rule_check{$item}) {
4728: $usertype = 'official';
4729: last;
4730: }
4731: }
4732: }
4733: }
4734: }
4735: return $usertype;
4736: }
4737:
1.17 raeburn 4738: sub roles_by_context {
4739: my ($context,$custom) = @_;
4740: my @allroles;
4741: if ($context eq 'course') {
4742: @allroles = ('st','ad','ta','ep','in','cc');
4743: if ($custom) {
4744: push(@allroles,'cr');
4745: }
4746: } elsif ($context eq 'author') {
4747: @allroles = ('ca','aa');
4748: } elsif ($context eq 'domain') {
4749: @allroles = ('li','dg','sc','au','dc');
4750: }
4751: return @allroles;
4752: }
4753:
1.16 raeburn 4754: sub get_permission {
1.17 raeburn 4755: my ($context,$roles) = @_;
1.16 raeburn 4756: my %permission;
4757: if ($context eq 'course') {
1.17 raeburn 4758: my $custom = 1;
4759: my @allroles = &roles_by_context($context,$custom);
4760: foreach my $role (@allroles) {
4761: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
4762: $permission{'cusr'} = 1;
4763: last;
4764: }
1.16 raeburn 4765: }
4766: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
4767: $permission{'custom'} = 1;
4768: }
4769: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
4770: $permission{'view'} = 1;
4771: }
4772: if (!$permission{'view'}) {
4773: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4774: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
4775: if ($permission{'view'}) {
4776: $permission{'view_section'} = $env{'request.course.sec'};
4777: }
4778: }
1.17 raeburn 4779: if (!$permission{'cusr'}) {
4780: if ($env{'request.course.sec'} ne '') {
4781: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4782: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
4783: if ($permission{'cusr'}) {
4784: $permission{'cusr_section'} = $env{'request.course.sec'};
4785: }
4786: }
4787: }
1.16 raeburn 4788: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
4789: $permission{'grp_manage'} = 1;
4790: }
4791: } elsif ($context eq 'author') {
4792: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
4793: $permission{'view'} = $permission{'cusr'};
4794: } else {
1.17 raeburn 4795: my @allroles = &roles_by_context($context);
4796: foreach my $role (@allroles) {
1.28 raeburn 4797: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
4798: $permission{'cusr'} = 1;
1.17 raeburn 4799: last;
4800: }
4801: }
4802: if (!$permission{'cusr'}) {
4803: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
4804: $permission{'cusr'} = 1;
4805: }
1.16 raeburn 4806: }
4807: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
4808: $permission{'custom'} = 1;
4809: }
4810: $permission{'view'} = $permission{'cusr'};
4811: }
4812: my $allowed = 0;
4813: foreach my $perm (values(%permission)) {
4814: if ($perm) { $allowed=1; last; }
4815: }
4816: return (\%permission,$allowed);
4817: }
4818:
4819: # ==================================================== Figure out author access
4820:
4821: sub authorpriv {
4822: my ($auname,$audom)=@_;
4823: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
4824: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
4825: }
4826:
1.27 raeburn 4827: sub roles_on_upload {
1.42 raeburn 4828: my ($context,$setting,%customroles) = @_;
1.27 raeburn 4829: my (@possible_roles,@permitted_roles);
1.42 raeburn 4830: @possible_roles = &curr_role_permissions($context,$setting,1);
1.27 raeburn 4831: foreach my $role (@possible_roles) {
4832: if ($role eq 'cr') {
4833: push(@permitted_roles,keys(%customroles));
4834: } else {
4835: push(@permitted_roles,$role);
4836: }
4837: }
1.42 raeburn 4838: return @permitted_roles;
1.27 raeburn 4839: }
4840:
1.17 raeburn 4841: sub get_course_identity {
4842: my ($cid) = @_;
4843: my ($cnum,$cdom,$cdesc);
4844: if ($cid eq '') {
4845: $cid = $env{'request.course.id'}
4846: }
4847: if ($cid ne '') {
4848: $cnum = $env{'course.'.$cid.'.num'};
4849: $cdom = $env{'course.'.$cid.'.domain'};
4850: $cdesc = $env{'course.'.$cid.'.description'};
4851: if ($cnum eq '' || $cdom eq '') {
4852: my %coursehash =
4853: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
4854: $cdom = $coursehash{'domain'};
4855: $cnum = $coursehash{'num'};
4856: $cdesc = $coursehash{'description'};
4857: }
4858: }
4859: return ($cnum,$cdom,$cdesc);
4860: }
4861:
1.19 raeburn 4862: sub dc_setcourse_js {
1.37 raeburn 4863: my ($formname,$mode,$context) = @_;
4864: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 4865: my $cctext = &Apache::lonnet::plaintext('cc');
4866: my %alerts = §ioncheck_alerts();
4867: my $role = 'role';
4868: if ($mode eq 'upload') {
4869: $role = 'courserole';
1.37 raeburn 4870: } else {
4871: $authen_check = &verify_authen($formname,$context);
1.19 raeburn 4872: }
4873: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 4874: $authen_check
4875:
1.19 raeburn 4876: function setCourse() {
4877: var course = document.$formname.dccourse.value;
4878: if (course != "") {
4879: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
4880: alert("$alerts{'curd'}");
4881: return;
4882: }
4883: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
4884: var section="";
4885: var numsections = 0;
4886: var newsecs = new Array();
4887: for (var i=0; i<document.$formname.currsec.length; i++) {
4888: if (document.$formname.currsec.options[i].selected == true ) {
4889: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
4890: if (numsections == 0) {
4891: section = document.$formname.currsec.options[i].value
4892: numsections = 1;
4893: }
4894: else {
4895: section = section + "," + document.$formname.currsec.options[i].value
4896: numsections ++;
4897: }
4898: }
4899: }
4900: }
4901: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
4902: if (numsections == 0) {
4903: section = document.$formname.newsec.value
4904: }
4905: else {
4906: section = section + "," + document.$formname.newsec.value
4907: }
4908: newsecs = document.$formname.newsec.value.split(/,/g);
4909: numsections = numsections + newsecs.length;
4910: }
4911: if ((userrole == 'st') && (numsections > 1)) {
4912: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
4913: return;
4914: }
4915: for (var j=0; j<newsecs.length; j++) {
4916: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
4917: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
4918: return;
4919: }
4920: if (document.$formname.groups.value != '') {
4921: var groups = document.$formname.groups.value.split(/,/g);
4922: for (var k=0; k<groups.length; k++) {
4923: if (newsecs[j] == groups[k]) {
4924: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
4925: return;
4926: }
4927: }
4928: }
4929: }
4930: if ((userrole == 'cc') && (numsections > 0)) {
4931: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
4932: section = "";
4933: }
4934: SCRIPTTOP
4935: if ($mode ne 'upload') {
4936: $dc_setcourse_code .= (<<"ENDSCRIPT");
4937: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
4938: var numcourse = getIndex(document.$formname.dccourse);
4939: if (numcourse == "-1") {
4940: alert("$alerts{'thwa'}");
4941: return;
4942: }
4943: else {
4944: document.$formname.elements[numcourse].name = "act"+coursename;
4945: var numnewsec = getIndex(document.$formname.newsec);
4946: if (numnewsec != "-1") {
4947: document.$formname.elements[numnewsec].name = "sec"+coursename;
4948: document.$formname.elements[numnewsec].value = section;
4949: }
4950: var numstart = getIndex(document.$formname.start);
4951: if (numstart != "-1") {
4952: document.$formname.elements[numstart].name = "start"+coursename;
4953: }
4954: var numend = getIndex(document.$formname.end);
4955: if (numend != "-1") {
4956: document.$formname.elements[numend].name = "end"+coursename
4957: }
4958: }
4959: }
1.37 raeburn 4960: var authcheck = auth_check();
4961: if (authcheck == 'ok') {
4962: document.$formname.submit();
4963: }
1.19 raeburn 4964: }
4965: ENDSCRIPT
4966: } else {
4967: $dc_setcourse_code .= "
4968: document.$formname.sections.value = section;
4969: }
4970: return 'ok';
4971: }
4972: ";
4973: }
4974: $dc_setcourse_code .= (<<"ENDSCRIPT");
4975:
4976: function getIndex(caller) {
4977: for (var i=0;i<document.$formname.elements.length;i++) {
4978: if (document.$formname.elements[i] == caller) {
4979: return i;
4980: }
4981: }
4982: return -1;
4983: }
4984: ENDSCRIPT
1.37 raeburn 4985: return $dc_setcourse_code;
4986: }
4987:
4988: sub verify_authen {
4989: my ($formname,$context) = @_;
4990: my %alerts = &authcheck_alerts();
4991: my $finish = "return 'ok';";
4992: if ($context eq 'author') {
4993: $finish = "document.$formname.submit();";
4994: }
4995: my $outcome = <<"ENDSCRIPT";
4996:
4997: function auth_check() {
4998: var logintype;
4999: if (document.$formname.login.length) {
5000: if (document.$formname.login.length > 0) {
5001: var loginpicked = 0;
5002: for (var i=0; i<document.$formname.login.length; i++) {
5003: if (document.$formname.login[i].checked == true) {
5004: loginpicked = 1;
5005: logintype = document.$formname.login[i].value;
5006: }
5007: }
5008: if (loginpicked == 0) {
5009: alert("$alerts{'authen'}");
5010: return;
5011: }
5012: }
5013: } else {
5014: logintype = document.$formname.login.value;
5015: }
5016: if (logintype == 'nochange') {
5017: return 'ok';
5018: }
5019: var argpicked = document.$formname.elements[logintype+'arg'].value;
5020: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
5021: var alertmsg = '';
5022: switch (logintype) {
5023: case 'krb':
5024: alertmsg = '$alerts{'krb'}';
5025: break;
5026: case 'int':
5027: alertmsg = '$alerts{'ipass'}';
5028: case 'fsys':
5029: alertmsg = '$alerts{'ipass'}';
5030: break;
5031: case 'loc':
5032: alertmsg = '';
5033: break;
5034: default:
5035: alertmsg = '';
5036: }
5037: if (alertmsg != '') {
5038: alert(alertmsg);
5039: return;
5040: }
5041: }
5042: $finish
5043: }
5044: ENDSCRIPT
1.19 raeburn 5045: }
5046:
5047: sub sectioncheck_alerts {
5048: my %alerts = &Apache::lonlocal::texthash(
5049: curd => 'You must select a course in the current domain',
5050: inea => 'In each course, each user may only have one student role at a time',
5051: youh => 'You had selected',
5052: sect => 'sections',
5053: plsm => 'Please modify your selections so they include no more than one section',
5054: mayn => 'may not be used as the name for a section, as it is a reserved word',
5055: plsc => 'Please choose a different section name',
5056: mayt => 'may not be used as the name for a section, as it is the name of a course group',
5057: secn => 'Section names and group names must be distinct',
5058: secd => 'Section designations do not apply to ',
5059: role => 'roles',
5060: accr => 'role will be added with access to all sections',
5061: thwa => 'There was a problem with your course selection'
5062: );
5063: return %alerts;
5064: }
1.17 raeburn 5065:
1.37 raeburn 5066: sub authcheck_alerts {
5067: my %alerts =
5068: &Apache::lonlocal::texthash(
5069: authen => 'You must choose an authentication type.',
5070: krb => 'You need to specify the Kerberos domain.',
5071: ipass => 'You need to specify the initial password.',
5072: );
5073: return %alerts;
5074: }
5075:
1.1 raeburn 5076: 1;
5077:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>