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