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