Annotation of loncom/interface/lonuserutils.pm, revision 1.54
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Utility functions for managing LON-CAPA user accounts
3: #
1.54 ! raeburn 4: # $Id: lonuserutils.pm,v 1.53 2008/05/09 17:55:25 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.10 raeburn 1866: my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
1.1 raeburn 1867: #
1868: # Variables for excel output
1869: my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
1870: #
1871: # Variables for csv output
1872: my ($CSVfile,$CSVfilename);
1873: #
1874: my $sortby = $env{'form.sortby'};
1.3 raeburn 1875: my @sortable = ('username','domain','id','fullname','start','end','email','role');
1.2 raeburn 1876: if ($context eq 'course') {
1.3 raeburn 1877: push(@sortable,('section','groups','type'));
1.2 raeburn 1878: } else {
1.3 raeburn 1879: push(@sortable,'extent');
1880: }
1881: if (!grep(/^\Q$sortby\E$/,@sortable)) {
1882: $sortby = 'username';
1.1 raeburn 1883: }
1.22 raeburn 1884: my $setting = $env{'form.roletype'};
1.35 raeburn 1885: my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
1.1 raeburn 1886: if ($context eq 'course') {
1.22 raeburn 1887: $cid = $env{'request.course.id'};
1.17 raeburn 1888: ($cnum,$cdom) = &get_course_identity($cid);
1.2 raeburn 1889: ($classgroups) = &Apache::loncoursedata::get_group_memberships(
1890: $userlist,$keylist,$cdom,$cnum);
1.16 raeburn 1891: if ($mode eq 'autoenroll') {
1892: $env{'form.showrole'} = 'st';
1893: } else {
1894: if (! exists($env{'form.displayphotos'})) {
1895: $env{'form.displayphotos'} = 'off';
1896: }
1897: $displayphotos = $env{'form.displayphotos'};
1898: if (! exists($env{'form.displayclickers'})) {
1899: $env{'form.displayclickers'} = 'off';
1900: }
1901: $displayclickers = $env{'form.displayclickers'};
1902: if ($env{'course.'.$cid.'.internal.showphoto'}) {
1903: $r->print('
1.1 raeburn 1904: <script type="text/javascript">
1905: function photowindow(photolink) {
1906: var title = "Photo_Viewer";
1907: var options = "scrollbars=1,resizable=1,menubar=0";
1908: options += ",width=240,height=240";
1909: stdeditbrowser = open(photolink,title,options,"1");
1910: stdeditbrowser.focus();
1911: }
1912: </script>
1.16 raeburn 1913: ');
1914: }
1915: $r->print(<<END);
1.1 raeburn 1916: <input type="hidden" name="displayphotos" value="$displayphotos" />
1917: <input type="hidden" name="displayclickers" value="$displayclickers" />
1918: END
1.16 raeburn 1919: }
1.1 raeburn 1920: }
1.16 raeburn 1921: if ($mode ne 'autoenroll') {
1.11 raeburn 1922: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1923: my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
1.25 raeburn 1924: my $singconfirm = &mt(' for a single user?');
1925: my $multconfirm = &mt(' for multiple users?');
1.40 raeburn 1926: my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
1927: my %lt = &Apache::lonlocal::texthash(
1928: acwi => 'Access will be set to start immediately',
1929: asyo => 'as you did not select an end date in the pop-up window',
1930: accw => 'Access will be set to continue indefinitely',
1931: asyd => 'as you did not select an end date in the pop-up window',
1932: sewi => "Sections will be switched to 'No section'",
1933: ayes => "as you either selected the 'No section' option",
1934: oryo => 'or you did not select a section in the pop-up window',
1935: arol => 'A role with no section will be added',
1936: swbs => 'Sections will be switched to:',
1937: rwba => 'Roles will be added for section(s):',
1938: );
1.1 raeburn 1939: $r->print(<<END);
1.10 raeburn 1940:
1941: <script type="text/javascript" language="Javascript">
1.11 raeburn 1942: $check_uncheck_js
1943:
1944: function verify_action (field) {
1945: var numchecked = 0;
1946: var singconf = '$singconfirm';
1947: var multconf = '$multconfirm';
1948: if (field.length > 0) {
1949: for (i = 0; i < field.length; i++) {
1950: if (field[i].checked == true) {
1951: numchecked ++;
1952: }
1953: }
1954: } else {
1955: if (field.checked == true) {
1956: numchecked ++;
1957: }
1958: }
1959: if (numchecked == 0) {
1960: alert("$alert");
1961: }
1962: else {
1963: var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
1.40 raeburn 1964: var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value;
1.11 raeburn 1965: if (numchecked == 1) {
1966: message += singconf;
1967: }
1968: else {
1969: message += multconf;
1970: }
1.40 raeburn 1971: if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
1972: var datemsg = '';
1973: if ((document.studentform.startdate_month.value == '') &&
1974: (document.studentform.startdate_day.value == '') &&
1975: (document.studentform.startdate_year.value == '')) {
1976: datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
1977: }
1978: if ((document.studentform.enddate_month.value == '') &&
1979: (document.studentform.enddate_day.value == '') &&
1980: (document.studentform.enddate_year.value == '')) {
1981: datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
1982: }
1983: if (datemsg != '') {
1984: message += "\\n"+datemsg;
1985: }
1986: }
1987: if (choice == 'chgsec') {
1988: var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value;
1989: var retained = document.studentform.retainsec.value;
1990: var secshow = document.studentform.newsecs.value;
1991: if (secshow == '') {
1992: if (rolefilter == 'st' || retained == 0 || retained == "") {
1993: message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
1994: } else {
1995: message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
1996: }
1997: } else {
1998: if (rolefilter == 'st' || retained == 0 || retained == "") {
1999: message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
2000: } else {
2001: message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
2002: }
2003: }
2004: }
1.11 raeburn 2005: if (confirm(message)) {
2006: document.studentform.phase.value = 'bulkchange';
2007: document.studentform.submit();
2008: }
2009: }
2010: }
1.10 raeburn 2011:
2012: function username_display_launch(username,domain) {
2013: var target;
2014: for (var i=0; i<document.studentform.usernamelink.length; i++) {
2015: if (document.studentform.usernamelink[i].checked) {
2016: target = document.studentform.usernamelink[i].value;
2017: }
2018: }
2019: if (target == 'modify') {
1.50 raeburn 2020: if (document.studentform.userwin.checked == true) {
2021: var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';
2022: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2023: modifywin = window.open(url,'',options,1);
2024: modifywin.focus();
2025: return;
2026: } else {
2027: document.studentform.srchterm.value=username;
2028: document.studentform.srchdomain.value=domain;
2029: document.studentform.phase.value='get_user_info';
2030: document.studentform.action.value = 'singleuser';
2031: document.studentform.submit();
2032: }
1.10 raeburn 2033: }
1.48 raeburn 2034: if (target == 'aboutme') {
1.50 raeburn 2035: if (document.studentform.userwin.checked == true) {
2036: var url = '/adm/'+domain+'/'+username+'/aboutme?popup=1';
2037: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2038: aboutmewin = window.open(url,'',options,1);
2039: aboutmewin.focus();
2040: return;
2041: } else {
2042: document.location.href = '/adm/'+domain+'/'+username+'/aboutme';
2043: }
1.48 raeburn 2044: }
1.10 raeburn 2045: }
2046: </script>
1.11 raeburn 2047: $date_sec_selector
1.1 raeburn 2048: <input type="hidden" name="state" value="$env{'form.state'}" />
2049: END
2050: }
2051: $r->print(<<END);
2052: <input type="hidden" name="sortby" value="$sortby" />
2053: END
2054:
2055: my %lt=&Apache::lonlocal::texthash(
2056: 'username' => "username",
2057: 'domain' => "domain",
2058: 'id' => 'ID',
2059: 'fullname' => "name",
2060: 'section' => "section",
2061: 'groups' => "active groups",
2062: 'start' => "start date",
2063: 'end' => "end date",
2064: 'status' => "status",
1.2 raeburn 2065: 'role' => "role",
1.1 raeburn 2066: 'type' => "enroll type/action",
2067: 'email' => "email address",
2068: 'clicker' => "clicker id",
2069: 'photo' => "photo",
1.2 raeburn 2070: 'extent' => "extent",
1.41 raeburn 2071: 'go' => "go",
1.11 raeburn 2072: 'pr' => "Proceed",
2073: 'ca' => "check all",
2074: 'ua' => "uncheck all",
2075: 'ac' => "Action to take for selected users",
1.10 raeburn 2076: 'link' => "Behavior of username links",
2077: 'aboutme' => "Display a user's personal page",
1.50 raeburn 2078: 'owin' => "Open in a new window",
1.10 raeburn 2079: 'modify' => "Modify a user's information",
1.1 raeburn 2080: );
1.2 raeburn 2081: if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
2082: $lt{'extent'} = &mt('Course(s): description, section(s), status');
1.13 raeburn 2083: } elsif ($context eq 'author') {
1.2 raeburn 2084: $lt{'extent'} = &mt('Author');
2085: }
1.1 raeburn 2086: my @cols = ('username','domain','id','fullname');
2087: if ($context eq 'course') {
2088: push(@cols,'section');
2089: }
1.2 raeburn 2090: if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
2091: push(@cols,('start','end'));
2092: }
1.3 raeburn 2093: if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
1.2 raeburn 2094: push(@cols,'role');
2095: }
1.13 raeburn 2096: if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
1.2 raeburn 2097: $env{'form.roletype'} eq 'course')) {
2098: push (@cols,'extent');
2099: }
2100: if (($statusmode eq 'Any') &&
2101: (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
1.1 raeburn 2102: push(@cols,'status');
2103: }
2104: if ($context eq 'course') {
2105: push(@cols,'groups');
2106: }
2107: push(@cols,'email');
2108:
1.4 raeburn 2109: my $rolefilter = $env{'form.showrole'};
1.5 raeburn 2110: if ($env{'form.showrole'} eq 'cr') {
2111: $rolefilter = &mt('custom');
2112: } elsif ($env{'form.showrole'} ne 'Any') {
1.2 raeburn 2113: $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
2114: }
1.16 raeburn 2115: my $results_description;
2116: if ($mode ne 'autoenroll') {
2117: $results_description = &results_header_row($rolefilter,$statusmode,
1.24 raeburn 2118: $context,$permission,$mode);
1.16 raeburn 2119: $r->print('<b>'.$results_description.'</b><br />');
2120: }
1.26 raeburn 2121: my ($output,$actionselect,%canchange,%canchangesec);
1.16 raeburn 2122: if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
2123: if ($mode ne 'autoenroll') {
2124: if ($permission->{'cusr'}) {
2125: $actionselect = &select_actions($context,$setting,$statusmode);
2126: }
2127: $r->print(<<END);
1.10 raeburn 2128: <input type="hidden" name="srchby" value="uname" />
2129: <input type="hidden" name="srchin" value="dom" />
2130: <input type="hidden" name="srchtype" value="exact" />
2131: <input type="hidden" name="srchterm" value="" />
1.11 raeburn 2132: <input type="hidden" name="srchdomain" value="" />
1.1 raeburn 2133: END
1.16 raeburn 2134: $output = '<p>';
1.50 raeburn 2135: my @linkdests = ('aboutme');
1.16 raeburn 2136: if ($permission->{'cusr'}) {
1.48 raeburn 2137: unshift (@linkdests,'modify');
2138: }
2139: $output .= '<span class="LC_nobreak">'.$lt{'link'}.': ';
2140: my $usernamelink = $env{'form.usernamelink'};
2141: if ($usernamelink eq '') {
2142: $usernamelink = 'aboutme';
2143: }
2144: foreach my $item (@linkdests) {
2145: my $checkedstr = '';
2146: if ($item eq $usernamelink) {
2147: $checkedstr = ' checked="checked" ';
1.16 raeburn 2148: }
1.48 raeburn 2149: $output .= '<label><input type="radio" name="usernamelink" value="'.$item.'"'.$checkedstr.'> '.$lt{$item}.'</label> ';
1.16 raeburn 2150: }
1.50 raeburn 2151: my $checkwin;
2152: if ($env{'form.userwin'}) {
2153: $checkwin = 'checked = "checked"';
2154: }
2155: $output .= ' <input type="checkbox" name="userwin" value="1" $checkwin />'.$lt{'owin'}.'</span><br />';
1.16 raeburn 2156: if ($actionselect) {
1.41 raeburn 2157: $output .= <<"END";
2158: $lt{'ac'}: $actionselect <input type="button" value="$lt{'go'}" onclick="javascript:opendatebrowser(this.form,'studentform','go')" /></p>
1.11 raeburn 2159: <p><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.actionlist)" />
1.41 raeburn 2160: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.actionlist)" /><br /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action(document.studentform.actionlist)" />
1.11 raeburn 2161: END
1.26 raeburn 2162: my @allroles;
2163: if ($env{'form.showrole'} eq 'Any') {
2164: my $custom = 1;
2165: if ($context eq 'domain') {
2166: @allroles = &roles_by_context($setting,$custom);
2167: } else {
2168: @allroles = &roles_by_context($context,$custom);
2169: }
2170: } else {
2171: @allroles = ($env{'form.showrole'});
2172: }
2173: foreach my $role (@allroles) {
2174: if ($context eq 'domain') {
2175: if ($setting eq 'domain') {
2176: if (&Apache::lonnet::allowed('c'.$role,
2177: $env{'request.role.domain'})) {
2178: $canchange{$role} = 1;
2179: }
1.31 raeburn 2180: } elsif ($setting eq 'author') {
2181: if (&Apache::lonnet::allowed('c'.$role,
2182: $env{'request.role.domain'})) {
2183: $canchange{$role} = 1;
2184: }
1.26 raeburn 2185: }
2186: } elsif ($context eq 'author') {
2187: if (&Apache::lonnet::allowed('c'.$role,
2188: $env{'user.domain'}.'/'.$env{'user.name'})) {
2189: $canchange{$role} = 1;
2190: }
2191: } elsif ($context eq 'course') {
2192: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
2193: $canchange{$role} = 1;
2194: } elsif ($env{'request.course.sec'} ne '') {
2195: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2196: $canchangesec{$role} = $env{'request.course.sec'};
2197: }
2198: }
2199: }
2200: }
1.16 raeburn 2201: }
1.4 raeburn 2202: }
2203: $output .= "\n<p>\n".
1.1 raeburn 2204: &Apache::loncommon::start_data_table().
1.4 raeburn 2205: &Apache::loncommon::start_data_table_header_row();
1.1 raeburn 2206: if ($mode eq 'autoenroll') {
1.4 raeburn 2207: $output .= "
1.1 raeburn 2208: <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
1.4 raeburn 2209: ";
1.1 raeburn 2210: } else {
1.11 raeburn 2211: $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
2212: if ($actionselect) {
2213: $output .= '<th>'.&mt('Select').'</th>'."\n";
2214: }
1.1 raeburn 2215: }
2216: foreach my $item (@cols) {
1.4 raeburn 2217: $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
1.1 raeburn 2218: }
1.2 raeburn 2219: my %role_types = &role_type_names();
1.16 raeburn 2220: if ($context eq 'course' && $mode ne 'autoenroll') {
1.4 raeburn 2221: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2222: # Clicker display on or off?
2223: my %clicker_options = &Apache::lonlocal::texthash(
2224: 'on' => 'Show',
2225: 'off' => 'Hide',
2226: );
2227: my $clickerchg = 'on';
2228: if ($displayclickers eq 'on') {
2229: $clickerchg = 'off';
2230: }
2231: $output .= ' <th>'."\n".' '.
2232: '<a href="javascript:document.studentform.displayclickers.value='.
1.1 raeburn 2233: "'".$clickerchg."'".';document.studentform.submit();">'.
2234: $clicker_options{$clickerchg}.'</a> '.$lt{'clicker'}."\n".
1.4 raeburn 2235: ' </th>'."\n";
1.1 raeburn 2236:
1.4 raeburn 2237: # Photo display on or off?
2238: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2239: my %photo_options = &Apache::lonlocal::texthash(
2240: 'on' => 'Show',
2241: 'off' => 'Hide',
2242: );
2243: my $photochg = 'on';
2244: if ($displayphotos eq 'on') {
2245: $photochg = 'off';
2246: }
2247: $output .= ' <th>'."\n".' '.
2248: '<a href="javascript:document.studentform.displayphotos.value='.
1.1 raeburn 2249: "'".$photochg."'".';document.studentform.submit();">'.
2250: $photo_options{$photochg}.'</a> '.$lt{'photo'}."\n".
1.4 raeburn 2251: ' </th>'."\n";
2252: }
1.1 raeburn 2253: }
1.4 raeburn 2254: }
1.16 raeburn 2255: $output .= &Apache::loncommon::end_data_table_header_row();
1.1 raeburn 2256: # Done with the HTML header line
2257: } elsif ($mode eq 'csv') {
2258: #
2259: # Open a file
2260: $CSVfilename = '/prtspool/'.
1.2 raeburn 2261: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
2262: time.'_'.rand(1000000000).'.csv';
1.1 raeburn 2263: unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
2264: $r->log_error("Couldn't open $CSVfilename for output $!");
2265: $r->print("Problems occured in writing the csv file. ".
2266: "This error has been logged. ".
2267: "Please alert your LON-CAPA administrator.");
2268: $CSVfile = undef;
2269: }
2270: #
2271: # Write headers and data to file
1.2 raeburn 2272: print $CSVfile '"'.$results_description.'"'."\n";
1.1 raeburn 2273: print $CSVfile '"'.join('","',map {
2274: &Apache::loncommon::csv_translate($lt{$_})
2275: } (@cols)).'"'."\n";
2276: } elsif ($mode eq 'excel') {
2277: # Create the excel spreadsheet
2278: ($excel_workbook,$excel_filename,$format) =
2279: &Apache::loncommon::create_workbook($r);
2280: return if (! defined($excel_workbook));
2281: $excel_sheet = $excel_workbook->addworksheet('userlist');
1.2 raeburn 2282: $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
1.1 raeburn 2283: #
2284: my @colnames = map {$lt{$_}} (@cols);
2285: $excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
2286: }
2287:
2288: # Done with header lines in all formats
2289: my %index;
2290: my $i;
1.2 raeburn 2291: foreach my $idx (@$keylist) {
2292: $index{$idx} = $i++;
2293: }
1.4 raeburn 2294: my $usercount = 0;
1.33 raeburn 2295: my ($secfilter,$grpfilter);
2296: if ($context eq 'course') {
2297: $secfilter = $env{'form.secfilter'};
2298: $grpfilter = $env{'form.grpfilter'};
2299: if ($secfilter eq '') {
2300: $secfilter = 'all';
2301: }
2302: if ($grpfilter eq '') {
2303: $grpfilter = 'all';
2304: }
2305: }
1.2 raeburn 2306: # Get groups, role, permanent e-mail so we can sort on them if
2307: # necessary.
2308: foreach my $user (keys(%{$userlist})) {
1.43 raeburn 2309: if ($user eq '' ) {
2310: delete($userlist->{$user});
2311: next;
2312: }
1.11 raeburn 2313: if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
2314: delete($userlist->{$user});
2315: next;
2316: }
1.2 raeburn 2317: my ($uname,$udom,$role,$groups,$email);
1.5 raeburn 2318: if (($statusmode ne 'Any') &&
2319: ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
2320: delete($userlist->{$user});
2321: next;
2322: }
1.2 raeburn 2323: if ($context eq 'domain') {
2324: if ($env{'form.roletype'} eq 'domain') {
2325: ($role,$uname,$udom) = split(/:/,$user);
1.11 raeburn 2326: if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
2327: ($udom eq $env{'request.role.domain'})) {
2328: delete($userlist->{$user});
2329: next;
2330: }
1.13 raeburn 2331: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 2332: ($uname,$udom,$role) = split(/:/,$user,-1);
2333: } elsif ($env{'form.roletype'} eq 'course') {
2334: ($uname,$udom,$role) = split(/:/,$user);
2335: }
2336: } else {
2337: ($uname,$udom,$role) = split(/:/,$user,-1);
2338: if (($context eq 'course') && $role eq '') {
2339: $role = 'st';
2340: }
2341: }
2342: $userlist->{$user}->[$index{'role'}] = $role;
2343: if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
2344: delete($userlist->{$user});
2345: next;
2346: }
1.33 raeburn 2347: if ($context eq 'course') {
2348: my @ac_groups;
2349: if (ref($classgroups) eq 'HASH') {
2350: $groups = $classgroups->{$user};
2351: }
2352: if (ref($groups->{'active'}) eq 'HASH') {
2353: @ac_groups = keys(%{$groups->{'active'}});
2354: $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
2355: }
2356: if ($mode ne 'autoenroll') {
2357: my $section = $userlist->{$user}->[$index{'section'}];
1.43 raeburn 2358: if (($env{'request.course.sec'} ne '') &&
2359: ($section ne $env{'request.course.sec'})) {
2360: if ($role eq 'st') {
2361: delete($userlist->{$user});
2362: next;
2363: }
2364: }
1.33 raeburn 2365: if ($secfilter eq 'none') {
2366: if ($section ne '') {
2367: delete($userlist->{$user});
2368: next;
2369: }
2370: } elsif ($secfilter ne 'all') {
2371: if ($section ne $secfilter) {
2372: delete($userlist->{$user});
2373: next;
2374: }
2375: }
2376: if ($grpfilter eq 'none') {
2377: if (@ac_groups > 0) {
2378: delete($userlist->{$user});
2379: next;
2380: }
2381: } elsif ($grpfilter ne 'all') {
2382: if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
2383: delete($userlist->{$user});
2384: next;
2385: }
2386: }
1.44 raeburn 2387: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
2388: if (($displayphotos eq 'on') && ($role eq 'st')) {
2389: $userlist->{$user}->[$index{'photo'}] =
1.47 raeburn 2390: &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
2391: $userlist->{$user}->[$index{'thumbnail'}] =
1.44 raeburn 2392: &Apache::lonnet::retrievestudentphoto($udom,$uname,
2393: 'gif','thumbnail');
2394: }
2395: }
1.33 raeburn 2396: }
1.2 raeburn 2397: }
2398: my %emails = &Apache::loncommon::getemails($uname,$udom);
2399: if ($emails{'permanentemail'} =~ /\S/) {
2400: $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
2401: }
1.4 raeburn 2402: $usercount ++;
2403: }
2404: my $autocount = 0;
2405: my $manualcount = 0;
2406: my $lockcount = 0;
2407: my $unlockcount = 0;
2408: if ($usercount) {
2409: $r->print($output);
2410: } else {
2411: if ($mode eq 'autoenroll') {
2412: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
2413: } else {
2414: return;
2415: }
1.1 raeburn 2416: }
1.2 raeburn 2417: #
2418: # Sort the users
1.1 raeburn 2419: my $index = $index{$sortby};
2420: my $second = $index{'username'};
2421: my $third = $index{'domain'};
1.2 raeburn 2422: my @sorted_users = sort {
2423: lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
1.1 raeburn 2424: ||
1.2 raeburn 2425: lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
2426: lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
2427: } (keys(%$userlist));
1.4 raeburn 2428: my $rowcount = 0;
1.2 raeburn 2429: foreach my $user (@sorted_users) {
1.4 raeburn 2430: my %in;
1.2 raeburn 2431: my $sdata = $userlist->{$user};
1.4 raeburn 2432: $rowcount ++;
1.2 raeburn 2433: foreach my $item (@{$keylist}) {
2434: $in{$item} = $sdata->[$index{$item}];
2435: }
1.11 raeburn 2436: my $role = $in{'role'};
1.2 raeburn 2437: $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
2438: if (! defined($in{'start'}) || $in{'start'} == 0) {
2439: $in{'start'} = &mt('none');
2440: } else {
2441: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
1.1 raeburn 2442: }
1.2 raeburn 2443: if (! defined($in{'end'}) || $in{'end'} == 0) {
2444: $in{'end'} = &mt('none');
1.1 raeburn 2445: } else {
1.2 raeburn 2446: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
1.1 raeburn 2447: }
1.2 raeburn 2448: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2449: $r->print(&Apache::loncommon::start_data_table_row());
1.11 raeburn 2450: my $checkval;
1.16 raeburn 2451: if ($mode eq 'autoenroll') {
2452: my $cellentry;
2453: if ($in{'type'} eq 'auto') {
2454: $cellentry = '<b>'.&mt('auto').'</b> <label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" /> Change</label>';
2455: $autocount ++;
2456: } else {
2457: $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>';
2458: $manualcount ++;
2459: if ($in{'lockedtype'}) {
2460: $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Unlock').'</label>';
2461: $unlockcount ++;
2462: } else {
2463: $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" /> '.&mt('Lock').'</label>';
2464: $lockcount ++;
1.11 raeburn 2465: }
1.16 raeburn 2466: $cellentry .= '</nobr></td></tr></table>';
2467: }
2468: $r->print("<td>$cellentry</td>\n");
2469: } else {
2470: $r->print("<td>$rowcount</td>\n");
2471: if ($actionselect) {
1.26 raeburn 2472: my $showcheckbox;
2473: if ($role =~ /^cr\//) {
2474: $showcheckbox = $canchange{'cr'};
2475: } else {
2476: $showcheckbox = $canchange{$role};
2477: }
2478: if (!$showcheckbox) {
2479: if ($context eq 'course') {
2480: if ($canchangesec{$role} ne '') {
2481: if ($canchangesec{$role} eq $in{'section'}) {
2482: $showcheckbox = 1;
2483: }
2484: }
1.16 raeburn 2485: }
1.26 raeburn 2486: }
2487: if ($showcheckbox) {
2488: $checkval = $user;
2489: if ($context eq 'course') {
2490: if ($role eq 'st') {
2491: $checkval .= ':st';
2492: }
2493: $checkval .= ':'.$in{'section'};
2494: if ($role eq 'st') {
2495: $checkval .= ':'.$in{'type'}.':'.
2496: $in{'lockedtype'};
2497: }
1.16 raeburn 2498: }
1.26 raeburn 2499: $r->print('<td><input type="checkbox" name="'.
2500: 'actionlist" value="'.$checkval.'"></td>');
2501: } else {
2502: $r->print('<td> </td>');
1.16 raeburn 2503: }
1.11 raeburn 2504: }
2505: }
1.2 raeburn 2506: foreach my $item (@cols) {
1.10 raeburn 2507: if ($item eq 'username') {
1.48 raeburn 2508: $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
1.16 raeburn 2509: } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
1.11 raeburn 2510: $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.$checkval.'_'.$item.'" value="'.$sdata->[$index{$item}].'" /></td>'."\n");
1.10 raeburn 2511: } else {
2512: $r->print('<td>'.$in{$item}.'</td>'."\n");
2513: }
1.2 raeburn 2514: }
1.16 raeburn 2515: if (($context eq 'course') && ($mode ne 'autoenroll')) {
1.4 raeburn 2516: if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
2517: if ($displayclickers eq 'on') {
2518: my $clickers =
1.2 raeburn 2519: (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
1.4 raeburn 2520: if ($clickers!~/\w/) { $clickers='-'; }
2521: $r->print('<td>'.$clickers.'</td>');
1.2 raeburn 2522: } else {
2523: $r->print(' <td> </td> ');
2524: }
1.4 raeburn 2525: if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
1.44 raeburn 2526: if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
1.47 raeburn 2527: $r->print(' <td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1"></a></td>');
1.4 raeburn 2528: } else {
2529: $r->print(' <td> </td> ');
2530: }
2531: }
1.2 raeburn 2532: }
2533: }
2534: $r->print(&Apache::loncommon::end_data_table_row());
2535: } elsif ($mode eq 'csv') {
2536: next if (! defined($CSVfile));
2537: # no need to bother with $linkto
2538: if (! defined($in{'start'}) || $in{'start'} == 0) {
2539: $in{'start'} = &mt('none');
2540: } else {
2541: $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
2542: }
2543: if (! defined($in{'end'}) || $in{'end'} == 0) {
2544: $in{'end'} = &mt('none');
2545: } else {
2546: $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
2547: }
2548: my @line = ();
2549: foreach my $item (@cols) {
2550: push @line,&Apache::loncommon::csv_translate($in{$item});
2551: }
2552: print $CSVfile '"'.join('","',@line).'"'."\n";
2553: } elsif ($mode eq 'excel') {
2554: my $col = 0;
2555: foreach my $item (@cols) {
2556: if ($item eq 'start' || $item eq 'end') {
2557: if (defined($item) && $item != 0) {
2558: $excel_sheet->write($row,$col++,
2559: &Apache::lonstathelpers::calc_serial($in{item}),
2560: $format->{'date'});
2561: } else {
2562: $excel_sheet->write($row,$col++,'none');
2563: }
2564: } else {
2565: $excel_sheet->write($row,$col++,$in{$item});
2566: }
2567: }
2568: $row++;
1.1 raeburn 2569: }
2570: }
1.2 raeburn 2571: if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
2572: $r->print(&Apache::loncommon::end_data_table().'<br />');
2573: } elsif ($mode eq 'excel') {
2574: $excel_workbook->close();
2575: $r->print('<p><a href="'.$excel_filename.'">'.
2576: &mt('Your Excel spreadsheet').'</a> '.&mt('is ready for download').'.</p>'."\n");
2577: } elsif ($mode eq 'csv') {
2578: close($CSVfile);
2579: $r->print('<a href="'.$CSVfilename.'">'.
2580: &mt('Your CSV file').'</a> is ready for download.'.
2581: "\n");
2582: $r->rflush();
2583: }
2584: if ($mode eq 'autoenroll') {
2585: return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
1.4 raeburn 2586: } else {
2587: return ($usercount);
1.2 raeburn 2588: }
1.1 raeburn 2589: }
2590:
1.10 raeburn 2591: sub print_username_link {
1.48 raeburn 2592: my ($mode,$in) = @_;
1.10 raeburn 2593: my $output;
1.16 raeburn 2594: if ($mode eq 'autoenroll') {
2595: $output = $in->{'username'};
1.10 raeburn 2596: } else {
2597: $output = '<a href="javascript:username_display_launch('.
2598: "'$in->{'username'}','$in->{'domain'}'".')" />'.
2599: $in->{'username'}.'</a>';
2600: }
2601: return $output;
2602: }
2603:
1.2 raeburn 2604: sub role_type_names {
2605: my %lt = &Apache::lonlocal::texthash (
1.13 raeburn 2606: 'domain' => 'Domain Roles',
2607: 'author' => 'Co-Author Roles',
2608: 'course' => 'Course Roles',
1.2 raeburn 2609: );
2610: return %lt;
2611: }
2612:
1.11 raeburn 2613: sub select_actions {
2614: my ($context,$setting,$statusmode) = @_;
2615: my %lt = &Apache::lonlocal::texthash(
2616: revoke => "Revoke user roles",
2617: delete => "Delete user roles",
2618: reenable => "Re-enable expired user roles",
2619: activate => "Make future user roles active now",
2620: chgdates => "Change starting/ending dates",
2621: chgsec => "Change section associated with user roles",
2622: );
2623: my ($output,$options,%choices);
1.23 raeburn 2624: # FIXME Disable actions for now for roletype=course in domain context
2625: if ($context eq 'domain' && $setting eq 'course') {
2626: return;
2627: }
1.26 raeburn 2628: if ($context eq 'course') {
2629: if ($env{'form.showrole'} ne 'Any') {
2630: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
2631: $env{'request.course.id'})) {
2632: if ($env{'request.course.sec'} eq '') {
2633: return;
2634: } else {
2635: if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
2636: return;
2637: }
2638: }
2639: }
2640: }
2641: }
1.11 raeburn 2642: if ($statusmode eq 'Any') {
2643: $options .= '
2644: <option value="chgdates">'.$lt{'chgdates'}.'</option>';
2645: $choices{'dates'} = 1;
2646: } else {
2647: if ($statusmode eq 'Future') {
2648: $options .= '
2649: <option value="activate">'.$lt{'activate'}.'</option>';
2650: $choices{'dates'} = 1;
2651: } elsif ($statusmode eq 'Expired') {
2652: $options .= '
2653: <option value="reenable">'.$lt{'reenable'}.'</option>';
2654: $choices{'dates'} = 1;
2655: }
1.13 raeburn 2656: if ($statusmode eq 'Active' || $statusmode eq 'Future') {
2657: $options .= '
2658: <option value="chgdates">'.$lt{'chgdates'}.'</option>
2659: <option value="revoke">'.$lt{'revoke'}.'</option>';
2660: $choices{'dates'} = 1;
2661: }
1.11 raeburn 2662: }
2663: if ($context eq 'domain') {
2664: $options .= '
2665: <option value="delete">'.$lt{'delete'}.'</option>';
2666: }
2667: if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
1.26 raeburn 2668: if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
1.11 raeburn 2669: $options .= '
2670: <option value="chgsec">'.$lt{'chgsec'}.'</option>';
2671: $choices{'sections'} = 1;
2672: }
2673: }
2674: if ($options) {
1.41 raeburn 2675: $output = '<select name="bulkaction" onchange="javascript:opendatebrowser(this.form,'."'studentform','change'".')" />'."\n".
1.11 raeburn 2676: '<option value="" selected="selected">'.
2677: &mt('Please select').'</option>'."\n".$options."\n".'</select>';
2678: if ($choices{'dates'}) {
2679: $output .=
2680: '<input type="hidden" name="startdate_month" value="" />'."\n".
2681: '<input type="hidden" name="startdate_day" value="" />'."\n".
2682: '<input type="hidden" name="startdate_year" value="" />'."\n".
2683: '<input type="hidden" name="startdate_hour" value="" />'."\n".
2684: '<input type="hidden" name="startdate_minute" value="" />'."\n".
2685: '<input type="hidden" name="startdate_second" value="" />'."\n".
2686: '<input type="hidden" name="enddate_month" value="" />'."\n".
2687: '<input type="hidden" name="enddate_day" value="" />'."\n".
2688: '<input type="hidden" name="enddate_year" value="" />'."\n".
2689: '<input type="hidden" name="enddate_hour" value="" />'."\n".
2690: '<input type="hidden" name="enddate_minute" value="" />'."\n".
2691: '<input type="hidden" name="enddate_second" value="" />'."\n";
2692: if ($context eq 'course') {
2693: $output .= '<input type="hidden" name="makedatesdefault" value="" />'."\n";
2694: }
2695: }
2696: if ($choices{'sections'}) {
2697: $output .= '<input type="hidden" name="retainsec" value= "" />'."\n".
2698: '<input type="hidden" name="newsecs" value= "" />'."\n";
2699: }
2700: }
2701: return $output;
2702: }
2703:
2704: sub date_section_javascript {
2705: my ($context,$setting) = @_;
1.49 raeburn 2706: my $title = 'Date_And_Section_Selector';
1.41 raeburn 2707: my %nopopup = &Apache::lonlocal::texthash (
2708: revoke => "Check the boxes for any users for whom roles are to be revoked, and click 'Proceed'",
2709: delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
2710: none => "Choose an action to take for selected users",
2711: );
1.11 raeburn 2712: my $output = '
1.49 raeburn 2713: <script type="text/javascript">'."\n";
1.11 raeburn 2714: $output .= <<"ENDONE";
1.41 raeburn 2715: function opendatebrowser(callingform,formname,calledby) {
1.11 raeburn 2716: var bulkaction = callingform.bulkaction.options[callingform.bulkaction.selectedIndex].value;
2717: if (bulkaction == 'revoke' || bulkaction == 'delete' || bulkaction == '') {
1.41 raeburn 2718: if (calledby == 'go') {
2719: if (bulkaction == 'revoke') {
2720: alert("$nopopup{'revoke'}");
2721: }
2722: if (bulkaction == 'delete') {
2723: alert("$nopopup{'delete'}");
2724: }
2725: if (bulkaction == '') {
2726: alert("$nopopup{'none'}");
2727: }
2728: }
1.11 raeburn 2729: return;
2730: }
2731: var url = '/adm/createuser?';
2732: var type = '';
2733: var showrole = callingform.showrole.options[callingform.showrole.selectedIndex].value;
2734: ENDONE
2735: if ($context eq 'domain') {
2736: $output .= '
2737: type = callingform.roletype.options[callingform.roletype.selectedIndex].value;
2738: ';
2739: }
2740: my $width= '700';
2741: my $height = '400';
2742: $output .= <<"ENDTWO";
2743: url += 'action=dateselect&callingform=' + formname +
2744: '&roletype='+type+'&showrole='+showrole +'&bulkaction='+bulkaction;
2745: var title = '$title';
2746: var options = 'scrollbars=1,resizable=1,menubar=0';
2747: options += ',width=$width,height=$height';
2748: stdeditbrowser = open(url,title,options,'1');
2749: stdeditbrowser.focus();
2750: }
2751: </script>
2752: ENDTWO
2753: return $output;
2754: }
2755:
2756: sub date_section_selector {
1.21 raeburn 2757: my ($context,$permission) = @_;
1.11 raeburn 2758: my $callingform = $env{'form.callingform'};
2759: my $formname = 'dateselect';
2760: my $groupslist = &get_groupslist();
2761: my $sec_js = &setsections_javascript($formname,$groupslist);
2762: my $output = <<"END";
2763: <script type="text/javascript">
2764:
2765: $sec_js
2766:
2767: function saveselections(formname) {
2768:
2769: END
2770: if ($env{'form.bulkaction'} eq 'chgsec') {
2771: $output .= <<"END";
1.40 raeburn 2772: if (formname.retainsec.length > 1) {
2773: for (var i=0; i<formname.retainsec.length; i++) {
2774: if (formname.retainsec[i].checked == true) {
2775: opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
2776: }
2777: }
2778: } else {
2779: opener.document.$callingform.retainsec.value = formname.retainsec.value;
2780: }
1.11 raeburn 2781: setSections(formname);
2782: if (seccheck == 'ok') {
2783: opener.document.$callingform.newsecs.value = formname.sections.value;
2784: window.close();
2785: }
2786: return;
2787: END
2788: } else {
2789: if ($context eq 'course') {
2790: if (($env{'form.bulkaction'} eq 'reenable') ||
2791: ($env{'form.bulkaction'} eq 'activate') ||
2792: ($env{'form.bulkaction'} eq 'chgdates')) {
1.26 raeburn 2793: if ($env{'request.course.sec'} eq '') {
2794: $output .= <<"END";
1.11 raeburn 2795:
2796: if (formname.makedatesdefault.checked == true) {
2797: opener.document.$callingform.makedatesdefault.value = 1;
2798: }
2799: else {
2800: opener.document.$callingform.makedatesdefault.value = 0;
2801: }
2802:
2803: END
1.26 raeburn 2804: }
1.11 raeburn 2805: }
2806: }
2807: $output .= <<"END";
2808: opener.document.$callingform.startdate_month.value = formname.startdate_month.options[formname.startdate_month.selectedIndex].value;
2809: opener.document.$callingform.startdate_day.value = formname.startdate_day.value;
2810: opener.document.$callingform.startdate_year.value = formname.startdate_year.value;
2811: opener.document.$callingform.startdate_hour.value = formname.startdate_hour.options[formname.startdate_hour.selectedIndex].value;
2812: opener.document.$callingform.startdate_minute.value = formname.startdate_minute.value;
2813: opener.document.$callingform.startdate_second.value = formname.startdate_second.value;
2814: opener.document.$callingform.enddate_month.value = formname.enddate_month.options[formname.enddate_month.selectedIndex].value;
2815: opener.document.$callingform.enddate_day.value = formname.enddate_day.value;
2816: opener.document.$callingform.enddate_year.value = formname.enddate_year.value;
2817: opener.document.$callingform.enddate_hour.value = formname.enddate_hour.options[formname.enddate_hour.selectedIndex].value;
2818: opener.document.$callingform.enddate_minute.value = formname.enddate_minute.value;
2819: opener.document.$callingform.enddate_second.value = formname.enddate_second.value;
2820: window.close();
2821: END
2822: }
2823: $output .= '
2824: }
2825: </script>
2826: ';
2827: my %lt = &Apache::lonlocal::texthash (
2828: chac => 'Access dates to apply for selected users',
2829: chse => 'Changes in section affiliation to apply to selected users',
2830: 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.',
2831: 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.',
2832: reta => "Retain each user's current section affiliations?",
2833: dnap => '(Does not apply to student roles).',
2834: );
2835: my ($date_items,$headertext);
2836: if ($env{'form.bulkaction'} eq 'chgsec') {
2837: $headertext = $lt{'chse'};
2838: } else {
2839: $headertext = $lt{'chac'};
2840: my $starttime;
2841: if (($env{'form.bulkaction'} eq 'activate') ||
2842: ($env{'form.bulkaction'} eq 'reenable')) {
2843: $starttime = time;
2844: }
2845: $date_items = &date_setting_table($starttime,undef,$context,
1.21 raeburn 2846: $env{'form.bulkaction'},$formname,
2847: $permission);
1.11 raeburn 2848: }
2849: $output .= '<h3>'.$headertext.'</h3>'.
2850: '<form name="'.$formname.'" method="post">'."\n".
2851: $date_items;
2852: if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
1.17 raeburn 2853: my ($cnum,$cdom) = &get_course_identity();
1.11 raeburn 2854: my $info;
2855: if ($env{'form.showrole'} eq 'st') {
2856: $output .= '<p>'.$lt{'fors'}.'</p>';
1.26 raeburn 2857: } elsif ($env{'form.showrole'} eq 'Any') {
1.11 raeburn 2858: $output .= '<p>'.$lt{'fors'}.'</p>'.
2859: '<p>'.$lt{'forn'}.' ';
2860: $info = $lt{'reta'};
2861: } else {
2862: $output .= '<p>'.$lt{'forn'}.' ';
2863: $info = $lt{'reta'};
2864: }
2865: if ($info) {
2866: $info .= '<span class="LC_nobreak">'.
2867: '<label><input type="radio" name="retainsec" value="1" '.
2868: 'checked="checked" />'.&mt('Yes').'</label> '.
2869: '<label><input type="radio" name="retainsec" value="0" />'.
2870: &mt('No').'</label></span>';
2871: if ($env{'form.showrole'} eq 'Any') {
2872: $info .= '<br />'.$lt{'dnap'};
2873: }
2874: $info .= '</p>';
2875: } else {
2876: $info = '<input type="hidden" name="retainsec" value="0" />';
2877: }
1.21 raeburn 2878: my $rowtitle = &mt('New section to assign');
2879: my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
1.11 raeburn 2880: $output .= $info.$secbox;
2881: }
2882: $output .= '<p>'.
2883: &mt('Use "Save" to update the main window with your selections.').'<br /><br />'.
2884: '<input type="button" name="dateselection" value="'.&mt('Save').'" onclick="javascript:saveselections(this.form)" /></p>'."\n".
2885: '</form>';
2886: return $output;
2887: }
2888:
1.17 raeburn 2889: sub section_picker {
2890: my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
2891: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
2892: my $sections_select .= &course_sections(\%sections_count,$role);
2893: my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
2894: if ($mode eq 'upload') {
2895: my ($options,$cb_script,$coursepick) =
2896: &default_role_selector($context,1);
2897: $secbox .= &Apache::lonhtmlcommon::row_title('role','LC_oddrow_value').
2898: $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
2899: }
2900: $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
2901: if ($env{'request.course.sec'} eq '') {
2902: $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
2903: '<td align="center">'.&mt('Existing sections')."\n".
2904: '<br />'.$sections_select.'</td><td align="center">'.
2905: &mt('New section').'<br />'."\n".
2906: '<input type="text" name="newsec" size="15" />'."\n".
2907: '<input type="hidden" name="sections" value="" />'."\n".
2908: '</td></tr></table>'."\n";
2909: } else {
2910: $secbox .= '<input type="hidden" name="sections" value="'.
2911: $env{'request.course.sec'}.'" />'.
2912: $env{'request.course.sec'};
2913: }
2914: $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
2915: &Apache::lonhtmlcommon::end_pick_box().'</p>';
2916: return $secbox;
2917: }
2918:
1.2 raeburn 2919: sub results_header_row {
1.24 raeburn 2920: my ($rolefilter,$statusmode,$context,$permission,$mode) = @_;
1.5 raeburn 2921: my ($description,$showfilter);
2922: if ($rolefilter ne 'Any') {
2923: $showfilter = $rolefilter;
2924: }
1.2 raeburn 2925: if ($context eq 'course') {
1.24 raeburn 2926: if ($mode eq 'csv' || $mode eq 'excel') {
2927: $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
2928: }
1.2 raeburn 2929: if ($statusmode eq 'Expired') {
1.5 raeburn 2930: $description .= &mt('Users in course with expired [_1] roles',$showfilter);
1.11 raeburn 2931: } elsif ($statusmode eq 'Future') {
1.5 raeburn 2932: $description .= &mt('Users in course with future [_1] roles',$showfilter);
1.2 raeburn 2933: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2934: $description .= &mt('Users in course with active [_1] roles',$showfilter);
1.2 raeburn 2935: } else {
2936: if ($rolefilter eq 'Any') {
2937: $description .= &mt('All users in course');
2938: } else {
2939: $description .= &mt('All users in course with [_1] roles',$rolefilter);
2940: }
2941: }
1.33 raeburn 2942: my $constraint;
1.26 raeburn 2943: my $viewablesec = &viewable_section($permission);
2944: if ($viewablesec ne '') {
1.15 raeburn 2945: if ($env{'form.showrole'} eq 'st') {
1.33 raeburn 2946: $constraint = &mt('only users in section "[_1]"',$viewablesec);
1.26 raeburn 2947: } elsif ($env{'form.showrole'} ne 'cc') {
1.33 raeburn 2948: $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
2949: }
2950: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
2951: if ($env{'form.grpfilter'} eq 'none') {
2952: $constraint .= &mt(' and not in any group');
2953: } else {
2954: $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
2955: }
2956: }
2957: } else {
2958: if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
2959: if ($env{'form.secfilter'} eq 'none') {
2960: $constraint = &mt('only users affiliated with no section');
2961: } else {
2962: $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
2963: }
2964: }
2965: if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
2966: if ($env{'form.grpfilter'} eq 'none') {
2967: if ($constraint eq '') {
2968: $constraint = &mt('only users not in any group');
2969: } else {
2970: $constraint .= &mt(' and also not in any group');
2971: }
2972: } else {
2973: if ($constraint eq '') {
2974: $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
2975: } else {
2976: $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
2977: }
2978: }
1.15 raeburn 2979: }
2980: }
1.33 raeburn 2981: if ($constraint ne '') {
2982: $description .= ' ('.$constraint.')';
2983: }
1.13 raeburn 2984: } elsif ($context eq 'author') {
1.14 raeburn 2985: $description =
2986: &mt('Author space for <span class="LC_cusr_emph">[_1]</span>',
2987: &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})).': ';
1.2 raeburn 2988: if ($statusmode eq 'Expired') {
1.5 raeburn 2989: $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
1.2 raeburn 2990: } elsif ($statusmode eq 'Future') {
1.5 raeburn 2991: $description .= &mt('Co-authors with future [_1] roles',$showfilter);
1.2 raeburn 2992: } elsif ($statusmode eq 'Active') {
1.5 raeburn 2993: $description .= &mt('Co-authors with active [_1] roles',$showfilter);
1.2 raeburn 2994: } else {
2995: if ($rolefilter eq 'Any') {
1.5 raeburn 2996: $description .= &mt('All co-authors');
1.2 raeburn 2997: } else {
2998: $description .= &mt('All co-authors with [_1] roles',$rolefilter);
2999: }
3000: }
3001: } elsif ($context eq 'domain') {
3002: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
3003: $description = &mt('Domain - ').$domdesc.': ';
3004: if ($env{'form.roletype'} eq 'domain') {
3005: if ($statusmode eq 'Expired') {
1.5 raeburn 3006: $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3007: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3008: $description .= &mt('Users in domain with future [_1] roles',$showfilter);
1.2 raeburn 3009: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3010: $description .= &mt('Users in domain with active [_1] roles',$showfilter);
1.2 raeburn 3011: } else {
3012: if ($rolefilter eq 'Any') {
1.5 raeburn 3013: $description .= &mt('All users in domain');
1.2 raeburn 3014: } else {
3015: $description .= &mt('All users in domain with [_1] roles',$rolefilter);
3016: }
3017: }
1.13 raeburn 3018: } elsif ($env{'form.roletype'} eq 'author') {
1.2 raeburn 3019: if ($statusmode eq 'Expired') {
1.5 raeburn 3020: $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
1.2 raeburn 3021: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3022: $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
1.2 raeburn 3023: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3024: $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
1.2 raeburn 3025: } else {
3026: if ($rolefilter eq 'Any') {
1.5 raeburn 3027: $description .= &mt('All users with co-author roles in domain',$showfilter);
1.2 raeburn 3028: } else {
3029: $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
3030: }
3031: }
3032: } elsif ($env{'form.roletype'} eq 'course') {
3033: my $coursefilter = $env{'form.coursepick'};
3034: if ($coursefilter eq 'category') {
3035: my $instcode = &instcode_from_coursefilter();
3036: if ($instcode eq '.') {
3037: $description .= &mt('All courses in domain').' - ';
3038: } else {
3039: $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
3040: }
3041: } elsif ($coursefilter eq 'selected') {
3042: $description .= &mt('Selected courses in domain').' - ';
3043: } elsif ($coursefilter eq 'all') {
3044: $description .= &mt('All courses in domain').' - ';
3045: }
3046: if ($statusmode eq 'Expired') {
1.5 raeburn 3047: $description .= &mt('users with expired [_1] roles',$showfilter);
1.2 raeburn 3048: } elsif ($statusmode eq 'Future') {
1.5 raeburn 3049: $description .= &mt('users with future [_1] roles',$showfilter);
1.2 raeburn 3050: } elsif ($statusmode eq 'Active') {
1.5 raeburn 3051: $description .= &mt('users with active [_1] roles',$showfilter);
1.2 raeburn 3052: } else {
3053: if ($rolefilter eq 'Any') {
3054: $description .= &mt('all users');
3055: } else {
3056: $description .= &mt('users with [_1] roles',$rolefilter);
3057: }
3058: }
3059: }
3060: }
3061: return $description;
3062: }
1.22 raeburn 3063:
3064: sub viewable_section {
3065: my ($permission) = @_;
3066: my $viewablesec;
3067: if (ref($permission) eq 'HASH') {
3068: if (exists($permission->{'view_section'})) {
3069: $viewablesec = $permission->{'view_section'};
3070: } elsif (exists($permission->{'cusr_section'})) {
3071: $viewablesec = $permission->{'cusr_section'};
3072: }
3073: }
3074: return $viewablesec;
3075: }
3076:
1.2 raeburn 3077:
1.1 raeburn 3078: #################################################
3079: #################################################
3080: sub show_drop_list {
1.30 raeburn 3081: my ($r,$classlist,$nosort,$permission) = @_;
1.29 raeburn 3082: my $cid = $env{'request.course.id'};
1.17 raeburn 3083: my ($cnum,$cdom) = &get_course_identity($cid);
1.1 raeburn 3084: if (! exists($env{'form.sortby'})) {
3085: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3086: ['sortby']);
3087: }
3088: my $sortby = $env{'form.sortby'};
3089: if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
3090: $sortby = 'username';
3091: }
3092: my $action = "drop";
1.17 raeburn 3093: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
1.1 raeburn 3094: $r->print(<<END);
3095: <input type="hidden" name="sortby" value="$sortby" />
3096: <input type="hidden" name="action" value="$action" />
3097: <input type="hidden" name="state" value="done" />
1.17 raeburn 3098: <script type="text/javascript" language="Javascript">
3099: $check_uncheck_js
1.1 raeburn 3100: </script>
3101: <p>
3102: <input type="hidden" name="phase" value="four">
3103: END
1.30 raeburn 3104: my ($indexhash,$keylist) = &make_keylist_array();
3105: my $studentcount = 0;
3106: if (ref($classlist) eq 'HASH') {
3107: foreach my $student (keys(%{$classlist})) {
3108: my $sdata = $classlist->{$student};
3109: my $status = $sdata->[$indexhash->{'status'}];
3110: my $section = $sdata->[$indexhash->{'section'}];
3111: if ($status ne 'Active') {
3112: delete($classlist->{$student});
3113: next;
3114: }
3115: if ($env{'request.course.sec'} ne '') {
3116: if ($section ne $env{'request.course.sec'}) {
3117: delete($classlist->{$student});
3118: next;
3119: }
3120: }
3121: $studentcount ++;
3122: }
3123: }
3124: if (!$studentcount) {
3125: $r->print(&mt('There are no students to drop.'));
3126: return;
3127: }
3128: my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
3129: $classlist,$keylist,$cdom,$cnum);
3130: my %lt=&Apache::lonlocal::texthash('usrn' => "username",
3131: 'dom' => "domain",
3132: 'sn' => "student name",
3133: 'sec' => "section",
3134: 'start' => "start date",
3135: 'end' => "end date",
3136: 'groups' => "active groups",
3137: );
1.1 raeburn 3138: if ($nosort) {
1.17 raeburn 3139: $r->print(&Apache::loncommon::start_data_table().
3140: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 3141: $r->print(<<END);
3142: <th> </th>
3143: <th>$lt{'usrn'}</th>
3144: <th>$lt{'dom'}</th>
3145: <th>ID</th>
3146: <th>$lt{'sn'}</th>
3147: <th>$lt{'sec'}</th>
3148: <th>$lt{'start'}</th>
3149: <th>$lt{'end'}</th>
3150: <th>$lt{'groups'}</th>
3151: END
1.17 raeburn 3152: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 3153: } else {
1.17 raeburn 3154: $r->print(&Apache::loncommon::start_data_table().
3155: &Apache::loncommon::start_data_table_header_row());
1.1 raeburn 3156: $r->print(<<END);
1.17 raeburn 3157: <th> </th>
1.1 raeburn 3158: <th>
1.17 raeburn 3159: <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
1.1 raeburn 3160: </th><th>
1.17 raeburn 3161: <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
1.1 raeburn 3162: </th><th>
1.17 raeburn 3163: <a href="/adm/createuser?action=$action&sortby=id">ID</a>
1.1 raeburn 3164: </th><th>
1.17 raeburn 3165: <a href="/adm/createuser?action=$action&sortby=fullname">$lt{'sn'}</a>
1.1 raeburn 3166: </th><th>
1.17 raeburn 3167: <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
1.1 raeburn 3168: </th><th>
1.17 raeburn 3169: <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
1.1 raeburn 3170: </th><th>
1.17 raeburn 3171: <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
1.1 raeburn 3172: </th><th>
1.17 raeburn 3173: <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
1.1 raeburn 3174: </th>
3175: END
1.17 raeburn 3176: $r->print(&Apache::loncommon::end_data_table_header_row());
1.1 raeburn 3177: }
3178: #
3179: # Sort the students
1.30 raeburn 3180: my $index = $indexhash->{$sortby};
3181: my $second = $indexhash->{'username'};
3182: my $third = $indexhash->{'domain'};
1.1 raeburn 3183: my @Sorted_Students = sort {
3184: lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
3185: ||
3186: lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
3187: ||
3188: lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
1.30 raeburn 3189: } (keys(%{$classlist}));
1.1 raeburn 3190: foreach my $student (@Sorted_Students) {
3191: my $error;
3192: my $sdata = $classlist->{$student};
1.30 raeburn 3193: my $username = $sdata->[$indexhash->{'username'}];
3194: my $domain = $sdata->[$indexhash->{'domain'}];
3195: my $section = $sdata->[$indexhash->{'section'}];
3196: my $name = $sdata->[$indexhash->{'fullname'}];
3197: my $id = $sdata->[$indexhash->{'id'}];
3198: my $start = $sdata->[$indexhash->{'start'}];
3199: my $end = $sdata->[$indexhash->{'end'}];
1.1 raeburn 3200: my $groups = $classgroups->{$student};
3201: my $active_groups;
3202: if (ref($groups->{active}) eq 'HASH') {
3203: $active_groups = join(', ',keys(%{$groups->{'active'}}));
3204: }
3205: if (! defined($start) || $start == 0) {
3206: $start = &mt('none');
3207: } else {
3208: $start = &Apache::lonlocal::locallocaltime($start);
3209: }
3210: if (! defined($end) || $end == 0) {
3211: $end = &mt('none');
3212: } else {
3213: $end = &Apache::lonlocal::locallocaltime($end);
3214: }
1.17 raeburn 3215: my $studentkey = $student.':'.$section;
1.30 raeburn 3216: my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
1.1 raeburn 3217: #
3218: $r->print(&Apache::loncommon::start_data_table_row());
3219: $r->print(<<"END");
1.29 raeburn 3220: <td><input type="checkbox" name="droplist" value="$studentkey"></td>
1.1 raeburn 3221: <td>$username</td>
3222: <td>$domain</td>
3223: <td>$id</td>
3224: <td>$name</td>
3225: <td>$section</td>
1.29 raeburn 3226: <td>$start $startitem</td>
1.1 raeburn 3227: <td>$end</td>
3228: <td>$active_groups</td>
3229: END
3230: $r->print(&Apache::loncommon::end_data_table_row());
3231: }
3232: $r->print(&Apache::loncommon::end_data_table().'<br />');
3233: %lt=&Apache::lonlocal::texthash(
1.29 raeburn 3234: 'dp' => "Drop Students",
1.1 raeburn 3235: 'ca' => "check all",
3236: 'ua' => "uncheck all",
3237: );
3238: $r->print(<<"END");
3239: </p><p>
3240: <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)">
3241: <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)">
3242: <p><input type=submit value="$lt{'dp'}"></p>
3243: END
3244: return;
3245: }
3246:
3247: #
3248: # Print out the initial form to get the file containing a list of users
3249: #
3250: sub print_first_users_upload_form {
3251: my ($r,$context) = @_;
3252: my $str;
3253: $str = '<input type="hidden" name="phase" value="two">';
3254: $str .= '<input type="hidden" name="action" value="upload" />';
3255: $str .= '<input type="hidden" name="state" value="got_file" />';
1.2 raeburn 3256: $str .= "<h3>".&mt('Upload a file containing information about users')."</h3>\n";
1.1 raeburn 3257: $str .= &Apache::loncommon::upfile_select_html();
3258: $str .= "<p>\n";
3259: $str .= '<input type="submit" name="fileupload" value="'.
1.2 raeburn 3260: &mt('Upload file of users').'">'."\n";
1.1 raeburn 3261: $str .= '<label><input type="checkbox" name="noFirstLine" /> '.
3262: &mt('Ignore First Line')."</label></p>\n";
3263: $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
3264: &mt("How do I create a users list from a spreadsheet")).
3265: "<br />\n";
3266: $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3267: &mt("How do I create a CSV file from a spreadsheet")).
3268: "<br />\n";
3269: $str .= &Apache::loncommon::end_page();
3270: $r->print($str);
3271: return;
3272: }
3273:
3274: # ================================================= Drop/Add from uploaded file
3275: sub upfile_drop_add {
1.21 raeburn 3276: my ($r,$context,$permission) = @_;
1.1 raeburn 3277: &Apache::loncommon::load_tmp_file($r);
3278: my @userdata=&Apache::loncommon::upfile_record_sep();
3279: if($env{'form.noFirstLine'}){shift(@userdata);}
3280: my @keyfields = split(/\,/,$env{'form.keyfields'});
3281: my %fields=();
3282: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3283: if ($env{'form.upfile_associate'} eq 'reverse') {
3284: if ($env{'form.f'.$i} ne 'none') {
3285: $fields{$keyfields[$i]}=$env{'form.f'.$i};
3286: }
3287: } else {
3288: $fields{$env{'form.f'.$i}}=$keyfields[$i];
3289: }
3290: }
1.29 raeburn 3291: if ($env{'form.fullup'} ne 'yes') {
3292: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
3293: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
3294: }
1.1 raeburn 3295: #
3296: # Store the field choices away
3297: foreach my $field (qw/username names
3298: fname mname lname gen id sec ipwd email role/) {
3299: $env{'form.'.$field.'_choice'}=$fields{$field};
3300: }
3301: &Apache::loncommon::store_course_settings('enrollment_upload',
3302: { 'username_choice' => 'scalar',
3303: 'names_choice' => 'scalar',
3304: 'fname_choice' => 'scalar',
3305: 'mname_choice' => 'scalar',
3306: 'lname_choice' => 'scalar',
3307: 'gen_choice' => 'scalar',
3308: 'id_choice' => 'scalar',
3309: 'sec_choice' => 'scalar',
3310: 'ipwd_choice' => 'scalar',
3311: 'email_choice' => 'scalar',
3312: 'role_choice' => 'scalar' });
3313: #
3314: my ($startdate,$enddate) = &get_dates_from_form();
3315: if ($env{'form.makedatesdefault'}) {
1.27 raeburn 3316: $r->print(&make_dates_default($startdate,$enddate,$context));
1.1 raeburn 3317: }
3318: # Determine domain and desired host (home server)
3319: my $domain=$env{'request.role.domain'};
3320: my $desiredhost = $env{'form.lcserver'};
3321: if (lc($desiredhost) eq 'default') {
3322: $desiredhost = undef;
3323: } else {
3324: my %home_servers = &Apache::lonnet::get_servers($domain,'library');
3325: if (! exists($home_servers{$desiredhost})) {
3326: $r->print('<span class="LC_error">'.&mt('Error').
3327: &mt('Invalid home server specified').'</span>');
3328: $r->print(&Apache::loncommon::end_page());
3329: return;
3330: }
3331: }
3332: # Determine authentication mechanism
3333: my $changeauth;
3334: if ($context eq 'domain') {
3335: $changeauth = $env{'form.changeauth'};
3336: }
3337: my $amode = '';
3338: my $genpwd = '';
3339: if ($env{'form.login'} eq 'krb') {
3340: $amode='krb';
3341: $amode.=$env{'form.krbver'};
3342: $genpwd=$env{'form.krbarg'};
3343: } elsif ($env{'form.login'} eq 'int') {
3344: $amode='internal';
3345: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
3346: $genpwd=$env{'form.intarg'};
3347: }
3348: } elsif ($env{'form.login'} eq 'loc') {
3349: $amode='localauth';
3350: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
3351: $genpwd=$env{'form.locarg'};
3352: }
3353: }
3354: if ($amode =~ /^krb/) {
3355: if (! defined($genpwd) || $genpwd eq '') {
3356: $r->print('<span class="Error">'.
3357: &mt('Unable to enroll users').' '.
3358: &mt('No Kerberos domain was specified.').'</span></p>');
3359: $amode = ''; # This causes the loop below to be skipped
3360: }
3361: }
3362: my ($cid,$defaultsec,$defaultrole,$setting);
3363: if ($context eq 'domain') {
3364: $setting = $env{'form.roleaction'};
3365: if ($setting eq 'domain') {
3366: $defaultrole = $env{'form.defaultrole'};
3367: } elsif ($setting eq 'course') {
3368: $defaultrole = $env{'form.courserole'};
1.27 raeburn 3369: $defaultsec = $env{'form.sections'};
1.1 raeburn 3370: }
1.13 raeburn 3371: } elsif ($context eq 'author') {
1.1 raeburn 3372: $defaultrole = $env{'form.defaultrole'};
1.27 raeburn 3373: } elsif ($context eq 'course') {
3374: $defaultrole = $env{'form.defaultrole'};
3375: $defaultsec = $env{'form.sections'};
1.1 raeburn 3376: }
1.27 raeburn 3377: if ($env{'request.course.id'} ne '') {
3378: $cid = $env{'request.course.id'};
3379: } elsif ($setting eq 'course') {
3380: if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
3381: $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
1.1 raeburn 3382: }
3383: }
1.27 raeburn 3384: # Check to see if user information can be changed
3385: my @userinfo = ('firstname','middlename','lastname','generation',
3386: 'permanentemail','id');
3387: my %canmodify;
3388: if (&Apache::lonnet::allowed('mau',$domain)) {
3389: foreach my $field (@userinfo) {
3390: $canmodify{$field} = 1;
3391: }
3392: }
3393: my (%userlist,%modifiable_fields,@poss_roles);
3394: my $secidx = &Apache::loncoursedata::CL_SECTION();
3395: my @courseroles = &roles_by_context('course',1);
3396: if (!&Apache::lonnet::allowed('mau',$domain)) {
3397: if ($context eq 'course' || $context eq 'author') {
3398: @poss_roles = &curr_role_permissions($context);
3399: my @statuses = ('active','future');
3400: my ($indexhash,$keylist) = &make_keylist_array();
3401: my %info;
3402: foreach my $role (@poss_roles) {
3403: %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain,
3404: \@userinfo,[$role]);
3405: }
3406: if ($context eq 'course') {
3407: my ($cnum,$cdom) = &get_course_identity();
3408: my $roster = &Apache::loncoursedata::get_classlist();
3409: %userlist = %{$roster};
3410: my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
3411: \@statuses,\@poss_roles);
3412: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3413: \%advrolehash,$permission);
3414: } elsif ($context eq 'author') {
3415: my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
3416: \@statuses,\@poss_roles);
3417: &gather_userinfo($context,'view',\%userlist,$indexhash,\%info,
3418: \%cstr_roles,$permission);
3419:
3420: }
3421: }
1.1 raeburn 3422: }
3423: if ( $domain eq &LONCAPA::clean_domain($domain)
3424: && ($amode ne '')) {
3425: #######################################
3426: ## Add/Modify Users ##
3427: #######################################
3428: if ($context eq 'course') {
3429: $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
1.13 raeburn 3430: } elsif ($context eq 'author') {
1.1 raeburn 3431: $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
3432: } else {
3433: $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
3434: }
3435: my %counts = (
3436: user => 0,
3437: auth => 0,
3438: role => 0,
3439: );
3440: my $flushc=0;
3441: my %student=();
1.42 raeburn 3442: my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
1.1 raeburn 3443: my %userchg;
1.27 raeburn 3444: if ($context eq 'course' || $setting eq 'course') {
3445: if ($context eq 'course') {
3446: # Get information about course groups
3447: %curr_groups = &Apache::longroup::coursegroups();
3448: } elsif ($setting eq 'course') {
3449: if ($cid) {
3450: %curr_groups =
3451: &Apache::longroup::coursegroups($env{'form.dcdomain'},
3452: $env{'form.dccourse'});
3453: }
3454: }
3455: # determine section number
3456: if ($defaultsec =~ /,/) {
3457: push(@sections,split(/,/,$defaultsec));
3458: } else {
3459: push(@sections,$defaultsec);
3460: }
3461: # remove non alphanumeric values from section
3462: foreach my $item (@sections) {
3463: $item =~ s/\W//g;
3464: if ($item eq "none" || $item eq 'all') {
3465: $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
3466: } elsif ($item ne '' && exists($curr_groups{$item})) {
3467: $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
3468: } elsif ($item ne '') {
3469: push(@cleansec,$item);
3470: }
3471: }
3472: if ($defaultwarn) {
3473: $r->print($defaultwarn.'<br />');
3474: }
3475: if ($groupwarn) {
3476: $r->print($groupwarn.'<br />');
3477: }
1.1 raeburn 3478: }
1.5 raeburn 3479: my (%curr_rules,%got_rules,%alerts);
1.27 raeburn 3480: my %customroles = &my_custom_roles();
1.42 raeburn 3481: my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
1.1 raeburn 3482: # Get new users list
1.27 raeburn 3483: foreach my $line (@userdata) {
1.42 raeburn 3484: my @secs;
1.27 raeburn 3485: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 3486: # Determine user name
3487: unless (($entries{$fields{'username'}} eq '') ||
3488: (!defined($entries{$fields{'username'}}))) {
3489: my ($fname, $mname, $lname,$gen) = ('','','','');
3490: if (defined($fields{'names'})) {
3491: ($lname,$fname,$mname)=($entries{$fields{'names'}}=~
3492: /([^\,]+)\,\s*(\w+)\s*(.*)$/);
3493: } else {
3494: if (defined($fields{'fname'})) {
3495: $fname=$entries{$fields{'fname'}};
3496: }
3497: if (defined($fields{'mname'})) {
3498: $mname=$entries{$fields{'mname'}};
3499: }
3500: if (defined($fields{'lname'})) {
3501: $lname=$entries{$fields{'lname'}};
3502: }
3503: if (defined($fields{'gen'})) {
3504: $gen=$entries{$fields{'gen'}};
3505: }
3506: }
3507: if ($entries{$fields{'username'}}
3508: ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
3509: $r->print('<br />'.
3510: &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
3511: $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
3512: '</b>');
1.27 raeburn 3513: next;
1.1 raeburn 3514: } else {
1.5 raeburn 3515: my $username = $entries{$fields{'username'}};
1.27 raeburn 3516: if (defined($fields{'sec'})) {
3517: if (defined($entries{$fields{'sec'}})) {
1.42 raeburn 3518: $entries{$fields{'sec'}} =~ s/\W//g;
1.27 raeburn 3519: my $item = $entries{$fields{'sec'}};
3520: if ($item eq "none" || $item eq 'all') {
3521: $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));
3522: next;
3523: } elsif (exists($curr_groups{$item})) {
3524: $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.'));
3525: next;
3526: } else {
3527: push(@secs,$item);
3528: }
3529: }
3530: }
3531: if ($env{'request.course.sec'} ne '') {
3532: @secs = ($env{'request.course.sec'});
3533: if (ref($userlist{$username.':'.$domain}) eq 'ARRAY') {
3534: my $currsec = $userlist{$username.':'.$domain}[$secidx];
3535: if ($currsec ne $env{'request.course.sec'}) {
3536: $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 />');
3537: if ($currsec eq '') {
3538: $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
3539:
3540: } else {
3541: $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
3542: }
3543: $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 />');
3544: next;
1.1 raeburn 3545: }
3546: }
1.27 raeburn 3547: } elsif ($context eq 'course' || $setting eq 'course') {
3548: if (@secs == 0) {
3549: @secs = @cleansec;
1.1 raeburn 3550: }
3551: }
3552: # determine id number
3553: my $id='';
3554: if (defined($fields{'id'})) {
3555: if (defined($entries{$fields{'id'}})) {
3556: $id=$entries{$fields{'id'}};
3557: }
3558: $id=~tr/A-Z/a-z/;
3559: }
3560: # determine email address
3561: my $email='';
3562: if (defined($fields{'email'})) {
3563: if (defined($entries{$fields{'email'}})) {
3564: $email=$entries{$fields{'email'}};
3565: unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
3566: }
3567: # determine user password
3568: my $password = $genpwd;
3569: if (defined($fields{'ipwd'})) {
3570: if ($entries{$fields{'ipwd'}}) {
3571: $password=$entries{$fields{'ipwd'}};
3572: }
3573: }
3574: # determine user role
3575: my $role = '';
3576: if (defined($fields{'role'})) {
3577: if ($entries{$fields{'role'}}) {
1.42 raeburn 3578: $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
3579: if ($entries{$fields{'role'}} ne '') {
3580: if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
3581: $role = $entries{$fields{'role'}};
1.27 raeburn 3582: }
3583: }
3584: if ($role eq '') {
3585: my $rolestr = join(', ',@permitted_roles);
1.1 raeburn 3586: $r->print('<br />'.
3587: &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");
3588: next;
3589: }
3590: }
3591: }
3592: if ($role eq '') {
3593: $role = $defaultrole;
3594: }
3595: # Clean up whitespace
3596: foreach (\$domain,\$username,\$id,\$fname,\$mname,
1.27 raeburn 3597: \$lname,\$gen) {
1.1 raeburn 3598: $$_ =~ s/(\s+$|^\s+)//g;
3599: }
1.5 raeburn 3600: # check against rules
3601: my $checkid = 0;
3602: my $newuser = 0;
3603: my (%rulematch,%inst_results,%idinst_results);
3604: my $uhome=&Apache::lonnet::homeserver($username,$domain);
3605: if ($uhome eq 'no_host') {
3606: $checkid = 1;
3607: $newuser = 1;
3608: my $checkhash;
3609: my $checks = { 'username' => 1 };
3610: $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
3611: &Apache::loncommon::user_rule_check($checkhash,$checks,
3612: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
3613: \%got_rules);
3614: if (ref($alerts{'username'}) eq 'HASH') {
3615: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
3616: next if ($alerts{'username'}{$domain}{$username});
3617: }
3618: }
1.13 raeburn 3619: } else {
1.27 raeburn 3620: if ($context eq 'course' || $context eq 'author') {
3621: if ($role eq '') {
3622: my @checkroles;
3623: foreach my $role (@poss_roles) {
3624: my $endkey;
3625: if ($role ne 'st') {
3626: $endkey = ':'.$role;
3627: }
3628: if (exists($userlist{$username.':'.$domain.$endkey})) {
3629: if (!grep(/^\Q$role\E$/,@checkroles)) {
3630: push(@checkroles,$role);
3631: }
3632: }
3633: }
3634: if (@checkroles > 0) {
3635: %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
3636: }
3637: } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
3638: %canmodify = %{$modifiable_fields{$role}};
3639: }
3640: }
3641: my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
3642: for (my $i=0; $i<@userinfo; $i++) {
3643: if (${$newinfo[$i]} ne '') {
3644: if (!$canmodify{$userinfo[$i]}) {
3645: ${$newinfo[$i]} = '';
3646: }
3647: }
3648: }
1.5 raeburn 3649: }
3650: if ($id ne '') {
3651: if (!$newuser) {
3652: my %idhash = &Apache::lonnet::idrget($domain,($username));
3653: if ($idhash{$username} ne $id) {
3654: $checkid = 1;
3655: }
3656: }
3657: if ($checkid) {
3658: my $checkhash;
3659: my $checks = { 'id' => 1 };
3660: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
3661: 'id' => $id };
3662: &Apache::loncommon::user_rule_check($checkhash,$checks,
3663: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
3664: \%got_rules);
3665: if (ref($alerts{'id'}) eq 'HASH') {
3666: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
3667: next if ($alerts{'id'}{$domain}{$id});
3668: }
3669: }
3670: }
3671: }
1.1 raeburn 3672: if ($password || $env{'form.login'} eq 'loc') {
1.27 raeburn 3673: my $multiple = 0;
3674: my ($userresult,$authresult,$roleresult,$idresult);
3675: my (%userres,%authres,%roleres,%idres);
1.42 raeburn 3676: my $singlesec = '';
1.1 raeburn 3677: if ($role eq 'st') {
1.27 raeburn 3678: my $sec;
1.42 raeburn 3679: if (@secs > 0) {
3680: $sec = $secs[0];
1.27 raeburn 3681: }
1.42 raeburn 3682: &modifystudent($domain,$username,$cid,$sec,
1.52 raeburn 3683: $desiredhost,$context);
1.42 raeburn 3684: $roleresult =
3685: &Apache::lonnet::modifystudent
3686: ($domain,$username,$id,$amode,$password,
3687: $fname,$mname,$lname,$gen,$sec,$enddate,
3688: $startdate,$env{'form.forceid'},
1.52 raeburn 3689: $desiredhost,$email,'manual','',$cid,
3690: '',$context);
1.42 raeburn 3691: $userresult = $roleresult;
1.1 raeburn 3692: } else {
1.42 raeburn 3693: if ($role ne '') {
3694: if ($context eq 'course' || $setting eq 'course') {
3695: if ($customroles{$role}) {
3696: $role = 'cr_'.$env{'user.domain'}.'_'.
3697: $env{'user.name'}.'_'.$role;
3698: }
3699: if ($role ne 'cc') {
3700: if (@secs > 1) {
3701: $multiple = 1;
3702: foreach my $sec (@secs) {
3703: ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
3704: &modifyuserrole($context,$setting,
3705: $changeauth,$cid,$domain,$username,
3706: $id,$amode,$password,$fname,
3707: $mname,$lname,$gen,$sec,
3708: $env{'form.forceid'},$desiredhost,
3709: $email,$role,$enddate,
3710: $startdate,$checkid);
3711: }
3712: } elsif (@secs > 0) {
3713: $singlesec = $secs[0];
3714: }
1.27 raeburn 3715: }
3716: }
3717: }
3718: if (!$multiple) {
1.28 raeburn 3719: ($userresult,$authresult,$roleresult,$idresult) =
1.27 raeburn 3720: &modifyuserrole($context,$setting,
1.42 raeburn 3721: $changeauth,$cid,$domain,$username,
3722: $id,$amode,$password,$fname,
3723: $mname,$lname,$gen,$singlesec,
3724: $env{'form.forceid'},$desiredhost,
3725: $email,$role,$enddate,$startdate,$checkid);
1.27 raeburn 3726: }
3727: }
3728: if ($multiple) {
3729: foreach my $sec (sort(keys(%userres))) {
1.42 raeburn 3730: $flushc =
1.27 raeburn 3731: &user_change_result($r,$userres{$sec},$authres{$sec},
3732: $roleres{$sec},$idres{$sec},\%counts,$flushc,
3733: $username,\%userchg);
3734:
3735: }
3736: } else {
3737: $flushc =
3738: &user_change_result($r,$userresult,$authresult,
1.28 raeburn 3739: $roleresult,$idresult,\%counts,$flushc,
1.29 raeburn 3740: $username,\%userchg);
1.1 raeburn 3741: }
3742: } else {
3743: if ($context eq 'course') {
3744: $r->print('<br />'.
3745: &mt('<b>[_1]</b>: Unable to enroll. No password specified.',$username)
3746: );
1.13 raeburn 3747: } elsif ($context eq 'author') {
1.1 raeburn 3748: $r->print('<br />'.
3749: &mt('<b>[_1]</b>: Unable to add co-author. No password specified.',$username)
3750: );
3751: } else {
3752: $r->print('<br />'.
3753: &mt('<b>[_1]</b>: Unable to add user. No password specified.',$username)
3754: );
3755: }
3756: }
3757: }
3758: }
3759: } # end of foreach (@userdata)
3760: # Flush the course logs so reverse user roles immediately updated
1.5 raeburn 3761: &Apache::lonnet::flushcourselogs();
1.29 raeburn 3762: $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
1.1 raeburn 3763: "</p>\n");
3764: if ($counts{'role'} > 0) {
3765: $r->print("<p>\n".
1.29 raeburn 3766: &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");
3767: } else {
3768: $r->print('<p>'.&mt('No roles added').'</p>');
1.1 raeburn 3769: }
3770: if ($counts{'auth'} > 0) {
3771: $r->print("<p>\n".
3772: &mt('Authentication changed for [_1] existing users.',
3773: $counts{'auth'})."</p>\n");
3774: }
1.13 raeburn 3775: $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
1.1 raeburn 3776: #####################################
1.29 raeburn 3777: # Display list of students to drop #
1.1 raeburn 3778: #####################################
3779: if ($env{'form.fullup'} eq 'yes') {
1.29 raeburn 3780: $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
1.1 raeburn 3781: # Get current classlist
1.30 raeburn 3782: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 3783: if (! defined($classlist)) {
1.29 raeburn 3784: $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
3785: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
3786: &mt('There are no students with current/future access to the course.').
3787: '</form>'."\n");
1.1 raeburn 3788: } else {
3789: # Remove the students we just added from the list of students.
1.30 raeburn 3790: foreach my $line (@userdata) {
3791: my %entries=&Apache::loncommon::record_sep($line);
1.1 raeburn 3792: unless (($entries{$fields{'username'}} eq '') ||
3793: (!defined($entries{$fields{'username'}}))) {
3794: delete($classlist->{$entries{$fields{'username'}}.
3795: ':'.$domain});
3796: }
3797: }
3798: # Print out list of dropped students.
1.30 raeburn 3799: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 3800: }
3801: }
3802: } # end of unless
1.29 raeburn 3803: if ($env{'form.fullup'} ne 'yes') {
3804: $r->print('</form>');
3805: }
1.1 raeburn 3806: }
3807:
1.13 raeburn 3808: sub print_namespacing_alerts {
3809: my ($domain,$alerts,$curr_rules) = @_;
3810: my $output;
3811: if (ref($alerts) eq 'HASH') {
3812: if (keys(%{$alerts}) > 0) {
3813: if (ref($alerts->{'username'}) eq 'HASH') {
3814: foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
3815: my $count;
3816: if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
3817: $count = keys(%{$alerts->{'username'}{$dom}});
3818: }
3819: my $domdesc = &Apache::lonnet::domain($domain,'description');
3820: if (ref($curr_rules->{$dom}) eq 'HASH') {
3821: $output .= &Apache::loncommon::instrule_disallow_msg(
3822: 'username',$domdesc,$count,'upload');
3823: }
3824: $output .= &Apache::loncommon::user_rule_formats($dom,
3825: $domdesc,$curr_rules->{$dom}{'username'},
3826: 'username');
3827: }
3828: }
3829: if (ref($alerts->{'id'}) eq 'HASH') {
3830: foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
3831: my $count;
3832: if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
3833: $count = keys(%{$alerts->{'id'}{$dom}});
3834: }
3835: my $domdesc = &Apache::lonnet::domain($domain,'description');
3836: if (ref($curr_rules->{$dom}) eq 'HASH') {
3837: $output .= &Apache::loncommon::instrule_disallow_msg(
3838: 'id',$domdesc,$count,'upload');
3839: }
3840: $output .= &Apache::loncommon::user_rule_formats($dom,
3841: $domdesc,$curr_rules->{$dom}{'id'},'id');
3842: }
3843: }
3844: }
3845: }
3846: }
3847:
1.1 raeburn 3848: sub user_change_result {
1.29 raeburn 3849: my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
3850: $username,$userchg) = @_;
1.1 raeburn 3851: my $okresult = 0;
3852: if ($userresult ne 'ok') {
3853: if ($userresult =~ /^error:(.+)$/) {
3854: my $error = $1;
3855: $r->print('<br />'.
3856: &mt('<b>[_1]</b>: Unable to add/modify: [_2]',$username,$error));
3857: }
3858: } else {
3859: $counts->{'user'} ++;
3860: $okresult = 1;
3861: }
3862: if ($authresult ne 'ok') {
3863: if ($authresult =~ /^error:(.+)$/) {
3864: my $error = $1;
3865: $r->print('<br />'.
3866: &mt('<b>[_1]</b>: Unable to modify authentication: [_2]',$username,$error));
3867: }
3868: } else {
3869: $counts->{'auth'} ++;
3870: $okresult = 1;
3871: }
3872: if ($roleresult ne 'ok') {
3873: if ($roleresult =~ /^error:(.+)$/) {
3874: my $error = $1;
3875: $r->print('<br />'.
3876: &mt('<b>[_1]</b>: Unable to add role: [_2]',$username,$error));
3877: }
3878: } else {
3879: $counts->{'role'} ++;
3880: $okresult = 1;
3881: }
3882: if ($okresult) {
3883: $flushc++;
3884: $userchg->{$username}=1;
3885: $r->print('. ');
3886: if ($flushc>15) {
3887: $r->rflush;
3888: $flushc=0;
3889: }
3890: }
1.29 raeburn 3891: if ($idresult) {
3892: $r->print($idresult);
3893: }
1.1 raeburn 3894: return $flushc;
3895: }
3896:
3897: # ========================================================= Menu Phase Two Drop
1.17 raeburn 3898: sub print_drop_menu {
3899: my ($r,$context,$permission) = @_;
3900: $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
3901: '<form name="studentform" method="post">'."\n");
1.30 raeburn 3902: my $classlist = &Apache::loncoursedata::get_classlist();
1.1 raeburn 3903: if (! defined($classlist)) {
3904: $r->print(&mt('There are no students currently enrolled.')."\n");
1.30 raeburn 3905: } else {
3906: &show_drop_list($r,$classlist,'nosort',$permission);
1.1 raeburn 3907: }
1.17 raeburn 3908: $r->print('</form>'. &Apache::loncommon::end_page());
1.1 raeburn 3909: return;
3910: }
3911:
3912: # ================================================================== Phase four
3913:
1.11 raeburn 3914: sub update_user_list {
3915: my ($r,$context,$setting,$choice) = @_;
3916: my $now = time;
1.1 raeburn 3917: my $count=0;
1.11 raeburn 3918: my @changelist;
1.29 raeburn 3919: if ($choice eq 'drop') {
3920: @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
3921: } else {
1.11 raeburn 3922: @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
3923: }
3924: my %result_text = ( ok => { 'revoke' => 'Revoked',
3925: 'delete' => 'Deleted',
3926: 'reenable' => 'Re-enabled',
1.17 raeburn 3927: 'activate' => 'Activated',
3928: 'chgdates' => 'Changed Access Dates for',
3929: 'chgsec' => 'Changed section for',
3930: 'drop' => 'Dropped',
1.11 raeburn 3931: },
3932: error => {'revoke' => 'revoking',
3933: 'delete' => 'deleting',
3934: 'reenable' => 're-enabling',
3935: 'activate' => 'activating',
1.17 raeburn 3936: 'chgdates' => 'changing access dates for',
3937: 'chgsec' => 'changing section for',
3938: 'drop' => 'dropping',
1.11 raeburn 3939: },
3940: );
3941: my ($startdate,$enddate);
3942: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
3943: ($startdate,$enddate) = &get_dates_from_form();
3944: }
3945: foreach my $item (@changelist) {
3946: my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
3947: $scopestem);
1.17 raeburn 3948: if ($choice eq 'drop') {
3949: ($uname,$udom,$sec) = split(/:/,$item,-1);
3950: $role = 'st';
3951: $cid = $env{'request.course.id'};
3952: $scopestem = '/'.$cid;
3953: $scopestem =~s/\_/\//g;
3954: if ($sec eq '') {
3955: $scope = $scopestem;
3956: } else {
3957: $scope = $scopestem.'/'.$sec;
3958: }
3959: } elsif ($context eq 'course') {
1.11 raeburn 3960: ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
3961: $cid = $env{'request.course.id'};
3962: $scopestem = '/'.$cid;
3963: $scopestem =~s/\_/\//g;
3964: if ($sec eq '') {
3965: $scope = $scopestem;
3966: } else {
3967: $scope = $scopestem.'/'.$sec;
3968: }
1.13 raeburn 3969: } elsif ($context eq 'author') {
1.11 raeburn 3970: ($uname,$udom,$role) = split(/\:/,$item,-1);
3971: $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
3972: } elsif ($context eq 'domain') {
3973: if ($setting eq 'domain') {
3974: ($role,$uname,$udom) = split(/\:/,$item,-1);
3975: $scope = '/'.$env{'request.role.domain'}.'/';
1.13 raeburn 3976: } elsif ($setting eq 'author') {
1.11 raeburn 3977: ($uname,$udom,$role,$scope) = split(/\:/,$item);
3978: } elsif ($setting eq 'course') {
3979: ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
3980: split(/\:/,$item);
3981: $scope = '/'.$cid;
3982: $scope =~s/\_/\//g;
3983: if ($sec ne '') {
3984: $scope .= '/'.$sec;
3985: }
3986: }
3987: }
3988: my $plrole = &Apache::lonnet::plaintext($role);
3989: my $start = $env{'form.'.$item.'_start'};
3990: my $end = $env{'form.'.$item.'_end'};
1.17 raeburn 3991: if ($choice eq 'drop') {
3992: # drop students
3993: $end = $now;
3994: $type = 'manual';
3995: $result =
1.52 raeburn 3996: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.17 raeburn 3997: } elsif ($choice eq 'revoke') {
3998: # revoke or delete user role
1.11 raeburn 3999: $end = $now;
4000: if ($role eq 'st') {
4001: $result =
1.52 raeburn 4002: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4003: } else {
4004: $result =
1.52 raeburn 4005: &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
4006: '','',$context);
1.11 raeburn 4007: }
4008: } elsif ($choice eq 'delete') {
4009: if ($role eq 'st') {
1.52 raeburn 4010: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
1.29 raeburn 4011: }
4012: $result =
4013: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
1.52 raeburn 4014: $start,1,'',$context);
1.11 raeburn 4015: } else {
4016: #reenable, activate, change access dates or change section
4017: if ($choice ne 'chgsec') {
4018: $start = $startdate;
4019: $end = $enddate;
4020: }
4021: if ($choice eq 'reenable') {
4022: if ($role eq 'st') {
1.52 raeburn 4023: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4024: } else {
4025: $result =
4026: &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4027: $now,'','',$context);
1.11 raeburn 4028: }
4029: } elsif ($choice eq 'activate') {
4030: if ($role eq 'st') {
1.52 raeburn 4031: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4032: } else {
4033: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4034: $now,'','',$context);
1.11 raeburn 4035: }
4036: } elsif ($choice eq 'chgdates') {
4037: if ($role eq 'st') {
1.52 raeburn 4038: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4039: } else {
4040: $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
1.52 raeburn 4041: $start,'','',$context);
1.11 raeburn 4042: }
4043: } elsif ($choice eq 'chgsec') {
4044: my (@newsecs,$revresult,$nochg,@retained);
4045: if ($role ne 'cc') {
4046: @newsecs = split(/,/,$env{'form.newsecs'});
4047: }
4048: # remove existing section if not to be retained.
4049: if (!$env{'form.retainsec'}) {
4050: if ($sec eq '') {
4051: if (@newsecs == 0) {
4052: $result = &mt('No change in section assignment (none)');
4053: $nochg = 1;
1.40 raeburn 4054: } else {
4055: $revresult =
4056: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4057: $scope,$role,
4058: '','',$context);
1.40 raeburn 4059: }
1.11 raeburn 4060: } else {
1.28 raeburn 4061: if (@newsecs > 0) {
4062: if (grep(/^\Q$sec\E$/,@newsecs)) {
4063: push(@retained,$sec);
4064: } else {
4065: $revresult =
4066: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4067: $scope,$role,
4068: '','',$context);
1.28 raeburn 4069: }
4070: } else {
1.11 raeburn 4071: $revresult =
1.28 raeburn 4072: &Apache::lonnet::revokerole($udom,$uname,
1.52 raeburn 4073: $scope,$role,
4074: '','',$context);
1.11 raeburn 4075: }
4076: }
4077: } else {
1.28 raeburn 4078: if ($sec eq '') {
4079: $nochg = 1;
4080: } else {
4081: push(@retained,$sec);
4082: }
1.11 raeburn 4083: }
4084: # add new sections
4085: if (@newsecs == 0) {
4086: if (!$nochg) {
1.28 raeburn 4087: if ($role eq 'st') {
4088: $result =
1.52 raeburn 4089: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
1.28 raeburn 4090: } else {
4091: my $newscope = $scopestem;
1.52 raeburn 4092: $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
1.11 raeburn 4093: }
4094: }
4095: } else {
4096: foreach my $newsec (@newsecs) {
4097: if (!grep(/^\Q$newsec\E$/,@retained)) {
4098: if ($role eq 'st') {
1.52 raeburn 4099: $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
1.11 raeburn 4100: } else {
4101: my $newscope = $scopestem;
4102: if ($newsec ne '') {
4103: $newscope .= '/'.$newsec;
4104: }
4105: $result = &Apache::lonnet::assignrole($udom,$uname,
4106: $newscope,$role,$end,$start);
4107: }
4108: }
4109: }
4110: }
4111: }
4112: }
1.17 raeburn 4113: my $extent = $scope;
4114: if ($choice eq 'drop' || $context eq 'course') {
4115: my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
4116: if ($cdesc) {
4117: $extent = $cdesc;
4118: }
4119: }
1.1 raeburn 4120: if ($result eq 'ok' || $result eq 'ok:') {
1.11 raeburn 4121: $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
1.17 raeburn 4122: $plrole,$extent,$uname.':'.$udom).'<br />');
1.1 raeburn 4123: $count++;
4124: } else {
4125: $r->print(
1.29 raeburn 4126: &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
1.17 raeburn 4127: $plrole,$extent,$uname.':'.$udom,$result).'<br />');
1.11 raeburn 4128: }
4129: }
1.32 raeburn 4130: $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
1.33 raeburn 4131: if ($choice eq 'drop') {
4132: $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
4133: '<input type="hidden" name="Status" value="Active" />'."\n".
4134: '<input type="hidden" name="showrole" value="st" />'."\n");
4135: } else {
4136: foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
4137: if ($env{'form.'.$item} ne '') {
4138: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
4139: '" />'."\n");
4140: }
1.32 raeburn 4141: }
4142: }
1.29 raeburn 4143: $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
1.11 raeburn 4144: if ($count > 0) {
1.17 raeburn 4145: if ($choice eq 'revoke' || $choice eq 'drop') {
1.11 raeburn 4146: $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>'));
4147: }
4148: # Flush the course logs so reverse user roles immediately updated
4149: &Apache::lonnet::flushcourselogs();
4150: }
4151: if ($env{'form.makedatesdefault'}) {
4152: if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
1.29 raeburn 4153: $r->print(&make_dates_default($startdate,$enddate,$context));
1.1 raeburn 4154: }
4155: }
1.33 raeburn 4156: my $linktext = &mt('Display User Lists');
4157: if ($choice eq 'drop') {
4158: $linktext = &mt('Display current class roster');
4159: }
4160: $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
1.1 raeburn 4161: }
4162:
1.8 raeburn 4163: sub classlist_drop {
1.29 raeburn 4164: my ($scope,$uname,$udom,$now) = @_;
1.8 raeburn 4165: my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
1.29 raeburn 4166: if (&Apache::lonnet::is_course($cdom,$cnum)) {
4167: my $user = $uname.':'.$udom;
1.8 raeburn 4168: if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
4169: my $result =
4170: &Apache::lonnet::cput('classlist',
1.29 raeburn 4171: { $user => $now },$cdom,$cnum);
1.8 raeburn 4172: return &mt('Drop from classlist: [_1]',
4173: '<b>'.$result.'</b>').'<br />';
4174: }
4175: }
4176: }
4177:
4178: sub active_student_roles {
4179: my ($cnum,$cdom,$uname,$udom) = @_;
4180: my %roles =
4181: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
4182: ['future','active'],['st']);
4183: return exists($roles{"$cnum:$cdom:st"});
4184: }
4185:
1.1 raeburn 4186: sub section_check_js {
1.8 raeburn 4187: my $groupslist= &get_groupslist();
1.1 raeburn 4188: return <<"END";
4189: function validate(caller) {
1.9 raeburn 4190: var groups = new Array($groupslist);
1.1 raeburn 4191: var secname = caller.value;
4192: if ((secname == 'all') || (secname == 'none')) {
4193: alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
4194: return 'error';
4195: }
4196: if (secname != '') {
4197: for (var k=0; k<groups.length; k++) {
4198: if (secname == groups[k]) {
4199: 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.");
4200: return 'error';
4201: }
4202: }
4203: }
4204: return 'ok';
4205: }
4206: END
4207: }
4208:
4209: sub set_login {
4210: my ($dom,$authformkrb,$authformint,$authformloc) = @_;
4211: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4212: my $response;
4213: my ($authnum,%can_assign) =
4214: &Apache::loncommon::get_assignable_auth($dom);
4215: if ($authnum) {
4216: $response = &Apache::loncommon::start_data_table();
4217: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
4218: $response .= &Apache::loncommon::start_data_table_row().
4219: '<td>'.$authformkrb.'</td>'.
4220: &Apache::loncommon::end_data_table_row()."\n";
4221: }
4222: if ($can_assign{'int'}) {
4223: $response .= &Apache::loncommon::start_data_table_row().
4224: '<td>'.$authformint.'</td>'.
4225: &Apache::loncommon::end_data_table_row()."\n"
4226: }
4227: if ($can_assign{'loc'}) {
4228: $response .= &Apache::loncommon::start_data_table_row().
4229: '<td>'.$authformloc.'</td>'.
4230: &Apache::loncommon::end_data_table_row()."\n";
4231: }
4232: $response .= &Apache::loncommon::end_data_table();
4233: }
4234: return $response;
4235: }
4236:
1.8 raeburn 4237: sub course_sections {
1.51 raeburn 4238: my ($sections_count,$role,$current_sec) = @_;
1.8 raeburn 4239: my $output = '';
4240: my @sections = (sort {$a <=> $b} keys %{$sections_count});
1.29 raeburn 4241: my $numsec = scalar(@sections);
1.51 raeburn 4242: my $is_selected = ' selected="selected" ';
1.29 raeburn 4243: if ($numsec <= 1) {
1.8 raeburn 4244: $output = '<select name="currsec_'.$role.'" >'."\n".
1.51 raeburn 4245: ' <option value="">'.&mt('Select').'</option>'."\n";
4246: if ($current_sec eq 'none') {
4247: $output .=
4248: ' <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
4249: } else {
4250: $output .=
1.29 raeburn 4251: ' <option value="">'.&mt('No section').'</option>'."\n";
1.51 raeburn 4252: }
1.29 raeburn 4253: if ($numsec == 1) {
1.51 raeburn 4254: if ($current_sec eq $sections[0]) {
4255: $output .=
4256: ' <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
4257: } else {
4258: $output .=
1.8 raeburn 4259: ' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
1.51 raeburn 4260: }
1.29 raeburn 4261: }
1.8 raeburn 4262: } else {
4263: $output = '<select name="currsec_'.$role.'" ';
4264: my $multiple = 4;
4265: if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
1.29 raeburn 4266: if ($role eq 'st') {
4267: $output .= '>'."\n".
1.51 raeburn 4268: ' <option value="">'.&mt('Select').'</option>'."\n";
4269: if ($current_sec eq 'none') {
4270: $output .=
4271: ' <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
4272: } else {
4273: $output .=
1.29 raeburn 4274: ' <option value="">'.&mt('No section')."</option>\n";
1.51 raeburn 4275: }
1.29 raeburn 4276: } else {
4277: $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
4278: }
1.8 raeburn 4279: foreach my $sec (@sections) {
1.51 raeburn 4280: if ($current_sec eq $sec) {
4281: $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
4282: } else {
4283: $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
4284: }
1.8 raeburn 4285: }
4286: }
4287: $output .= '</select>';
4288: return $output;
4289: }
4290:
4291: sub get_groupslist {
4292: my $groupslist;
4293: my %curr_groups = &Apache::longroup::coursegroups();
4294: if (%curr_groups) {
4295: $groupslist = join('","',sort(keys(%curr_groups)));
4296: $groupslist = '"'.$groupslist.'"';
4297: }
1.11 raeburn 4298: return $groupslist;
1.8 raeburn 4299: }
4300:
4301: sub setsections_javascript {
1.37 raeburn 4302: my ($formname,$groupslist,$mode,$checkauth) = @_;
1.28 raeburn 4303: my ($checkincluded,$finish,$rolecode,$setsection_js);
4304: if ($mode eq 'upload') {
4305: $checkincluded = 'formname.name == "'.$formname.'"';
4306: $finish = "return 'ok';";
4307: $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
4308: } elsif ($formname eq 'cu') {
1.8 raeburn 4309: $checkincluded = 'formname.elements[i-1].checked == true';
1.37 raeburn 4310: if ($checkauth) {
4311: $finish = "var authcheck = auth_check();\n".
4312: " if (authcheck == 'ok') {\n".
4313: " formname.submit();\n".
4314: " }\n";
4315: } else {
4316: $finish = 'formname.submit()';
4317: }
1.28 raeburn 4318: $rolecode = "var match = str.split('_');
4319: var role = match[3];\n";
4320: } elsif ($formname eq 'enrollstudent') {
4321: $checkincluded = 'formname.name == "'.$formname.'"';
1.37 raeburn 4322: if ($checkauth) {
4323: $finish = "var authcheck = auth_check();\n".
4324: " if (authcheck == 'ok') {\n".
4325: " formname.submit();\n".
4326: " }\n";
4327: } else {
4328: $finish = 'formname.submit()';
4329: }
1.28 raeburn 4330: $rolecode = "var match = str.split('_');
4331: var role = match[1];\n";
1.8 raeburn 4332: } else {
1.28 raeburn 4333: $checkincluded = 'formname.name == "'.$formname.'"';
1.8 raeburn 4334: $finish = "seccheck = 'ok';";
1.28 raeburn 4335: $rolecode = "var match = str.split('_');
4336: var role = match[1];\n";
1.11 raeburn 4337: $setsection_js = "var seccheck = 'alert';";
1.8 raeburn 4338: }
4339: my %alerts = &Apache::lonlocal::texthash(
4340: secd => 'Section designations do not apply to Course Coordinator roles.',
4341: accr => 'A course coordinator role will be added with access to all sections.',
4342: inea => 'In each course, each user may only have one student role at a time.',
4343: youh => 'You had selected ',
4344: secs => 'sections.',
4345: plmo => 'Please modify your selections so they include no more than one section.',
4346: mayn => 'may not be used as the name for a section, as it is a reserved word.',
4347: plch => 'Please choose a different section name.',
4348: mnot => 'may not be used as a section name, as it is the name of a course group.',
4349: secn => 'Section names and group names must be distinct. Please choose a different section name.',
1.11 raeburn 4350: );
1.8 raeburn 4351: $setsection_js .= <<"ENDSECCODE";
4352:
4353: function setSections(formname) {
4354: var re1 = /^currsec_/;
4355: var groups = new Array($groupslist);
4356: for (var i=0;i<formname.elements.length;i++) {
4357: var str = formname.elements[i].name;
4358: var checkcurr = str.match(re1);
4359: if (checkcurr != null) {
4360: if ($checkincluded) {
1.28 raeburn 4361: $rolecode
1.8 raeburn 4362: if (role == 'cc') {
4363: alert("$alerts{'secd'}\\n$alerts{'accr'}");
4364: }
4365: else {
4366: var sections = '';
4367: var numsec = 0;
4368: var sections;
4369: for (var j=0; j<formname.elements[i].length; j++) {
4370: if (formname.elements[i].options[j].selected == true ) {
4371: if (formname.elements[i].options[j].value != "") {
4372: if (numsec == 0) {
4373: if (formname.elements[i].options[j].value != "") {
4374: sections = formname.elements[i].options[j].value;
4375: numsec ++;
4376: }
4377: }
4378: else {
4379: sections = sections + "," + formname.elements[i].options[j].value
4380: numsec ++;
4381: }
4382: }
4383: }
4384: }
4385: if (numsec > 0) {
4386: if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
4387: sections = sections + "," + formname.elements[i+1].value;
4388: }
4389: }
4390: else {
4391: sections = formname.elements[i+1].value;
4392: }
4393: var newsecs = formname.elements[i+1].value;
4394: var numsplit;
4395: if (newsecs != null && newsecs != "") {
4396: numsplit = newsecs.split(/,/g);
4397: numsec = numsec + numsplit.length;
4398: }
4399:
4400: if ((role == 'st') && (numsec > 1)) {
4401: alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
4402: return;
4403: }
4404: else {
4405: if (numsplit != null) {
4406: for (var j=0; j<numsplit.length; j++) {
4407: if ((numsplit[j] == 'all') ||
4408: (numsplit[j] == 'none')) {
4409: alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
4410: return;
4411: }
4412: for (var k=0; k<groups.length; k++) {
4413: if (numsplit[j] == groups[k]) {
4414: alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
4415: return;
4416: }
4417: }
4418: }
4419: }
4420: formname.elements[i+2].value = sections;
4421: }
4422: }
4423: }
4424: }
4425: }
4426: $finish
4427: }
4428: ENDSECCODE
1.11 raeburn 4429: return $setsection_js;
1.8 raeburn 4430: }
4431:
1.15 raeburn 4432: sub can_create_user {
4433: my ($dom,$context,$usertype) = @_;
4434: my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4435: my $cancreate = 1;
1.28 raeburn 4436: if (&Apache::lonnet::allowed('mau',$dom)) {
4437: return $cancreate;
4438: }
1.15 raeburn 4439: if (ref($domconf{'usercreation'}) eq 'HASH') {
4440: if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
4441: if ($context eq 'course' || $context eq 'author') {
4442: my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
4443: if ($creation eq 'none') {
4444: $cancreate = 0;
4445: } elsif ($creation ne 'any') {
4446: if (defined($usertype)) {
4447: if ($creation ne $usertype) {
4448: $cancreate = 0;
4449: }
4450: }
4451: }
4452: }
4453: }
4454: }
4455: return $cancreate;
4456: }
4457:
1.20 raeburn 4458: sub can_modify_userinfo {
4459: my ($context,$dom,$fields,$userroles) = @_;
4460: my %domconfig =
4461: &Apache::lonnet::get_dom('configuration',['usermodification'],
4462: $dom);
4463: my %canmodify;
4464: if (ref($fields) eq 'ARRAY') {
4465: foreach my $field (@{$fields}) {
4466: $canmodify{$field} = 0;
4467: if (&Apache::lonnet::allowed('mau',$dom)) {
4468: $canmodify{$field} = 1;
4469: } else {
4470: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4471: if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
4472: if (ref($userroles) eq 'ARRAY') {
4473: foreach my $role (@{$userroles}) {
4474: my $testrole;
4475: if ($role =~ /^cr\//) {
4476: $testrole = 'cr';
4477: } else {
4478: $testrole = $role;
4479: }
4480: if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
4481: if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
4482: $canmodify{$field} = 1;
4483: last;
4484: }
4485: }
4486: }
4487: } else {
4488: foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
4489: if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
4490: if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
4491: $canmodify{$field} = 1;
4492: last;
4493: }
4494: }
4495: }
4496: }
4497: }
4498: } elsif ($context eq 'course') {
4499: if (ref($userroles) eq 'ARRAY') {
4500: if (grep(/^st$/,@{$userroles})) {
4501: $canmodify{$field} = 1;
4502: }
4503: } else {
4504: $canmodify{$field} = 1;
4505: }
4506: }
4507: }
4508: }
4509: }
4510: return %canmodify;
4511: }
4512:
1.18 raeburn 4513: sub check_usertype {
4514: my ($dom,$uname,$rules) = @_;
4515: my $usertype;
4516: if (ref($rules) eq 'HASH') {
4517: my @user_rules = keys(%{$rules});
4518: if (@user_rules > 0) {
4519: my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
4520: if (keys(%rule_check) > 0) {
4521: $usertype = 'unofficial';
4522: foreach my $item (keys(%rule_check)) {
4523: if ($rule_check{$item}) {
4524: $usertype = 'official';
4525: last;
4526: }
4527: }
4528: }
4529: }
4530: }
4531: return $usertype;
4532: }
4533:
1.17 raeburn 4534: sub roles_by_context {
4535: my ($context,$custom) = @_;
4536: my @allroles;
4537: if ($context eq 'course') {
4538: @allroles = ('st','ad','ta','ep','in','cc');
4539: if ($custom) {
4540: push(@allroles,'cr');
4541: }
4542: } elsif ($context eq 'author') {
4543: @allroles = ('ca','aa');
4544: } elsif ($context eq 'domain') {
4545: @allroles = ('li','dg','sc','au','dc');
4546: }
4547: return @allroles;
4548: }
4549:
1.16 raeburn 4550: sub get_permission {
1.17 raeburn 4551: my ($context,$roles) = @_;
1.16 raeburn 4552: my %permission;
4553: if ($context eq 'course') {
1.17 raeburn 4554: my $custom = 1;
4555: my @allroles = &roles_by_context($context,$custom);
4556: foreach my $role (@allroles) {
4557: if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
4558: $permission{'cusr'} = 1;
4559: last;
4560: }
1.16 raeburn 4561: }
4562: if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
4563: $permission{'custom'} = 1;
4564: }
4565: if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
4566: $permission{'view'} = 1;
4567: }
4568: if (!$permission{'view'}) {
4569: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4570: $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
4571: if ($permission{'view'}) {
4572: $permission{'view_section'} = $env{'request.course.sec'};
4573: }
4574: }
1.17 raeburn 4575: if (!$permission{'cusr'}) {
4576: if ($env{'request.course.sec'} ne '') {
4577: my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
4578: $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
4579: if ($permission{'cusr'}) {
4580: $permission{'cusr_section'} = $env{'request.course.sec'};
4581: }
4582: }
4583: }
1.16 raeburn 4584: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
4585: $permission{'grp_manage'} = 1;
4586: }
4587: } elsif ($context eq 'author') {
4588: $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
4589: $permission{'view'} = $permission{'cusr'};
4590: } else {
1.17 raeburn 4591: my @allroles = &roles_by_context($context);
4592: foreach my $role (@allroles) {
1.28 raeburn 4593: if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
4594: $permission{'cusr'} = 1;
1.17 raeburn 4595: last;
4596: }
4597: }
4598: if (!$permission{'cusr'}) {
4599: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
4600: $permission{'cusr'} = 1;
4601: }
1.16 raeburn 4602: }
4603: if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
4604: $permission{'custom'} = 1;
4605: }
4606: $permission{'view'} = $permission{'cusr'};
4607: }
4608: my $allowed = 0;
4609: foreach my $perm (values(%permission)) {
4610: if ($perm) { $allowed=1; last; }
4611: }
4612: return (\%permission,$allowed);
4613: }
4614:
4615: # ==================================================== Figure out author access
4616:
4617: sub authorpriv {
4618: my ($auname,$audom)=@_;
4619: unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
4620: || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
4621: }
4622:
1.27 raeburn 4623: sub roles_on_upload {
1.42 raeburn 4624: my ($context,$setting,%customroles) = @_;
1.27 raeburn 4625: my (@possible_roles,@permitted_roles);
1.42 raeburn 4626: @possible_roles = &curr_role_permissions($context,$setting,1);
1.27 raeburn 4627: foreach my $role (@possible_roles) {
4628: if ($role eq 'cr') {
4629: push(@permitted_roles,keys(%customroles));
4630: } else {
4631: push(@permitted_roles,$role);
4632: }
4633: }
1.42 raeburn 4634: return @permitted_roles;
1.27 raeburn 4635: }
4636:
1.17 raeburn 4637: sub get_course_identity {
4638: my ($cid) = @_;
4639: my ($cnum,$cdom,$cdesc);
4640: if ($cid eq '') {
4641: $cid = $env{'request.course.id'}
4642: }
4643: if ($cid ne '') {
4644: $cnum = $env{'course.'.$cid.'.num'};
4645: $cdom = $env{'course.'.$cid.'.domain'};
4646: $cdesc = $env{'course.'.$cid.'.description'};
4647: if ($cnum eq '' || $cdom eq '') {
4648: my %coursehash =
4649: &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
4650: $cdom = $coursehash{'domain'};
4651: $cnum = $coursehash{'num'};
4652: $cdesc = $coursehash{'description'};
4653: }
4654: }
4655: return ($cnum,$cdom,$cdesc);
4656: }
4657:
1.19 raeburn 4658: sub dc_setcourse_js {
1.37 raeburn 4659: my ($formname,$mode,$context) = @_;
4660: my ($dc_setcourse_code,$authen_check);
1.19 raeburn 4661: my $cctext = &Apache::lonnet::plaintext('cc');
4662: my %alerts = §ioncheck_alerts();
4663: my $role = 'role';
4664: if ($mode eq 'upload') {
4665: $role = 'courserole';
1.37 raeburn 4666: } else {
4667: $authen_check = &verify_authen($formname,$context);
1.19 raeburn 4668: }
4669: $dc_setcourse_code = (<<"SCRIPTTOP");
1.37 raeburn 4670: $authen_check
4671:
1.19 raeburn 4672: function setCourse() {
4673: var course = document.$formname.dccourse.value;
4674: if (course != "") {
4675: if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
4676: alert("$alerts{'curd'}");
4677: return;
4678: }
4679: var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
4680: var section="";
4681: var numsections = 0;
4682: var newsecs = new Array();
4683: for (var i=0; i<document.$formname.currsec.length; i++) {
4684: if (document.$formname.currsec.options[i].selected == true ) {
4685: if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
4686: if (numsections == 0) {
4687: section = document.$formname.currsec.options[i].value
4688: numsections = 1;
4689: }
4690: else {
4691: section = section + "," + document.$formname.currsec.options[i].value
4692: numsections ++;
4693: }
4694: }
4695: }
4696: }
4697: if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
4698: if (numsections == 0) {
4699: section = document.$formname.newsec.value
4700: }
4701: else {
4702: section = section + "," + document.$formname.newsec.value
4703: }
4704: newsecs = document.$formname.newsec.value.split(/,/g);
4705: numsections = numsections + newsecs.length;
4706: }
4707: if ((userrole == 'st') && (numsections > 1)) {
4708: alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
4709: return;
4710: }
4711: for (var j=0; j<newsecs.length; j++) {
4712: if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
4713: alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
4714: return;
4715: }
4716: if (document.$formname.groups.value != '') {
4717: var groups = document.$formname.groups.value.split(/,/g);
4718: for (var k=0; k<groups.length; k++) {
4719: if (newsecs[j] == groups[k]) {
4720: alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
4721: return;
4722: }
4723: }
4724: }
4725: }
4726: if ((userrole == 'cc') && (numsections > 0)) {
4727: alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
4728: section = "";
4729: }
4730: SCRIPTTOP
4731: if ($mode ne 'upload') {
4732: $dc_setcourse_code .= (<<"ENDSCRIPT");
4733: var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
4734: var numcourse = getIndex(document.$formname.dccourse);
4735: if (numcourse == "-1") {
4736: alert("$alerts{'thwa'}");
4737: return;
4738: }
4739: else {
4740: document.$formname.elements[numcourse].name = "act"+coursename;
4741: var numnewsec = getIndex(document.$formname.newsec);
4742: if (numnewsec != "-1") {
4743: document.$formname.elements[numnewsec].name = "sec"+coursename;
4744: document.$formname.elements[numnewsec].value = section;
4745: }
4746: var numstart = getIndex(document.$formname.start);
4747: if (numstart != "-1") {
4748: document.$formname.elements[numstart].name = "start"+coursename;
4749: }
4750: var numend = getIndex(document.$formname.end);
4751: if (numend != "-1") {
4752: document.$formname.elements[numend].name = "end"+coursename
4753: }
4754: }
4755: }
1.37 raeburn 4756: var authcheck = auth_check();
4757: if (authcheck == 'ok') {
4758: document.$formname.submit();
4759: }
1.19 raeburn 4760: }
4761: ENDSCRIPT
4762: } else {
4763: $dc_setcourse_code .= "
4764: document.$formname.sections.value = section;
4765: }
4766: return 'ok';
4767: }
4768: ";
4769: }
4770: $dc_setcourse_code .= (<<"ENDSCRIPT");
4771:
4772: function getIndex(caller) {
4773: for (var i=0;i<document.$formname.elements.length;i++) {
4774: if (document.$formname.elements[i] == caller) {
4775: return i;
4776: }
4777: }
4778: return -1;
4779: }
4780: ENDSCRIPT
1.37 raeburn 4781: return $dc_setcourse_code;
4782: }
4783:
4784: sub verify_authen {
4785: my ($formname,$context) = @_;
4786: my %alerts = &authcheck_alerts();
4787: my $finish = "return 'ok';";
4788: if ($context eq 'author') {
4789: $finish = "document.$formname.submit();";
4790: }
4791: my $outcome = <<"ENDSCRIPT";
4792:
4793: function auth_check() {
4794: var logintype;
4795: if (document.$formname.login.length) {
4796: if (document.$formname.login.length > 0) {
4797: var loginpicked = 0;
4798: for (var i=0; i<document.$formname.login.length; i++) {
4799: if (document.$formname.login[i].checked == true) {
4800: loginpicked = 1;
4801: logintype = document.$formname.login[i].value;
4802: }
4803: }
4804: if (loginpicked == 0) {
4805: alert("$alerts{'authen'}");
4806: return;
4807: }
4808: }
4809: } else {
4810: logintype = document.$formname.login.value;
4811: }
4812: if (logintype == 'nochange') {
4813: return 'ok';
4814: }
4815: var argpicked = document.$formname.elements[logintype+'arg'].value;
4816: if ((argpicked == null) || (argpicked == '') || (typeof argpicked == 'undefined')) {
4817: var alertmsg = '';
4818: switch (logintype) {
4819: case 'krb':
4820: alertmsg = '$alerts{'krb'}';
4821: break;
4822: case 'int':
4823: alertmsg = '$alerts{'ipass'}';
4824: case 'fsys':
4825: alertmsg = '$alerts{'ipass'}';
4826: break;
4827: case 'loc':
4828: alertmsg = '';
4829: break;
4830: default:
4831: alertmsg = '';
4832: }
4833: if (alertmsg != '') {
4834: alert(alertmsg);
4835: return;
4836: }
4837: }
4838: $finish
4839: }
4840: ENDSCRIPT
1.19 raeburn 4841: }
4842:
4843: sub sectioncheck_alerts {
4844: my %alerts = &Apache::lonlocal::texthash(
4845: curd => 'You must select a course in the current domain',
4846: inea => 'In each course, each user may only have one student role at a time',
4847: youh => 'You had selected',
4848: sect => 'sections',
4849: plsm => 'Please modify your selections so they include no more than one section',
4850: mayn => 'may not be used as the name for a section, as it is a reserved word',
4851: plsc => 'Please choose a different section name',
4852: mayt => 'may not be used as the name for a section, as it is the name of a course group',
4853: secn => 'Section names and group names must be distinct',
4854: secd => 'Section designations do not apply to ',
4855: role => 'roles',
4856: accr => 'role will be added with access to all sections',
4857: thwa => 'There was a problem with your course selection'
4858: );
4859: return %alerts;
4860: }
1.17 raeburn 4861:
1.37 raeburn 4862: sub authcheck_alerts {
4863: my %alerts =
4864: &Apache::lonlocal::texthash(
4865: authen => 'You must choose an authentication type.',
4866: krb => 'You need to specify the Kerberos domain.',
4867: ipass => 'You need to specify the initial password.',
4868: );
4869: return %alerts;
4870: }
4871:
1.1 raeburn 4872: 1;
4873:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>