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