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