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