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