--- loncom/interface/lonuserutils.pm 2007/10/22 22:16:38 1.1
+++ loncom/interface/lonuserutils.pm 2010/11/09 14:14:55 1.109.2.8
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.1 2007/10/22 22:16:38 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.109.2.8 2010/11/09 14:14:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,18 +35,19 @@ use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
-use LONCAPA();
+use Apache::longroup;
+use Apache::lonnavmaps;
+use LONCAPA qw(:DEFAULT :match);
###############################################################
###############################################################
# Drop student from all sections of a course, except optional $csec
sub modifystudent {
- my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+ my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
# if $csec is undefined, drop the student from all the courses matching
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
- my $cdom = $env{'course.'.$courseid.'.domain'};
- my $cnum = $env{'course.'.$courseid.'.num'};
+ my ($cnum,$cdom) = &get_course_identity($courseid);
my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
@@ -68,14 +69,15 @@ sub modifystudent {
my $reply=&Apache::lonnet::modifystudent
# dom name id mode pass f m l g
($udom,$unam,'', '', '',undef,undef,undef,undef,
- $section,time,undef,undef,$desiredhost);
+ $section,time,undef,undef,$desiredhost,'','manual',
+ '',$courseid,'',$context);
$result .= $reply.':';
}
}
}
}
if ($result eq '') {
- $result = 'Unable to find section for this student';
+ $result = &mt('Unable to find section for this student');
} else {
$result =~ s/(ok:)+/ok/g;
}
@@ -85,71 +87,204 @@ sub modifystudent {
sub modifyuserrole {
my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
$first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
- $end,$start) = @_;
- my ($scope,$userresult,$authresult,$roleresult);
+ $end,$start,$checkid,$inststatus) = @_;
+ my ($scope,$userresult,$authresult,$roleresult,$idresult);
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
$scope =~ s/\_/\//g;
- if ($role ne 'cc' && $sec ne '') {
+ if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
$scope .='/'.$sec;
}
- } elsif ($setting eq 'domain') {
+ } elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
- } elsif ($setting eq 'construction_space') {
+ } elsif ($context eq 'author') {
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
}
if ($context eq 'domain') {
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
if ($uhome ne 'no_host') {
- if (($changeauth) && (&Apache::lonnet::allowed('mau',$udom))) {
+ if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
($umode eq 'localauth')) {
$authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
}
}
+ if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
+ ($env{'form.recurseid'}) && ($checkid)) {
+ my %userupdate = (
+ lastname => $last,
+ middlename => $middle,
+ firstname => $first,
+ generation => $gene,
+ id => $uid,
+ );
+ $idresult = &propagate_id_change($uname,$udom,\%userupdate);
+ }
}
}
$userresult =
&Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
$middle,$last,$gene,$forceid,$desiredhome,
- $email,$role,$start,$end);
+ $email,$inststatus);
if ($userresult eq 'ok') {
- if ($role ne '') {
+ if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
- $role,$end,$start);
+ $role,$end,$start,'',
+ '',$context);
+ }
+ }
+ return ($userresult,$authresult,$roleresult,$idresult);
+}
+
+sub propagate_id_change {
+ my ($uname,$udom,$user) = @_;
+ my (@types,@roles);
+ @types = ('active','future');
+ @roles = ('st');
+ my $idresult;
+ my %roleshash = &Apache::lonnet::get_my_roles($uname,
+ $udom,'userroles',\@types,\@roles);
+ my %args = (
+ one_time => 1,
+ );
+ foreach my $item (keys(%roleshash)) {
+ my ($cnum,$cdom,$role) = split(/:/,$item,-1);
+ my ($start,$end) = split(/:/,$roleshash{$item});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
+ my $cdesc = $coursehash{'description'};
+ if ($cdesc eq '') {
+ $cdesc = $cdom.'_'.$cnum;
+ }
+ if ($result eq 'ok') {
+ $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).' '."\n";
+ } else {
+ $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).' '."\n";
+ }
}
}
- return ($userresult,$authresult,$roleresult);
+ return $idresult;
}
+sub update_classlist {
+ my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
+ my ($uid,$classlistentry);
+ my $fullname =
+ &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
+ $user->{'lastname'},$user->{'generation'},
+ 'lastname');
+ my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
+ $cdom,$cnum);
+ my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
+ my $ididx=&Apache::loncoursedata::CL_ID() - 2;
+ my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
+ my $endidx = &Apache::loncoursedata::CL_END() - 2;
+ my $startidx = &Apache::loncoursedata::CL_START() - 2;
+ for (my $i=0; $i<@classinfo; $i++) {
+ if ($i == $endidx) {
+ if ($newend ne '') {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $startidx) {
+ if ($newend ne '') {
+ if ($classinfo[$i] > $newend) {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $ididx) {
+ if (defined($user->{'id'})) {
+ $classlistentry .= $user->{'id'}.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $nameidx) {
+ if (defined($user->{'lastname'})) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ }
+ $classlistentry =~ s/:$//;
+ my $reply=&Apache::lonnet::cput('classlist',
+ {"$uname:$udom" => $classlistentry},
+ $cdom,$cnum);
+ if (($reply eq 'ok') || ($reply eq 'delayed')) {
+ return 'ok';
+ } else {
+ return 'error: '.$reply;
+ }
+}
+
+
###############################################################
###############################################################
-# build a domain and server selection form
-sub domain_form {
- my ($defdom) = @_;
- # Set up domain and server selection forms
+# build a role type and role selection form
+sub domain_roles_select {
+ # Set up the role type and role selection boxes when in
+ # domain context
+ #
+ # Role types
+ my @roletypes = ('domain','author','course','community');
+ my %lt = &role_type_names();
#
- # Get the domains
- my @domains = &Apache::lonnet::all_domains();
# build up the menu information to be passed to
# &Apache::loncommon::linked_select_forms
my %select_menus;
- foreach my $dom (@domains) {
+ if ($env{'form.roletype'} eq '') {
+ $env{'form.roletype'} = 'domain';
+ }
+ foreach my $roletype (@roletypes) {
# set up the text for this domain
- $select_menus{$dom}->{'text'}= $dom;
+ $select_menus{$roletype}->{'text'}= $lt{$roletype};
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community';
+ }
# we want a choice of 'default' as the default in the second menu
- $select_menus{$dom}->{'default'}= 'default';
- $select_menus{$dom}->{'select2'}->{'default'} = 'default';
+ if ($env{'form.roletype'} ne '') {
+ $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
+ } else {
+ $select_menus{$roletype}->{'default'} = 'Any';
+ }
# Now build up the other items in the second menu
- my %servers = &Apache::lonnet::get_servers($dom,'library');
- foreach my $server (keys(%servers)) {
- $select_menus{$dom}->{'select2'}->{$server}
- = "$server $servers{$server}";
+ my @roles;
+ if ($roletype eq 'domain') {
+ @roles = &domain_roles();
+ } elsif ($roletype eq 'author') {
+ @roles = &construction_space_roles();
+ } else {
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom,$roletype);
+ }
+ my $order = ['Any',@roles];
+ $select_menus{$roletype}->{'order'} = $order;
+ foreach my $role (@roles) {
+ if ($role eq 'cr') {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &mt('Custom role');
+ } else {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &Apache::lonnet::plaintext($role,$crstype);
+ }
}
+ $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
- my $result = &Apache::loncommon::linked_select_forms
- ('studentform',' with home server ',$defdom,
- 'lcdomain','lcserver',\%select_menus);
+ my $result = &Apache::loncommon::linked_select_forms
+ ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
+ 'roletype','showrole',\%select_menus,
+ ['domain','author','course','community']);
return $result;
}
@@ -161,7 +296,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,$formname,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -175,9 +311,9 @@ sub print_upload_manager_header {
}
}
if ($env{'form.upfile_associate'} eq 'reverse') {
- $javascript=&upload_manager_javascript_reverse_associate();
+ $javascript=&upload_manager_javascript_reverse_associate($can_assign);
} else {
- $javascript=&upload_manager_javascript_forward_associate();
+ $javascript=&upload_manager_javascript_forward_associate($can_assign);
}
#
# Deal with restored settings
@@ -191,72 +327,136 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
+ my ($sectionjs,$groupslist);
+ if ($context eq 'course') {
+ $groupslist = &get_groupslist();
+ if ($env{'form.context'} eq 'requestcrs') {
+ $sectionjs = <<"ENDJS";
+
+function toggleSectionsDefault() {
+ var usingsecs;
+ if (document.$formname.usesection.length > 1) {
+ for (var i=0; iprint(&mt('Total number of records found in file: [_1].',$distotal).
- " \n");
+ &javascript_validations('upload',$krbdefdom,$password_choice,undef,
+ $env{'request.role.domain'},$context,
+ $groupslist,$crstype);
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ $r->print('
'
+ .&mt('Total number of records found in file: [_1]'
+ ,''.$distotal.'')
+ ."
\n");
$r->print('
'.
&mt('Identify fields in uploaded list')."
\n");
- $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page, if the data selected are insufficient to add users.')." \n");
+ $r->print(&mt('Enter as many fields as you can.').' '.
+ &mt('The system will inform you and bring you back to this page,').
+ ' '.&mt('if the data selected are insufficient to add users.')." \n");
$r->print(&hidden_input('action','upload').
&hidden_input('state','got_file').
&hidden_input('associate','').
&hidden_input('datatoken',$datatoken).
&hidden_input('fileupload',$env{'form.fileupload'}).
&hidden_input('upfiletype',$env{'form.upfiletype'}).
- &hidden_input('upfile_associate',$env{'form.upfile_associate'}));
- $r->print(' ');
- $r->print('');
+ &hidden_input('upfile_associate',$env{'form.upfile_associate'}).
+ &hidden_input('context',$env{'form.context'}));
+ $r->print('
');
+ $r->print(' ');
$r->print("
\n".
'');
+ '// '."\n".
+ '');
}
###############################################################
###############################################################
sub javascript_validations {
- my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_;
- my $authheader;
- if ($mode eq 'auth') {
- my %param = ( formname => 'studentform',
- kerb_def_dom => $krbdefdom,
- curr_authtype => $curr_authtype);
- $authheader = &Apache::loncommon::authform_header(%param);
- } elsif ($mode eq 'createcourse') {
- my %param = ( formname => 'ccrs',
- kerb_def_dom => $krbdefdom,
- curr_authtype => $curr_authtype );
- $authheader = &Apache::loncommon::authform_header(%param);
- } elsif ($mode eq 'modifycourse') {
- my %param = ( formname => 'cmod',
+ my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
+ $context,$groupslist,$crstype)=@_;
+ my %param = (
kerb_def_dom => $krbdefdom,
- mode => 'modifycourse',
curr_authtype => $curr_authtype,
- curr_autharg => $curr_authfield );
- $authheader = &Apache::loncommon::authform_header(%param);
+ );
+ if ($mode eq 'upload') {
+ $param{'formname'} = 'studentform';
+ } elsif ($mode eq 'createcourse') {
+ $param{'formname'} = 'ccrs';
+ } elsif ($mode eq 'modifycourse') {
+ $param{'formname'} = 'cmod';
+ $param{'mode'} = 'modifycourse',
+ $param{'curr_autharg'} = $curr_authfield;
}
+ my ($setsection_call,$setsections_js);
+ my $finish = " vf.submit();\n";
+ if ($mode eq 'upload') {
+ if (($context eq 'course') || ($context eq 'domain')) {
+ if ($context eq 'course') {
+ if ($env{'request.course.sec'} eq '') {
+ $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
+ if ($env{'form.context'} eq 'requestcrs') {
+ $setsections_js = &newsections_javascript($param{'formname'});
+ } else {
+ $setsections_js =
+ &setsections_javascript($param{'formname'},$groupslist,
+ $mode,'',$crstype);
+ }
+ } else {
+ $setsection_call = "'ok'";
+ }
+ } elsif ($context eq 'domain') {
+ $setsection_call = 'setCourse()';
+ $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context);
+ }
+ $finish = " var checkSec = $setsection_call\n".
+ " if (checkSec == 'ok') {\n".
+ " vf.submit();\n".
+ " }\n";
+ }
+ }
+ my $authheader = &Apache::loncommon::authform_header(%param);
+
my %alert = &Apache::lonlocal::texthash
(username => 'You need to specify the username field.',
authen => 'You must choose an authentication type.',
krb => 'You need to specify the Kerberos domain.',
ipass => 'You need to specify the initial password.',
name => 'The optional name field was not specified.',
- snum => 'The optional ID number field was not specified.',
+ snum => 'The optional student/employee ID field was not specified.',
section => 'The optional section field was not specified.',
- email => 'The optional email address field was not specified.',
+ email => 'The optional e-mail address field was not specified.',
role => 'The optional role field was not specified.',
+ domain => 'The optional domain field was not specified.',
continue => 'Continue adding users?',
);
+ if (($mode eq 'upload') && ($context eq 'domain')) {
+ $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
+ }
+ my $function_name = <<"END";
+$setsections_js
-# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
- my $function_name =(< 1) {
+ $auth_update = <<"END";
+ // If we set the password, make the password form below correspond to
+ // the new value.
+ if (nw==9) {
+ changed_radio('int',document.studentform);
+ set_auth_radio_buttons('int',document.studentform);
+END
+ }
+ if ($can_assign->{'krb'}) {
+ $auth_update .= " vf.krbarg.value='';\n";
+ }
+ if ($can_assign->{'int'}) {
+ $auth_update .= " vf.intarg.value='';\n";
+ }
+ if ($can_assign->{'loc'}) {
+ $auth_update .= " vf.locarg.value='';\n";
+ }
+ $auth_update .= "
+ }\n";
+ }
+
return(<=2) && (tw<=6)) { foundname=1; }
- if (tw==7) { foundid=1; }
- if (tw==8) { foundsec=1; }
- if (tw==9) { foundpwd=1; }
+ if (tw==2) { foundpwd=1; }
+ if ((tw>=3) && (tw<=7)) { foundname=1; }
+ if (tw==8) { foundid=1; }
+ if (tw==9) { foundsec=1; }
if (tw==10) { foundemail=1; }
if (tw==11) { foundrole=1; }
+ if (tw==12) { founddomain=1; }
+ if (tw==13) { foundinststatus=1; }
}
- verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole);
+ verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
}
//
@@ -428,16 +689,18 @@ function verify(vf,sec_caller) {
//
// 0 = none
// 1 = username
-// 2 = names (lastname, firstnames)
-// 3 = fname (firstname)
-// 4 = mname (middlename)
-// 5 = lname (lastname)
-// 6 = gen (generation)
-// 7 = id
-// 8 = section
-// 9 = ipwd (password)
+// 2 = ipwd (password)
+// 3 = names (lastname, firstnames)
+// 4 = fname (firstname)
+// 5 = mname (middlename)
+// 6 = lname (lastname)
+// 7 = gen (generation)
+// 8 = id
+// 9 = section
// 10 = email address
// 11 = role
+// 12 = domain
+// 13 = inststatus
function flip(vf,tf) {
var nw=eval('vf.f'+tf+'.selectedIndex');
@@ -449,39 +712,31 @@ function flip(vf,tf) {
}
}
// If we set this to 'lastname, firstnames', clear out all the ones
- // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
- if (nw==2) {
+ // set to 'fname','mname','lname','gen' (4,5,6,7) currently.
+ if (nw==3) {
for (i=0;i<=vf.nfields.value;i++) {
- if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
- (eval('vf.f'+i+'.selectedIndex')<=6)) {
+ if ((eval('vf.f'+i+'.selectedIndex')>=4) &&
+ (eval('vf.f'+i+'.selectedIndex')<=7)) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
}
- // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
- // clear out any that are set to 'lastname, firstnames' (2)
- if ((nw>=3) && (nw<=6)) {
+ // If we set this to one of 'fname','mname','lname','gen' (4,5,6,7),
+ // clear out any that are set to 'lastname, firstnames' (3)
+ if ((nw>=4) && (nw<=7)) {
for (i=0;i<=vf.nfields.value;i++) {
- if (eval('vf.f'+i+'.selectedIndex')==2) {
+ if (eval('vf.f'+i+'.selectedIndex')==3) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
}
- // If we set the password, make the password form below correspond to
- // the new value.
- if (nw==9) {
- changed_radio('int',document.studentform);
- set_auth_radio_buttons('int',document.studentform);
- vf.intarg.value='';
- vf.krbarg.value='';
- vf.locarg.value='';
- }
+ $auth_update
}
function clearpwd(vf) {
var i;
for (i=0;i<=vf.nfields.value;i++) {
- if (eval('vf.f'+i+'.selectedIndex')==9) {
+ if (eval('vf.f'+i+'.selectedIndex')==2) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
@@ -493,6 +748,29 @@ ENDPICK
###############################################################
###############################################################
sub upload_manager_javascript_reverse_associate {
+ my ($can_assign) = @_;
+ my $auth_update;
+ if (ref($can_assign) eq 'HASH') {
+ if (keys(%{$can_assign}) > 1) {
+ $auth_update = <<"END";
+ // initial password specified, pick internal authentication
+ if (tf==8 && nw!=0) {
+ changed_radio('int',document.studentform);
+ set_auth_radio_buttons('int',document.studentform);
+END
+ }
+ if ($can_assign->{'krb'}) {
+ $auth_update .= " vf.krbarg.value='';\n";
+ }
+ if ($can_assign->{'int'}) {
+ $auth_update .= " vf.intarg.value='';\n";
+ }
+ if ($can_assign->{'loc'}) {
+ $auth_update .= " vf.locarg.value='';\n";
+ }
+ $auth_update .= "
+ }\n";
+ }
return(<=1) && (i<=5)) && tw!=0 ) { foundname=1; }
- if (i==6 && tw!=0) { foundid=1; }
- if (i==7 && tw!=0) { foundsec=1; }
- if (i==8 && tw!=0) { foundpwd=1; }
- if (i==9 && tw!=0) { foundrole=1; }
+ if (i==1 && tw!=0) { foundpwd=1; }
+ if (((i>=2) && (i<=6)) && tw!=0 ) { foundname=1; }
+ if (i==7 && tw!=0) { foundid=1; }
+ if (i==8 && tw!=0) { foundsec=1; }
+ if (i==9 && tw!=0) { foundemail=1; }
+ if (i==10 && tw!=0) { foundrole=1; }
+ if (i==11 && tw!=0) { founddomain=1; }
+ if (i==12 && tw!=0) { foundinstatus=1; }
}
- verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole);
+ verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
}
function flip(vf,tf) {
var nw=eval('vf.f'+tf+'.selectedIndex');
var i;
// picked the all one name field, reset the other name ones to blank
- if (tf==1 && nw!=0) {
- for (i=2;i<=5;i++) {
+ if (tf==2 && nw!=0) {
+ for (i=3;i<=6;i++) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
//picked one of the piecewise name fields, reset the all in
//one field to blank
- if ((tf>=2) && (tf<=5) && (nw!=0)) {
- eval('vf.f1.selectedIndex=0;')
- }
- // intial password specified, pick internal authentication
- if (tf==8 && nw!=0) {
- changed_radio('int',document.studentform);
- set_auth_radio_buttons('int',document.studentform);
- vf.krbarg.value='';
- vf.intarg.value='';
- vf.locarg.value='';
+ if ((tf>=3) && (tf<=6) && (nw!=0)) {
+ eval('vf.f2.selectedIndex=0;')
}
+ $auth_update
}
function clearpwd(vf) {
var i;
- if (eval('vf.f8.selectedIndex')!=0) {
- eval('vf.f8.selectedIndex=0;')
+ if (eval('vf.f1.selectedIndex')!=0) {
+ eval('vf.f1.selectedIndex=0;')
}
}
ENDPICK
@@ -550,18 +827,12 @@ ENDPICK
###############################################################
###############################################################
sub print_upload_manager_footer {
- my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context)=@_;
- my $formname;
- if ($context eq 'course') {
- $formname = 'document.studentform';
- } elsif ($context eq 'construction_space') {
- $formname = 'document.studentform';
- } elsif ($context eq 'domain') {
- $formname = 'document.studentform';
- }
+ my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype) = @_;
+ my $form = 'document.studentform';
+ my $formname = 'studentform';
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
- my %param = ( formname => $formname,
+ my %param = ( formname => $form,
kerb_def_dom => $krbdefdom,
kerb_def_auth => $krbdef
);
@@ -570,86 +841,216 @@ sub print_upload_manager_footer {
$env{'form.ipwd_choice'} ne '') {
$param{'curr_authtype'} = 'int';
}
+ if ($env{'form.context'} eq 'requestcrs') {
+ $param{'context'} = $env{'form.context'};
+ }
my $krbform = &Apache::loncommon::authform_kerberos(%param);
my $intform = &Apache::loncommon::authform_internal(%param);
my $locform = &Apache::loncommon::authform_local(%param);
- my $date_table = &date_setting_table(undef,undef,$context);
+ my $date_table = &date_setting_table(undef,undef,$context,undef,
+ $formname,$permission,$crstype);
my $Str = "\n".'
'.&mt('Change authentication for existing users to these settings?').'
';
+ $Str .= '
'
+ .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
+ ,$defdom)
+ .' '
+ .' '
+ .'
';
} else {
- $Str .= "
\n".
- &mt('Note: this will not take effect if the user already exists').
- &Apache::loncommon::help_open_topic('Auth_Options').
- "
\n";
+ $Str .= '
'."\n".
+ &mt('This will not take effect if the user already exists.');
+ my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
+ if ($authnum > 1) {
+ $Str .= &Apache::loncommon::help_open_topic('Auth_Options');
+ }
+ $Str .= "
'."\n".
- &mt('Pick the action to take on roles for these users:').' ';
- }
- if ($context eq 'construction_space') {
- $Str .= '
'.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without one specified in the uploaded file');
- } elsif ($context eq 'course') {
- $Str .= '
'.&mt('Default role and section')."
\n".
- &mt('Choose the role and/or section to assign to users without one specified in the uploaded file');
+ $Str .= &Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(
+ &mt('LON-CAPA Home Server for New Users'))
+ .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
+ .$home_server_pick
+ .&Apache::lonhtmlcommon::row_closure();
} else {
- $Str .= '
'.&mt('Default role and/or section')." \n".
- &mt('Role and/or section for users without one in the uploaded file.');
+ $Str .= $home_server_pick.
+ &Apache::lonhtmlcommon::row_closure();
+ }
+
+ unless ($env{'form.context'} eq 'requestcrs') {
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
+ .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
+ .&Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
+ ."
';
- my ($options,$cb_script,$coursepick) = &default_role_selector($context);
if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').' '.$options.'
'.&mt('Course Level').' '.$cb_script.$coursepick;
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Settings for assigning roles'))
+ .&mt('Pick the action to take on roles for these users:').' '
+ .''
+ .' '
+ .' '
+ .'';
+ } elsif ($context eq 'author') {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role'))
+ .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
+ } elsif ($context eq 'course') {
+ if ($env{'form.context'} eq 'requestcrs') {
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default section')).
+ &mt('Students can be assigned to different sections.').' '.
+ &mt('Will you be using sections?').' '.
+ ''.
+ ' '.&mt('Yes').''.
+ ' ';
+ } else {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and section'))
+ .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
+ }
+ } else {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and/or section(s)'))
+ .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
+ }
+ if (($context eq 'domain') || ($context eq 'author')) {
+ $Str .= ' ';
+ my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
+ if ($context eq 'domain') {
+ $Str .= '
';
+ } else {
+ $Str .= $secbox;
+ }
+ my %lt;
+ if ($crstype eq 'Community') {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display members with current/future access who are not in the uploaded file',
+ stus => 'Members selected from this list can be dropped.'
+ );
+ } else {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display students with current/future access who are not in the uploaded file',
+ stus => 'Students selected from this list can be dropped.'
+ );
+ }
+ unless ($env{'form.context'} eq 'requestcrs') {
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
+ .' '
+ .$lt{'stus'}
+ .&Apache::lonhtmlcommon::row_closure();
+ }
}
- if ($context eq 'course') {
- $Str .= "
".&mt('Full Update')."
\n".
- '\n";
- }
- $Str .= "
".&mt('ID/Student Number')."
\n";
- $Str .= "
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')."
\n";
- $Str .= '
';
+
+ # Footer
+ $Str .= '';
$r->print($Str);
return;
}
+sub forceid_change {
+ my ($context) = @_;
+ my $output =
+ &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
+ .' '."\n"
+ .&mt('(only do if you know what you are doing.)')."\n";
+ if ($context eq 'domain') {
+ $output .= ' '."\n";
+ }
+ $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
+ return $output;
+}
+
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission,$crstype,$formname) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -679,6 +1080,8 @@ sub print_upload_manager_form {
'ipwd_choice' => 'scalar',
'email_choice' => 'scalar',
'role_choice' => 'scalar',
+ 'domain_choice' => 'scalar',
+ 'inststatus_choice' => 'scalar',
};
my $defdom = $env{'request.role.domain'};
if ($context eq 'course') {
@@ -693,22 +1096,26 @@ sub print_upload_manager_form {
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
#
- &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context);
+ my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
+ $permission,$crstype,$formname,\%can_assign);
my $i;
my $keyfields;
if ($total>=0) {
my @field=
(['username',&mt('Username'), $env{'form.username_choice'}],
+ ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
['names',&mt('Last Name, First Names'),$env{'form.names_choice'}],
['fname',&mt('First Name'), $env{'form.fname_choice'}],
['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
['lname',&mt('Last Name'), $env{'form.lname_choice'}],
['gen', &mt('Generation'), $env{'form.gen_choice'}],
- ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
+ ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
['sec', &mt('Section'), $env{'form.sec_choice'}],
- ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
['email',&mt('E-mail Address'), $env{'form.email_choice'}],
- ['role',&mt('Role'), $env{'form.role_choice'}]);
+ ['role',&mt('Role'), $env{'form.role_choice'}],
+ ['domain',&mt('Domain'), $env{'form.domain_choice'}],
+ ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -727,11 +1134,14 @@ sub print_upload_manager_form {
}
$r->print('');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context);
+ $context,$permission,$crstype);
}
sub setup_date_selectors {
- my ($starttime,$endtime,$mode) = @_;
+ my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
+ if ($formname eq '') {
+ $formname = 'studentform';
+ }
if (! defined($starttime)) {
$starttime = time;
unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
@@ -752,12 +1162,15 @@ sub setup_date_selectors {
}
}
}
- my $startdateform = &Apache::lonhtmlcommon::date_setter('studentform',
- 'startdate',
- $starttime);
- my $enddateform = &Apache::lonhtmlcommon::date_setter('studentform',
- 'enddate',
- $endtime);
+
+ my $startdateform =
+ &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
+ undef,undef,undef,undef,undef,undef,undef,$nolink);
+
+ my $enddateform =
+ &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
+ undef,undef,undef,undef,undef,undef,undef,$nolink);
+
if ($mode eq 'create_enrolldates') {
$startdateform = &Apache::lonhtmlcommon::date_setter('ccrs',
'startenroll',
@@ -779,8 +1192,15 @@ sub setup_date_selectors {
sub get_dates_from_form {
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
+ my ($startname,$endname) = @_;
+ if ($startname eq '') {
+ $startname = 'startdate';
+ }
+ if ($endname eq '') {
+ $endname = 'enddate';
+ }
+ my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
+ my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
if ($env{'form.no_end_date'}) {
$enddate = 0;
}
@@ -788,35 +1208,51 @@ sub get_dates_from_form {
}
sub date_setting_table {
- my ($starttime,$endtime,$mode) = @_;
- my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
+ my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
+ my $nolink;
+ if ($bulkaction) {
+ $nolink = 1;
+ }
+ my ($startform,$endform) =
+ &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
my $dateDefault;
if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
$dateDefault = ' ';
- } elsif ($mode ne 'construction_space' && $mode ne 'domain') {
- $dateDefault = ''.
- '';
+ } elsif ($mode ne 'author' && $mode ne 'domain') {
+ if (($bulkaction eq 'reenable') ||
+ ($bulkaction eq 'activate') ||
+ ($bulkaction eq 'chgdates') ||
+ ($env{'form.action'} eq 'upload')) {
+ if ($env{'request.course.sec'} eq '') {
+ $dateDefault = ''.
+ '';
+ }
+ }
}
- my $perpetual = '';
+ $perpetual.= ' /> '.&mt('no ending date').'';
if ($mode eq 'create_enrolldates') {
$perpetual = ' ';
}
- my $result = &Apache::lonhtmlcommon::start_pick_box()."\n".
- &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
- 'LC_oddrow_value')."\n".
- $startform."\n".
- &Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
- 'LC_oddrow_value')."\n".
- $endform.' '.$perpetual.
- &Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box().' ';
+ my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
+ $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
+ 'LC_oddrow_value')."\n".
+ $startform."\n".
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
+ 'LC_oddrow_value')."\n".
+ $endform.' '.$perpetual.
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::end_pick_box();
if ($dateDefault) {
$result .= $dateDefault.' '."\n";
}
@@ -824,34 +1260,42 @@ sub date_setting_table {
}
sub make_dates_default {
- my ($startdate,$enddate,$context) = @_;
+ my ($startdate,$enddate,$context,$crstype) = @_;
my $result = '';
if ($context eq 'course') {
- my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my ($cnum,$cdom) = &get_course_identity();
my $put_result = &Apache::lonnet::put('environment',
{'default_enrollment_start_date'=>$startdate,
- 'default_enrollment_end_date' =>$enddate},$dom,$crs);
+ 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
- $result .= "Set default start and end dates for course ";
+ if ($crstype eq 'Community') {
+ $result .= &mt('Set default start and end access dates for community.');
+ } else {
+ $result .= &mt('Set default start and end access dates for course.');
+ }
+ $result .= ' '."\n";
#
# Refresh the course environment
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
} else {
- $result .= &mt('Unable to set default dates for course').":".$put_result.
- ' ';
+ if ($crstype eq 'Community') {
+ $result .= &mt('Unable to set default access dates for community');
+ } else {
+ $result .= &mt('Unable to set default access dates for course');
+ }
+ $result .= ':'.$put_result.' ';
}
}
return $result;
}
sub default_role_selector {
- my ($context) = @_;
+ my ($context,$checkpriv,$crstype) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
- if ($context ne 'construction_space') {
- %customroles = &my_custom_roles();
+ if ($context ne 'author') {
+ %customroles = &my_custom_roles($crstype);
}
my %lt=&Apache::lonlocal::texthash(
@@ -860,115 +1304,146 @@ sub default_role_selector {
'exs' => "Existing sections",
'new' => "New section",
);
- $options = '
\n".
+ '');
+ return;
+ }
+ if (!(($context eq 'domain') &&
+ (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
+ $r->print(' '.&list_submit_button(&mt('Update Display')).
+ "\n\n");
+ }
+ my ($indexhash,$keylist) = &make_keylist_array();
+ my (%userlist,%userinfo,$clearcoursepick);
+ if (($context eq 'domain') &&
+ ($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
+ my ($crstype,$numcodes,$title,$warning);
+ if ($env{'form.roletype'} eq 'course') {
+ $crstype = 'Course';
+ $numcodes = $totcodes;
+ $title = &mt('Select Courses');
+ $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
+ } elsif ($env{'form.roletype'} eq 'community') {
+ $crstype = 'Community';
+ $numcodes = 0;
+ $title = &mt('Select Communities');
+ $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
+ }
+ my $courseform =
+ &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
+ $codetitles,$idlist,$idlist_titles,$crstype);
+ $r->print('
'."\n");
+ ' '."\n";
+ }
}
- $r->print(&Apache::end_data_table_header_row());
- }
+ }
+ $output .= &Apache::loncommon::end_data_table_header_row();
# Done with the HTML header line
-
} elsif ($mode eq 'csv') {
#
# Open a file
$CSVfilename = '/prtspool/'.
- $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
- time.'_'.rand(1000000000).'.csv';
+ $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.csv';
unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
$r->log_error("Couldn't open $CSVfilename for output $!");
- $r->print("Problems occured in writing the csv file. ".
- "This error has been logged. ".
- "Please alert your LON-CAPA administrator.");
+ $r->print(
+ '
'
+ .&mt('Problems occurred in writing the CSV file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
$CSVfile = undef;
}
#
- # Write headers and data to file
- if($statusmode eq 'Expired') {
- print $CSVfile '"'.&mt('Users with expired roles').'"'."\n"; }
- if($statusmode eq 'Future') {
- print $CSVfile '"'.&mt('Users with future roles').'"'."\n";
+ if ($clickersupport) {
+ push @cols,'clicker';
}
+ # Write headers and data to file
+ print $CSVfile '"'.$results_description.'"'."\n";
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate($lt{$_})
- } (@cols)).'"'."\n";
+ } (@cols))."\"\n";
} elsif ($mode eq 'excel') {
+ if ($clickersupport) {
+ push @cols,'clicker';
+ }
# Create the excel spreadsheet
($excel_workbook,$excel_filename,$format) =
&Apache::loncommon::create_workbook($r);
return if (! defined($excel_workbook));
$excel_sheet = $excel_workbook->addworksheet('userlist');
- #
- my $description;
- if ($context eq 'course') {
- $description = &mt('Class List for ').
- $env{'course.'.$env{'request.course.id'}.'.description'};
- } elsif ($context eq 'construction_space') {
- $description = &mt('List of co-authors for construction space for [_1]',
- &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}));
- } else {
- $description = &mt('List of users for domain: [_1]',&Apache::lonnet::domain($env{'request.role.domain'},'description'));
- }
- $excel_sheet->write($row++,0,$description,$format->{'h1'});
+ $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
#
my @colnames = map {$lt{$_}} (@cols);
+
$excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
}
# Done with header lines in all formats
-
- #
- # Sort the users
my %index;
my $i;
- foreach (@$keylist) {
- $index{$_} = $i++;
+ foreach my $idx (@$keylist) {
+ $index{$idx} = $i++;
}
- $index{'groups'} = scalar(@$keylist);
+ my $usercount = 0;
+ my ($secfilter,$grpfilter);
+ if ($context eq 'course') {
+ $secfilter = $env{'form.secfilter'};
+ $grpfilter = $env{'form.grpfilter'};
+ if ($secfilter eq '') {
+ $secfilter = 'all';
+ }
+ if ($grpfilter eq '') {
+ $grpfilter = 'all';
+ }
+ }
+ my %ltstatus = &Apache::lonlocal::texthash(
+ Active => 'Active',
+ Future => 'Future',
+ Expired => 'Expired',
+ );
+ # If this is for a single course get last course "log-in" and submissions.
+ my (%crslogins,%stusubmissions,%elapsed,$numparts,%nummultipart,$multipart);
+ my $now = time;
+ if ($context eq 'course') {
+ if ($custommenu) {
+ %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
+ %stusubmissions=&Apache::lonnet::dump('nohist_submissiontracker',$cdom,$cnum);
+ %elapsed = &Apache::lonlocal::texthash(
+ -1 => 'more than a month ago',
+ 2592000 => 'within last 30 days',
+ 604800 => 'within last 7 days',
+ 86400 => 'within last 24 hours',
+ );
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (defined($navmap)) {
+ my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub { $_[0]->is_problem() },0);
+ foreach my $resource (@allres) {
+ my @parts = $resource->parts();
+ my $count = scalar(@parts);
+ if ($count > 1) {
+ $nummultipart{$count} ++;
+ }
+ $numparts += $count;
+ }
+ if (keys(%nummultipart) > 0) {
+ $multipart = ' '.'contains';
+ foreach my $key (sort {$a <=> $b} keys(%nummultipart)) {
+ $multipart .= " nummultipart{$key} multipart questions (with $key parts)";
+ }
+ }
+ }
+ }
+ }
+
+ # Get groups, role, permanent e-mail so we can sort on them if
+ # necessary.
+ foreach my $user (keys(%{$userlist})) {
+ if ($user eq '' ) {
+ delete($userlist->{$user});
+ next;
+ }
+ if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
+ delete($userlist->{$user});
+ next;
+ }
+ my ($uname,$udom,$role,$groups,$email);
+ if (($statusmode ne 'Any') &&
+ ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
+ delete($userlist->{$user});
+ next;
+ }
+ if ($context eq 'domain') {
+ if ($env{'form.roletype'} eq 'domain') {
+ ($role,$uname,$udom) = split(/:/,$user);
+ if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
+ ($udom eq $env{'request.role.domain'})) {
+ delete($userlist->{$user});
+ next;
+ }
+ } elsif ($env{'form.roletype'} eq 'author') {
+ ($uname,$udom,$role) = split(/:/,$user,-1);
+ } elsif (($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
+ ($uname,$udom,$role) = split(/:/,$user);
+ }
+ } else {
+ ($uname,$udom,$role) = split(/:/,$user,-1);
+ if (($context eq 'course') && $role eq '') {
+ $role = 'st';
+ }
+ }
+ $userlist->{$user}->[$index{'role'}] = $role;
+ if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
+ delete($userlist->{$user});
+ next;
+ }
+ if ($context eq 'course') {
+ my @ac_groups;
+ if (ref($classgroups) eq 'HASH') {
+ $groups = $classgroups->{$user};
+ }
+ if (ref($groups->{'active'}) eq 'HASH') {
+ @ac_groups = keys(%{$groups->{'active'}});
+ $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
+ }
+ if ($mode ne 'autoenroll') {
+ my $section = $userlist->{$user}->[$index{'section'}];
+ if (($env{'request.course.sec'} ne '') &&
+ ($section ne $env{'request.course.sec'})) {
+ if ($role eq 'st') {
+ delete($userlist->{$user});
+ next;
+ }
+ }
+ if ($secfilter eq 'none') {
+ if ($section ne '') {
+ delete($userlist->{$user});
+ next;
+ }
+ } elsif ($secfilter ne 'all') {
+ if ($section ne $secfilter) {
+ delete($userlist->{$user});
+ next;
+ }
+ }
+ if ($grpfilter eq 'none') {
+ if (@ac_groups > 0) {
+ delete($userlist->{$user});
+ next;
+ }
+ } elsif ($grpfilter ne 'all') {
+ if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
+ delete($userlist->{$user});
+ next;
+ }
+ }
+ if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
+ if (($displayphotos eq 'on') && ($role eq 'st')) {
+ $userlist->{$user}->[$index{'photo'}] =
+ &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
+ $userlist->{$user}->[$index{'thumbnail'}] =
+ &Apache::lonnet::retrievestudentphoto($udom,$uname,
+ 'gif','thumbnail');
+ }
+ }
+ }
+ }
+ my %emails = &Apache::loncommon::getemails($uname,$udom);
+ if ($emails{'permanentemail'} =~ /\S/) {
+ $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
+ }
+ $usercount ++;
+ }
+ my $autocount = 0;
+ my $manualcount = 0;
+ my $lockcount = 0;
+ my $unlockcount = 0;
+ if ($usercount) {
+ $r->print($output);
+ } else {
+ if ($mode eq 'autoenroll') {
+ return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
+ } else {
+ return;
+ }
+ }
+ #
+ # Sort the users
my $index = $index{$sortby};
my $second = $index{'username'};
my $third = $index{'domain'};
- my @Sorted_Students = sort {
- lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
+ my @sorted_users = sort {
+ lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
||
- lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second]) ||
- lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
- } (keys(%$classlist));
- my $studentcount = 0;
- my $autocount = 0;
- my $manualcount = 0;
- my $unlockcount = 0;
- my $lockcount = 0;
- foreach my $student (@Sorted_Students) {
- my $sdata = $classlist->{$student};
- my $groups = $classgroups->{$student};
- my $username = $sdata->[$index{'username'}];
- my $domain = $sdata->[$index{'domain'}];
- my $section = $sdata->[$index{'section'}];
- my $active_groups;
- if (ref($groups->{active}) eq 'HASH') {
- $active_groups = join(', ',keys(%{$groups->{'active'}}));
+ lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+ lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+ } (keys(%$userlist));
+ my $rowcount = 0;
+ foreach my $user (@sorted_users) {
+ my %in;
+ my $sdata = $userlist->{$user};
+ $rowcount ++;
+ foreach my $item (@{$keylist}) {
+ $in{$item} = $sdata->[$index{$item}];
+ }
+ my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
+ if ($clickers!~/\w/) { $clickers='-'; }
+ $in{'clicker'} = $clickers;
+ my $role = $in{'role'};
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
+ if (! defined($in{'start'}) || $in{'start'} == 0) {
+ $in{'start'} = &mt('none');
+ } else {
+ $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
}
- my $name = $sdata->[$index{'fullname'}];
- my $id = $sdata->[$index{'id'}];
- my $status = $sdata->[$index{'status'}];
- next if (($statusmode ne 'Any') && ($status ne $statusmode));
- my $start = $sdata->[$index{'start'}];
- my $end = $sdata->[$index{'end'}];
- if (! defined($start) || $start == 0) {
- $start = &mt('none');
+ if (! defined($in{'end'}) || $in{'end'} == 0) {
+ $in{'end'} = &mt('none');
} else {
- $start = &Apache::lonlocal::locallocaltime($start);
+ $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
}
- if (! defined($end) || $end == 0) {
- $end = &mt('none');
+ if ($context eq 'course') {
+ if ($custommenu) {
+ my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
+ if ($lastlogin ne '') {
+ my $sincelogin = $now - $lastlogin;
+ if ($sincelogin < 86400) {
+ $in{'lastlogin'} = $elapsed{'86400'};
+ } elsif ($sincelogin < 604800) {
+ $in{'lastlogin'} = $elapsed{'604800'};
+ } elsif ($sincelogin < 2592000 ) {
+ $in{'lastlogin'} = $elapsed{'2592000'};
+ } else {
+ $in{'lastlogin'} = $elapsed{'-1'};
+ }
+ }
+ }
+ if ($role eq 'st') {
+ my $numsub = $stusubmissions{$in{'username'}.':'.$in{'domain'}."\0attempts"} +
+ $stusubmissions{$in{'username'}.':'.$in{'domain'}."\0surveysubs"};
+ if (!$numsub) {
+ $in{'submissions'} = 'not attempted';
+ } elsif ($numsub < $numparts) {
+ $in{'submissions'} = 'incomplete ('.$numsub.'/'.$numparts.')';
+ } else {
+ $in{'submissions'} = 'completed';
+ }
+ }
+ }
+ if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
+ $r->print(&Apache::loncommon::start_data_table_row());
+ my $checkval;
+ if ($mode eq 'autoenroll') {
+ my $cellentry;
+ if ($in{'type'} eq 'auto') {
+ $cellentry = ''.&mt('auto').' Change';
+ $autocount ++;
+ } else {
+ $cellentry = '
END
return;
}
-
-
#
# Print out the initial form to get the file containing a list of users
#
sub print_first_users_upload_form {
- my ($r,$context) = @_;
+ my ($r,$context,$noheader,$caller) = @_;
my $str;
- $str = '';
+ $str = '';
$str .= '';
- $str .= '';
- $str .= "
\n";
- $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
- &mt("How do I create a users list from a spreadsheet")).
- " \n";
- $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
- &mt("How do I create a CSV file from a spreadsheet")).
- " \n";
- $str .= &Apache::loncommon::end_page();
+ $str .= '';
+
+ unless ($noheader) {
+ $str .= '
'.&mt('Upload a file containing information about users').'
'."\n";
+ }
+
+ # Excel and CSV Help
+ $str .= '
'
+ .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
+ &mt("How do I create a users list from a spreadsheet"))
+ .'
'."\n"
+ .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ &mt("How do I create a CSV file from a spreadsheet"))
+ .'
';
+
$r->print($str);
return;
}
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -1607,10 +3938,14 @@ sub upfile_drop_add {
$fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
+ if (($env{'form.fullup'} ne 'yes') && ($env{'form.context'} ne 'requestcrs')) {
+ $r->print('');
+ $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
#####################################
- # Drop students #
+ # Display list of students to drop #
#####################################
if ($env{'form.fullup'} eq 'yes') {
- $r->print('
'.&mt('Dropping Students')."
\n");
+ $r->print('
'.&mt('Students to Drop')."
\n");
# Get current classlist
- my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ my $classlist = &Apache::loncoursedata::get_classlist();
if (! defined($classlist)) {
- $r->print(&mt('There are no students currently enrolled.').
- "\n");
- } else {
+ $r->print(''.
+ ''.
+ &mt('There are no students with current/future access to the course.').
+ ''."\n");
+ } elsif (ref($classlist) eq 'HASH') {
# Remove the students we just added from the list of students.
- foreach (@userdata) {
- my %entries=&Apache::loncommon::record_sep($_);
+ foreach my $line (@userdata) {
+ my %entries=&Apache::loncommon::record_sep($line);
unless (($entries{$fields{'username'}} eq '') ||
(!defined($entries{$fields{'username'}}))) {
delete($classlist->{$entries{$fields{'username'}}.
@@ -1906,21 +4563,64 @@ sub upfile_drop_add {
}
}
# Print out list of dropped students.
- &show_drop_list($r,$classlist,$keylist,'nosort');
+ &show_drop_list($r,$classlist,'nosort',$permission);
}
}
} # end of unless
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
+ }
+}
+
+sub print_namespacing_alerts {
+ my ($domain,$alerts,$curr_rules) = @_;
+ my $output;
+ if (ref($alerts) eq 'HASH') {
+ if (keys(%{$alerts}) > 0) {
+ if (ref($alerts->{'username'}) eq 'HASH') {
+ foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
+ my $count;
+ if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
+ $count = keys(%{$alerts->{'username'}{$dom}});
+ }
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($curr_rules->{$dom}) eq 'HASH') {
+ $output .= &Apache::loncommon::instrule_disallow_msg(
+ 'username',$domdesc,$count,'upload');
+ }
+ $output .= &Apache::loncommon::user_rule_formats($dom,
+ $domdesc,$curr_rules->{$dom}{'username'},
+ 'username');
+ }
+ }
+ if (ref($alerts->{'id'}) eq 'HASH') {
+ foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
+ my $count;
+ if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
+ $count = keys(%{$alerts->{'id'}{$dom}});
+ }
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($curr_rules->{$dom}) eq 'HASH') {
+ $output .= &Apache::loncommon::instrule_disallow_msg(
+ 'id',$domdesc,$count,'upload');
+ }
+ $output .= &Apache::loncommon::user_rule_formats($dom,
+ $domdesc,$curr_rules->{$dom}{'id'},'id');
+ }
+ }
+ }
+ }
}
sub user_change_result {
- my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
- $userchg) = @_;
+ my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
+ $username,$userdomain,$userchg) = @_;
my $okresult = 0;
if ($userresult ne 'ok') {
if ($userresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print(' '.
- &mt('[_1]: Unable to add/modify: [_2]',$username,$error));
+ &mt('[_1]: Unable to add/modify: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'user'} ++;
@@ -1930,7 +4630,7 @@ sub user_change_result {
if ($authresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print(' '.
- &mt('[_1]: Unable to modify authentication: [_2]',$username,$error));
+ &mt('[_1]: Unable to modify authentication: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'auth'} ++;
@@ -1940,7 +4640,7 @@ sub user_change_result {
if ($roleresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print(' '.
- &mt('[_1]: Unable to add role: [_2]',$username,$error));
+ &mt('[_1]: Unable to add role: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'role'} ++;
@@ -1948,64 +4648,325 @@ sub user_change_result {
}
if ($okresult) {
$flushc++;
- $userchg->{$username}=1;
+ $userchg->{$username.':'.$userdomain}=1;
$r->print('. ');
if ($flushc>15) {
$r->rflush;
$flushc=0;
}
}
+ if ($idresult) {
+ $r->print($idresult);
+ }
return $flushc;
}
# ========================================================= Menu Phase Two Drop
-sub print_expire_menu {
- my ($r,$context) = @_;
- $r->print("
".&mt("Expire Users' Roles")."
");
- my $cid=$env{'request.course.id'};
- my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+sub print_drop_menu {
+ my ($r,$context,$permission,$crstype) = @_;
+ my $heading;
+ if ($crstype eq 'Community') {
+ $heading = &mt("Drop Members");
+ } else {
+ $heading = &mt("Drop Students");
+ }
+ $r->print('
'.$heading.'
'."\n".
+ ''. &Apache::loncommon::end_page());
return;
}
-
# ================================================================== Phase four
-sub expire_user_list {
- my ($r,$context) = @_;
+sub update_user_list {
+ my ($r,$context,$setting,$choice) = @_;
+ my $now = time;
my $count=0;
- my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
- foreach (@droplist) {
- my ($uname,$udom)=split(/\:/,$_);
- # drop student
- my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
+ my $crstype;
+ if ($context eq 'course') {
+ $crstype = &Apache::loncommon::course_type();
+ }
+ my @changelist;
+ if ($choice eq 'drop') {
+ @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
+ } else {
+ @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
+ }
+ my %result_text = ( ok => { 'revoke' => 'Revoked',
+ 'delete' => 'Deleted',
+ 'reenable' => 'Re-enabled',
+ 'activate' => 'Activated',
+ 'chgdates' => 'Changed Access Dates for',
+ 'chgsec' => 'Changed section for',
+ 'drop' => 'Dropped',
+ },
+ error => {'revoke' => 'revoking',
+ 'delete' => 'deleting',
+ 'reenable' => 're-enabling',
+ 'activate' => 'activating',
+ 'chgdates' => 'changing access dates for',
+ 'chgsec' => 'changing section for',
+ 'drop' => 'dropping',
+ },
+ );
+ my ($startdate,$enddate);
+ if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
+ ($startdate,$enddate) = &get_dates_from_form();
+ }
+ foreach my $item (@changelist) {
+ my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
+ $scopestem);
+ if ($choice eq 'drop') {
+ ($uname,$udom,$sec) = split(/:/,$item,-1);
+ $role = 'st';
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'course') {
+ ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'author') {
+ ($uname,$udom,$role) = split(/\:/,$item,-1);
+ $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
+ } elsif ($context eq 'domain') {
+ if ($setting eq 'domain') {
+ ($role,$uname,$udom) = split(/\:/,$item,-1);
+ $scope = '/'.$env{'request.role.domain'}.'/';
+ } elsif ($setting eq 'author') {
+ ($uname,$udom,$role,$scope) = split(/\:/,$item);
+ } elsif ($setting eq 'course') {
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
+ split(/\:/,$item);
+ $scope = '/'.$cid;
+ $scope =~s/\_/\//g;
+ if ($sec ne '') {
+ $scope .= '/'.$sec;
+ }
+ }
+ }
+ my $plrole = &Apache::lonnet::plaintext($role,$crstype);
+ my $start = $env{'form.'.$item.'_start'};
+ my $end = $env{'form.'.$item.'_end'};
+ if ($choice eq 'drop') {
+ # drop students
+ $end = $now;
+ $type = 'manual';
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } elsif ($choice eq 'revoke') {
+ # revoke or delete user role
+ $end = $now;
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result =
+ &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
+ '','',$context);
+ }
+ } elsif ($choice eq 'delete') {
+ if ($role eq 'st') {
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
+ }
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
+ $start,1,'',$context);
+ } else {
+ #reenable, activate, change access dates or change section
+ if ($choice ne 'chgsec') {
+ $start = $startdate;
+ $end = $enddate;
+ }
+ if ($choice eq 'reenable') {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $now,'','',$context);
+ }
+ } elsif ($choice eq 'activate') {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $now,'','',$context);
+ }
+ } elsif ($choice eq 'chgdates') {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $start,'','',$context);
+ }
+ } elsif ($choice eq 'chgsec') {
+ my (@newsecs,$revresult,$nochg,@retained);
+ if (($role ne 'cc') && ($role ne 'co')) {
+ @newsecs = split(/,/,$env{'form.newsecs'});
+ }
+ # remove existing section if not to be retained.
+ if (!$env{'form.retainsec'}) {
+ if ($sec eq '') {
+ if (@newsecs == 0) {
+ $result = &mt('No change in section assignment (none)');
+ $nochg = 1;
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ } else {
+ if (@newsecs > 0) {
+ if (grep(/^\Q$sec\E$/,@newsecs)) {
+ push(@retained,$sec);
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ }
+ } else {
+ if ($sec eq '') {
+ $nochg = 1;
+ } else {
+ push(@retained,$sec);
+ }
+ }
+ # add new sections
+ if (@newsecs == 0) {
+ if (!$nochg) {
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ my $newscope = $scopestem;
+ $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
+ }
+ }
+ } else {
+ foreach my $newsec (@newsecs) {
+ if (!grep(/^\Q$newsec\E$/,@retained)) {
+ if ($role eq 'st') {
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
+ } else {
+ my $newscope = $scopestem;
+ if ($newsec ne '') {
+ $newscope .= '/'.$newsec;
+ }
+ $result = &Apache::lonnet::assignrole($udom,$uname,
+ $newscope,$role,$end,$start);
+ }
+ }
+ }
+ }
+ }
+ }
+ my $extent = $scope;
+ if ($choice eq 'drop' || $context eq 'course') {
+ my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
+ if ($cdesc) {
+ $extent = $cdesc;
+ }
+ }
if ($result eq 'ok' || $result eq 'ok:') {
- $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).' ');
+ $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
+ $plrole,$extent,$uname.':'.$udom).' ');
$count++;
} else {
$r->print(
- &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
- ' ');
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
+ $plrole,$extent,$uname.':'.$udom,$result).' ');
+ }
+ }
+ $r->print(''."\n");
}
-sub section_check_js {
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
+sub classlist_drop {
+ my ($scope,$uname,$udom,$now) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my %user;
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
+ return &mt('Drop from classlist: [_1]',
+ ''.$result.'').' ';
+ }
}
+}
+
+sub active_student_roles {
+ my ($cnum,$cdom,$uname,$udom) = @_;
+ my %roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+ ['future','active'],['st']);
+ return exists($roles{"$cnum:$cdom:st"});
+}
+
+sub section_check_js {
+ my $groupslist= &get_groupslist();
return <<"END";
function validate(caller) {
- var groups = new Array("$groupslist");
+ var groups = new Array($groupslist);
var secname = caller.value;
if ((secname == 'all') || (secname == 'none')) {
alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
@@ -2052,5 +5013,731 @@ sub set_login {
return $response;
}
+sub course_sections {
+ my ($sections_count,$role,$current_sec) = @_;
+ my $output = '';
+ my @sections = (sort {$a <=> $b} keys %{$sections_count});
+ my $numsec = scalar(@sections);
+ my $is_selected = ' selected="selected"';
+ if ($numsec <= 1) {
+ $output = ''."\n".
+ ' '."\n";
+ if ($current_sec eq 'none') {
+ $output .=
+ ' '."\n";
+ } else {
+ $output .=
+ ' '."\n";
+ }
+ if ($numsec == 1) {
+ if ($current_sec eq $sections[0]) {
+ $output .=
+ ' '."\n";
+ } else {
+ $output .=
+ ' '."\n";
+ }
+ }
+ } else {
+ $output = ''.&mt('Select').''."\n";
+ if ($current_sec eq 'none') {
+ $output .=
+ ' \n";
+ } else {
+ $output .=
+ ' \n";
+ }
+ } else {
+ $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
+ }
+ foreach my $sec (@sections) {
+ if ($current_sec eq $sec) {
+ $output .= '\n";
+ } else {
+ $output .= '\n";
+ }
+ }
+ }
+ $output .= '';
+ return $output;
+}
+
+sub get_groupslist {
+ my $groupslist;
+ my %curr_groups = &Apache::longroup::coursegroups();
+ if (%curr_groups) {
+ $groupslist = join('","',sort(keys(%curr_groups)));
+ $groupslist = '"'.$groupslist.'"';
+ }
+ return $groupslist;
+}
+
+sub setsections_javascript {
+ my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
+ my ($checkincluded,$finish,$rolecode,$setsection_js);
+ if ($mode eq 'upload') {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ $finish = "return 'ok';";
+ $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n";
+ } elsif ($formname eq 'cu') {
+ $checkincluded = 'formname.elements[i-1].checked == true';
+ if ($checkauth) {
+ $finish = "var authcheck = auth_check();\n".
+ " if (authcheck == 'ok') {\n".
+ " formname.submit();\n".
+ " }\n";
+ } else {
+ $finish = 'formname.submit()';
+ }
+ $rolecode = "var match = str.split('_');
+ var role = match[3];\n";
+ } elsif ($formname eq 'enrollstudent') {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ if ($checkauth) {
+ $finish = "var authcheck = auth_check();\n".
+ " if (authcheck == 'ok') {\n".
+ " formname.submit();\n".
+ " }\n";
+ } else {
+ $finish = 'formname.submit()';
+ }
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
+ } else {
+ $checkincluded = 'formname.name == "'.$formname.'"';
+ $finish = "seccheck = 'ok';";
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
+ $setsection_js = "var seccheck = 'alert';";
+ }
+ my %alerts = &Apache::lonlocal::texthash(
+ secd => 'Section designations do not apply to Course Coordinator roles.',
+ sedn => 'Section designations do not apply to Coordinator roles.',
+ accr => 'A course coordinator role will be added with access to all sections.',
+ acor => 'A coordinator role will be added with access to all sections',
+ inea => 'In each course, each user may only have one student role at a time.',
+ inec => 'In each community, each user may only have on member role at a time.',
+ youh => 'You had selected ',
+ secs => 'sections.',
+ plmo => 'Please modify your selections so they include no more than one section.',
+ mayn => 'may not be used as the name for a section, as it is a reserved word.',
+ plch => 'Please choose a different section name.',
+ mnot => 'may not be used as a section name, as it is the name of a course group.',
+ secn => 'Section names and group names must be distinct. Please choose a different section name.',
+ );
+ $setsection_js .= <<"ENDSECCODE";
+
+function setSections(formname,crstype) {
+ var re1 = /^currsec_/;
+ var groups = new Array($groupslist);
+ for (var i=0;i 0) {
+ if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
+ sections = sections + "," + formname.elements[i+1].value;
+ }
+ }
+ else {
+ sections = formname.elements[i+1].value;
+ }
+ var newsecs = formname.elements[i+1].value;
+ var numsplit;
+ if (newsecs != null && newsecs != "") {
+ numsplit = newsecs.split(/,/g);
+ numsec = numsec + numsplit.length;
+ }
+
+ if ((role == 'st') && (numsec > 1)) {
+ if (crstype == 'Community') {
+ alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+ } else {
+ alert("$alerts{'inec'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+ }
+ return;
+ }
+ else {
+ if (numsplit != null) {
+ for (var j=0; j 'In each course, each user may only have one student role at a time.',
+ youh => 'You had selected ',
+ secs => 'sections.',
+ plmo => 'Please modify your selections so they include no more than one section.',
+ mayn => 'may not be used as the name for a section, as it is a reserved word.',
+ plch => 'Please choose a different section name.',
+ );
+ my $setsection_js = <<"ENDSECCODE";
+
+function setSections(formname) {
+ var newsecs = formname.newsec.value;
+ var numsplit = 0;
+ var numsec = 0;
+ if (newsecs != null && newsecs != "") {
+ numsplit = newsecs.split(/,/g);
+ numsec = numsplit.length;
+ }
+ if (numsec > 1) {
+ alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+ } else {
+ if (numsplit > 0) {
+ for (var j=0; j 0) {
+ my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
+ if (keys(%rule_check) > 0) {
+ $usertype = 'unofficial';
+ foreach my $item (keys(%rule_check)) {
+ if ($rule_check{$item}) {
+ $usertype = 'official';
+ last;
+ }
+ }
+ }
+ }
+ }
+ return $usertype;
+}
+
+sub roles_by_context {
+ my ($context,$custom,$crstype) = @_;
+ my @allroles;
+ if ($context eq 'course') {
+ @allroles = ('st');
+ if ($env{'request.role'} =~ m{^dc\./}) {
+ push(@allroles,'ad');
+ }
+ if (&Apache::loncommon::needs_gci_custom()) {
+ if ($crstype eq 'Community') {
+ push(@allroles,'co');
+ } else {
+ push(@allroles,'cc');
+ }
+ } else {
+ push(@allroles,('ta','ep','in'));
+ if ($crstype eq 'Community') {
+ push(@allroles,'co');
+ } else {
+ push(@allroles,'cc');
+ }
+ if ($custom) {
+ push(@allroles,'cr');
+ }
+ }
+ } elsif ($context eq 'author') {
+ @allroles = ('ca','aa');
+ } elsif ($context eq 'domain') {
+ @allroles = ('li','ad','dg','sc','au','dc');
+ }
+ return @allroles;
+}
+
+sub get_permission {
+ my ($context,$crstype) = @_;
+ my %permission;
+ if ($context eq 'course') {
+ my $custom = 1;
+ my @allroles = &roles_by_context($context,$custom,$crstype);
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
+ $permission{'cusr'} = 1;
+ last;
+ }
+ }
+ if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
+ $permission{'custom'} = 1;
+ }
+ if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
+ $permission{'view'} = 1;
+ }
+ if (!$permission{'view'}) {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
+ if ($permission{'view'}) {
+ $permission{'view_section'} = $env{'request.course.sec'};
+ }
+ }
+ if (!$permission{'cusr'}) {
+ if ($env{'request.course.sec'} ne '') {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
+ if ($permission{'cusr'}) {
+ $permission{'cusr_section'} = $env{'request.course.sec'};
+ }
+ }
+ }
+ if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
+ $permission{'grp_manage'} = 1;
+ }
+ } elsif ($context eq 'author') {
+ $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
+ $permission{'view'} = $permission{'cusr'};
+ } else {
+ my @allroles = &roles_by_context($context);
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
+ $permission{'cusr'} = 1;
+ last;
+ }
+ }
+ if (!$permission{'cusr'}) {
+ if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
+ $permission{'cusr'} = 1;
+ }
+ }
+ if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
+ $permission{'custom'} = 1;
+ }
+ $permission{'view'} = $permission{'cusr'};
+ }
+ my $allowed = 0;
+ foreach my $perm (values(%permission)) {
+ if ($perm) { $allowed=1; last; }
+ }
+ return (\%permission,$allowed);
+}
+
+# ==================================================== Figure out author access
+
+sub authorpriv {
+ my ($auname,$audom)=@_;
+ unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
+ || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1;
+}
+
+sub roles_on_upload {
+ my ($context,$setting,$crstype,%customroles) = @_;
+ my (@possible_roles,@permitted_roles);
+ @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
+ foreach my $role (@possible_roles) {
+ if ($role eq 'cr') {
+ push(@permitted_roles,keys(%customroles));
+ } else {
+ push(@permitted_roles,$role);
+ }
+ }
+ return @permitted_roles;
+}
+
+sub get_course_identity {
+ my ($cid) = @_;
+ my ($cnum,$cdom,$cdesc);
+ if ($cid eq '') {
+ $cid = $env{'request.course.id'}
+ }
+ if ($cid ne '') {
+ $cnum = $env{'course.'.$cid.'.num'};
+ $cdom = $env{'course.'.$cid.'.domain'};
+ $cdesc = $env{'course.'.$cid.'.description'};
+ if ($cnum eq '' || $cdom eq '') {
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
+ $cdom = $coursehash{'domain'};
+ $cnum = $coursehash{'num'};
+ $cdesc = $coursehash{'description'};
+ }
+ }
+ return ($cnum,$cdom,$cdesc);
+}
+
+sub dc_setcourse_js {
+ my ($formname,$mode,$context) = @_;
+ my ($dc_setcourse_code,$authen_check);
+ my $cctext = &Apache::lonnet::plaintext('cc');
+ my $cotext = &Apache::lonnet::plaintext('co');
+ my %alerts = §ioncheck_alerts();
+ my $role = 'role';
+ if ($mode eq 'upload') {
+ $role = 'courserole';
+ } else {
+ $authen_check = &verify_authen($formname,$context);
+ }
+ $dc_setcourse_code = (<<"SCRIPTTOP");
+$authen_check
+
+function setCourse() {
+ var course = document.$formname.dccourse.value;
+ if (course != "") {
+ if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
+ alert("$alerts{'curd'}");
+ return;
+ }
+ var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
+ var section="";
+ var numsections = 0;
+ var newsecs = new Array();
+ for (var i=0; i 1)) {
+ if (document.$formname.crstype.value == 'Community') {
+ alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ } else {
+ alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ }
+ return;
+ }
+ for (var j=0; j 0)) {
+ alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
+ section = "";
+ }
+ if ((userrole == 'co') && (numsections > 0)) {
+ alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
+ section = "";
+ }
+SCRIPTTOP
+ if ($mode ne 'upload') {
+ $dc_setcourse_code .= (<<"ENDSCRIPT");
+ var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
+ var numcourse = getIndex(document.$formname.dccourse);
+ if (numcourse == "-1") {
+ if (document.$formname.type == 'Community') {
+ alert("$alerts{'thwc'}");
+ } else {
+ alert("$alerts{'thwa'}");
+ }
+ return;
+ }
+ else {
+ document.$formname.elements[numcourse].name = "act"+coursename;
+ var numnewsec = getIndex(document.$formname.newsec);
+ if (numnewsec != "-1") {
+ document.$formname.elements[numnewsec].name = "sec"+coursename;
+ document.$formname.elements[numnewsec].value = section;
+ }
+ var numstart = getIndex(document.$formname.start);
+ if (numstart != "-1") {
+ document.$formname.elements[numstart].name = "start"+coursename;
+ }
+ var numend = getIndex(document.$formname.end);
+ if (numend != "-1") {
+ document.$formname.elements[numend].name = "end"+coursename
+ }
+ }
+ }
+ var authcheck = auth_check();
+ if (authcheck == 'ok') {
+ document.$formname.submit();
+ }
+}
+ENDSCRIPT
+ } else {
+ $dc_setcourse_code .= "
+ document.$formname.sections.value = section;
+ }
+ return 'ok';
+}
+";
+ }
+ $dc_setcourse_code .= (<<"ENDSCRIPT");
+
+ function getIndex(caller) {
+ for (var i=0;i 0) {
+ var loginpicked = 0;
+ for (var i=0; i 'You must select a course or community in the current domain',
+ inea => 'In each course, each user may only have one student role at a time',
+ inco => 'In each community, each user may only have one member role at a time',
+ youh => 'You had selected',
+ sect => 'sections',
+ plsm => 'Please modify your selections so they include no more than one section',
+ mayn => 'may not be used as the name for a section, as it is a reserved word',
+ plsc => 'Please choose a different section name',
+ mayt => 'may not be used as the name for a section, as it is the name of a course group',
+ mayc => 'may not be used as the name for a section, as it is the name of a community group',
+ secn => 'Section names and group names must be distinct',
+ secd => 'Section designations do not apply to ',
+ role => 'roles',
+ accr => 'role will be added with access to all sections',
+ thwa => 'There was a problem with your course selection',
+ thwc => 'There was a problem with your community selection',
+ );
+ return %alerts;
+}
+
+sub authcheck_alerts {
+ my %alerts =
+ &Apache::lonlocal::texthash(
+ authen => 'You must choose an authentication type.',
+ krb => 'You need to specify the Kerberos domain.',
+ ipass => 'You need to specify the initial password.',
+ );
+ return %alerts;
+}
+
1;