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