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