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