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