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