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