--- loncom/interface/lonuserutils.pm 2007/12/12 23:59:41 1.15
+++ loncom/interface/lonuserutils.pm 2007/12/22 22:42:58 1.29
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.15 2007/12/12 23:59:41 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,8 +46,7 @@ sub modifystudent {
# 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
@@ -69,7 +68,8 @@ 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);
$result .= $reply.':';
}
}
@@ -127,6 +127,7 @@ sub modifyuserrole {
$email,$role,$start,$end);
if ($userresult eq 'ok') {
if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
$role,$end,$start);
}
@@ -146,7 +147,7 @@ sub propagate_id_change {
one_time => 1,
);
foreach my $item (keys(%roleshash)) {
- my ($cnum,$cdom,$role) = split(/:/,$item);
+ 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);
@@ -236,8 +237,8 @@ sub domain_roles_select {
} elsif ($roletype eq 'author') {
@roles = &construction_space_roles();
} else {
- @roles = &course_roles('domain');
- unshift(@roles,'cr');
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom);
}
my $order = ['Any',@roles];
$select_menus{$roletype}->{'order'} = $order;
@@ -266,7 +267,7 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -296,9 +297,14 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
+ my $groupslist;
+ if ($context eq 'course') {
+ $groupslist = &get_groupslist();
+ }
my $javascript_validations =
- &javascript_validations('auth',$krbdefdom,$password_choice,undef,
- $env{'request.role.domain'});
+ &javascript_validations('upload',$krbdefdom,$password_choice,undef,
+ $env{'request.role.domain'},$context,
+ $permission,$groupslist);
my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
$r->print(&mt('Total number of records found in file: [_1].',$distotal).
"
\n");
@@ -325,27 +331,52 @@ sub print_upload_manager_header {
###############################################################
###############################################################
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,$permission,$groupslist)=@_;
+
+ 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 'createuser') {
+ $param{'formname'} = 'cu';
+ } elsif ($mode eq 'upload') {
+ $param{'formname'} = 'studentform';
+ } elsif ($mode eq 'singlestudent') {
+ $param{'formname'} = 'cu';
+ } 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'}.');';
+ $setsections_js =
+ &setsections_javascript($param{'formname'},$groupslist,
+ $mode);
+ } else {
+ $setsection_call = "'ok'";
+ }
+ } elsif ($context eq 'domain') {
+ $setsection_call = 'setCourse()';
+ $setsections_js = &dc_setcourse_js($param{'formname'},$mode);
+ }
+ $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.',
@@ -359,8 +390,9 @@ sub javascript_validations {
continue => 'Continue adding users?',
);
-# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $function_name =(<'.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without one specified in the uploaded file');
+ &mt('Choose the role to assign to users without a value 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');
+ &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
} else {
- $Str .= '
'.&mt('Default role and/or section')."
\n".
- &mt('Role and/or section for users without one in the uploaded file.');
+ $Str .= '
'.&mt('Default role and/or section(s)')."
\n".
+ &mt('Role and/or section(s) for users without values specified in the uploaded file.');
}
- $Str .= '
';
- my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
- if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').'
'.$options.'
'.&mt('Course Level').'
'.$cb_script.$coursepick;
- } elsif ($context eq 'author') {
- $Str .= $options;
+ $Str .= '
';
+ if (($context eq 'domain') || ($context eq 'author')) {
+ my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
+ if ($context eq 'domain') {
+ $Str .= ''.&mt('Domain Level').'
'.$options.'
'.&mt('Course Level').'
'.$cb_script.$coursepick;
+ } elsif ($context eq 'author') {
+ $Str .= $options;
+ }
} else {
- $Str .= '
';
- }
- if ($context eq 'course') {
- $Str .= "'.&mt('role').': '.
- $options.' '.
- ''.&mt('section').': ".&mt('Full Update')."
\n".
- ''."\n";
}
+ $output .= '';
return $output;
}
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -816,7 +844,8 @@ sub print_upload_manager_form {
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
#
- &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context);
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
+ $permission);
my $i;
my $keyfields;
if ($total>=0) {
@@ -850,11 +879,14 @@ sub print_upload_manager_form {
}
$r->print('
'."\n";
}
@@ -962,20 +997,19 @@ sub make_dates_default {
my ($startdate,$enddate,$context) = @_;
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 .= &mt('Set default start and end dates for course').
+ $result .= &mt('Set default start and end access dates for course.').
'
'."\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.
+ $result .= &mt('Unable to set default access dates for course.').":".$put_result.
'
';
}
}
@@ -1013,33 +1047,36 @@ sub default_role_selector {
$options .= ' ';
}
my $courseform = &Apache::loncommon::selectcourse_link
- ('studentform','defaultcourse','defaultdomain','defaultdesc',"$env{'request.role.domain'}",undef,'Course');
+ ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
$cb_jscript =
- &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'defaultsec','studentform');
+ &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
$coursepick = &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
''.$courseform.' '.$lt{'rol'}.' '.
''.$lt{'grs'}.' '.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row()."\n".
- ''."\n".
+ ' '."\n".
' '.
' '.
+ ''.
+ ''.
+ ''.
+ ''.
+ ''.
+ ''.
&Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table()."\n".
- ''.
- '';
+ &Apache::loncommon::end_data_table()."\n";
}
$options .= '';
return ($options,$cb_jscript,$coursepick);
@@ -1048,17 +1085,21 @@ sub default_role_selector {
sub default_course_roles {
my ($context,$checkpriv,%customroles) = @_;
my $output;
- my @roles = &course_roles($context,$checkpriv);
+ my $custom = 1;
+ my @roles = &course_roles($context,$checkpriv,$custom);
foreach my $role (@roles) {
- my $plrole=&Apache::lonnet::plaintext($role);
- $output .= ' ';
+ if ($role ne 'cr') {
+ my $plrole=&Apache::lonnet::plaintext($role);
+ $output .= ' ';
+ }
}
if (keys(%customroles) > 0) {
- my %customroles = &my_custom_roles();
- foreach my $cust (sort(keys(%customroles))) {
- my $custrole='cr_cr_'.$env{'user.domain'}.
- '_'.$env{'user.name'}.'_'.$cust;
- $output .= ' ';
+ if (grep(/^cr$/,@roles)) {
+ foreach my $cust (sort(keys(%customroles))) {
+ my $custrole='cr_'.$env{'user.domain'}.
+ '_'.$env{'user.name'}.'_'.$cust;
+ $output .= ' ';
+ }
}
}
return $output;
@@ -1066,7 +1107,7 @@ sub default_course_roles {
sub construction_space_roles {
my ($checkpriv) = @_;
- my @allroles = ('ca','aa');
+ my @allroles = &roles_by_context('author');
my @roles;
if ($checkpriv) {
foreach my $role (@allroles) {
@@ -1082,7 +1123,7 @@ sub construction_space_roles {
sub domain_roles {
my ($checkpriv) = @_;
- my @allroles = ('dc','li','dg','au','sc');
+ my @allroles = &roles_by_context('domain');
my @roles;
if ($checkpriv) {
foreach my $role (@allroles) {
@@ -1097,8 +1138,8 @@ sub domain_roles {
}
sub course_roles {
- my ($context,$checkpriv) = @_;
- my @allroles = ('st','ta','ep','in','cc');
+ my ($context,$checkpriv,$custom) = @_;
+ my @allroles = &roles_by_context('course',$custom);
my @roles;
if ($context eq 'domain') {
@roles = @allroles;
@@ -1109,10 +1150,10 @@ sub course_roles {
if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
push(@roles,$role);
} else {
- if ($role ne 'cc' && $env{'request.course.section'} ne '') {
- if (!&Apache::lonnet::allowed('c'.$role,
+ if ($role ne 'cc' && $env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$role,
$env{'request.course.id'}.'/'.
- $env{'request.course.section'})) {
+ $env{'request.course.sec'})) {
push(@roles,$role);
}
}
@@ -1128,17 +1169,18 @@ sub course_roles {
sub curr_role_permissions {
my ($context,$setting,$checkpriv) = @_;
+ my $custom = 1;
my @roles;
if ($context eq 'author') {
@roles = &construction_space_roles($checkpriv);
} elsif ($context eq 'domain') {
if ($setting eq 'course') {
- @roles = &course_roles($context,$checkpriv);
+ @roles = &course_roles($context,$checkpriv,$custom);
} else {
@roles = &domain_roles($checkpriv);
}
} elsif ($context eq 'course') {
- @roles = &course_roles($context,$checkpriv);
+ @roles = &course_roles($context,$checkpriv,$custom);
}
return @roles;
}
@@ -1236,19 +1278,20 @@ sub print_userlist {
if ($role eq $env{'form.showrole'}) {
$roleselected = ' selected="selected" ';
}
- my $plrole=&Apache::lonnet::plaintext($role);
+ my $plrole;
+ if ($role eq 'cr') {
+ $plrole = &mt('Custom role');
+ } else {
+ $plrole=&Apache::lonnet::plaintext($role);
+ }
$role_select .= '';
}
- $roleselected = '';
- if ($env{'form.showrole'} eq 'cr') {
- $roleselected = ' selected="selected" ';
- }
- $role_select .= ''.
- '';
+ $role_select .= '';
$r->print(''.
'
'.
- $lt{'exs'}.' '.
' '.
''.$lt{'new'}.' '.
- '
'.
''.
- '
';
- my @linkdests = ('aboutme');
- if ($permission->{'cusr'}) {
- push (@linkdests,'modify');
- $output .= ''.$lt{'link'}.': ';
- my $usernamelink = $env{'form.usernamelink'};
- if ($usernamelink eq '') {
- $usernamelink = 'aboutme';
- }
- foreach my $item (@linkdests) {
- my $checkedstr = '';
- if ($item eq $usernamelink) {
- $checkedstr = ' checked="checked" ';
- }
- $output .= '
';
- } else {
- $output .= &mt("Click on a username to view the user's personal page.").'
';
- }
- if ($actionselect) {
- $output .= <<"END";
+ $output = '
';
+ my @linkdests = ('aboutme');
+ if ($permission->{'cusr'}) {
+ push (@linkdests,'modify');
+ $output .= ''.$lt{'link'}.': ';
+ my $usernamelink = $env{'form.usernamelink'};
+ if ($usernamelink eq '') {
+ $usernamelink = 'aboutme';
+ }
+ foreach my $item (@linkdests) {
+ my $checkedstr = '';
+ if ($item eq $usernamelink) {
+ $checkedstr = ' checked="checked" ';
+ }
+ $output .= '
';
+ } else {
+ $output .= &mt("Click on a username to view the user's personal page.").'
';
+ }
+ if ($actionselect) {
+ $output .= <<"END";
$lt{'ac'}: $actionselect
END - } + my @allroles; + if ($env{'form.showrole'} eq 'Any') { + my $custom = 1; + if ($context eq 'domain') { + @allroles = &roles_by_context($setting,$custom); + } else { + @allroles = &roles_by_context($context,$custom); + } + } else { + @allroles = ($env{'form.showrole'}); + } + foreach my $role (@allroles) { + if ($context eq 'domain') { + if ($setting eq 'domain') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } + } elsif ($context eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'user.domain'}.'/'.$env{'user.name'})) { + $canchange{$role} = 1; + } + } elsif ($context eq 'course') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) { + $canchange{$role} = 1; + } elsif ($env{'request.course.sec'} ne '') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + $canchangesec{$role} = $env{'request.course.sec'}; + } + } + } + } + } } $output .= "\n
\n". &Apache::loncommon::start_data_table(). @@ -1980,7 +2082,7 @@ END $output .= "
'.&mt('manual').' | |
'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'
'); + $r->print(''.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'
'); if ($count > 0) { - if ($choice eq 'revoke') { + if ($choice eq 'revoke' || $choice eq 'drop') { $r->print(''.&mt('Re-enabling will re-activate data for the role.
')); } # Flush the course logs so reverse user roles immediately updated @@ -3479,23 +3886,20 @@ sub update_user_list { } if ($env{'form.makedatesdefault'}) { if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') { - $r->print(&make_dates_default($startdate,$enddate)); + $r->print(&make_dates_default($startdate,$enddate,$context)); } } } sub classlist_drop { - my ($scope,$uname,$udom,$now,$action) = @_; + my ($scope,$uname,$udom,$now) = @_; my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)}); - my $cid=$cdom.'_'.$cnum; - my $user = $uname.':'.$udom; - if ($action eq 'drop') { + if (&Apache::lonnet::is_course($cdom,$cnum)) { + my $user = $uname.':'.$udom; if (!&active_student_roles($cnum,$cdom,$uname,$udom)) { my $result = &Apache::lonnet::cput('classlist', - { $user => $now }, - $env{'course.'.$cid.'.domain'}, - $env{'course.'.$cid.'.num'}); + { $user => $now },$cdom,$cnum); return &mt('Drop from classlist: [_1]', ''.$result.'').'