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