--- loncom/interface/lonuserutils.pm 2007/12/21 14:05:40 1.18
+++ loncom/interface/lonuserutils.pm 2007/12/22 00:47:25 1.23
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.18 2007/12/21 14:05:40 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.23 2007/12/22 00:47:25 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -68,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.':';
}
}
@@ -126,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);
}
@@ -145,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);
@@ -265,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'})) {
@@ -295,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");
@@ -324,26 +331,51 @@ 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.',
@@ -358,8 +390,9 @@ sub javascript_validations {
continue => 'Continue adding users?',
);
-# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $function_name =(<
'.&mt('Default role and/or section')."
\n".
&mt('Role and/or section for users without one 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";
}
@@ -1011,33 +1046,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);
@@ -1049,15 +1087,18 @@ sub default_course_roles {
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;
@@ -1108,10 +1149,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);
}
}
@@ -1236,15 +1277,15 @@ 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'}.' '.
- '
'.
''.
- '
';
$space = ', ';
}
@@ -1754,10 +1804,10 @@ sub show_users_list {
if (!grep(/^\Q$sortby\E$/,@sortable)) {
$sortby = 'username';
}
- my $setting = $env{'form.roleaction'};
+ my $setting = $env{'form.roletype'};
my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
if ($context eq 'course') {
- $cid=$env{'request.course.id'};
+ $cid = $env{'request.course.id'};
($cnum,$cdom) = &get_course_identity($cid);
($classgroups) = &Apache::loncoursedata::get_group_memberships(
$userlist,$keylist,$cdom,$cnum);
@@ -2318,6 +2368,10 @@ sub select_actions {
chgsec => "Change section associated with user roles",
);
my ($output,$options,%choices);
+ # FIXME Disable actions for now for roletype=course in domain context
+ if ($context eq 'domain' && $setting eq 'course') {
+ return;
+ }
if ($statusmode eq 'Any') {
$options .= '
';
@@ -2423,7 +2477,7 @@ ENDTWO
}
sub date_section_selector {
- my ($context) = @_;
+ my ($context,$permission) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
@@ -2502,7 +2556,8 @@ END
$starttime = time;
}
$date_items = &date_setting_table($starttime,undef,$context,
- $env{'form.bulkaction'});
+ $env{'form.bulkaction'},$formname,
+ $permission);
}
$output .= ''.$headertext.'
'.
'
'.
@@ -2693,6 +2739,20 @@ sub results_header_row {
}
return $description;
}
+
+sub viewable_section {
+ my ($permission) = @_;
+ my $viewablesec;
+ if (ref($permission) eq 'HASH') {
+ if (exists($permission->{'view_section'})) {
+ $viewablesec = $permission->{'view_section'};
+ } elsif (exists($permission->{'cusr_section'})) {
+ $viewablesec = $permission->{'cusr_section'};
+ }
+ }
+ return $viewablesec;
+}
+
#################################################
#################################################
@@ -2883,7 +2943,7 @@ sub print_first_users_upload_form {
# ================================================= 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);}
@@ -3810,6 +3870,61 @@ sub can_create_user {
return $cancreate;
}
+sub can_modify_userinfo {
+ my ($context,$dom,$fields,$userroles) = @_;
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['usermodification'],
+ $dom);
+ my %canmodify;
+ if (ref($fields) eq 'ARRAY') {
+ foreach my $field (@{$fields}) {
+ $canmodify{$field} = 0;
+ if (&Apache::lonnet::allowed('mau',$dom)) {
+ $canmodify{$field} = 1;
+ } else {
+ if (ref($domconfig{'usermodification'}) eq 'HASH') {
+ if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
+ if (ref($userroles) eq 'ARRAY') {
+ foreach my $role (@{$userroles}) {
+ my $testrole;
+ if ($role =~ /^cr\//) {
+ $testrole = 'cr';
+ } else {
+ $testrole = $role;
+ }
+ if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
+ if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
+ $canmodify{$field} = 1;
+ last;
+ }
+ }
+ }
+ } else {
+ foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
+ if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
+ if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
+ $canmodify{$field} = 1;
+ last;
+ }
+ }
+ }
+ }
+ }
+ } elsif ($context eq 'course') {
+ if (ref($userroles) eq 'ARRAY') {
+ if (grep(/^st$/,@{$userroles})) {
+ $canmodify{$field} = 1;
+ }
+ } else {
+ $canmodify{$field} = 1;
+ }
+ }
+ }
+ }
+ }
+ return %canmodify;
+}
+
sub check_usertype {
my ($dom,$uname,$rules) = @_;
my $usertype;
@@ -3940,6 +4055,143 @@ sub get_course_identity {
return ($cnum,$cdom,$cdesc);
}
+sub dc_setcourse_js {
+ my ($formname,$mode) = @_;
+ my $dc_setcourse_code;
+ my $cctext = &Apache::lonnet::plaintext('cc');
+ my %alerts = §ioncheck_alerts();
+ my $role = 'role';
+ if ($mode eq 'upload') {
+ $role = 'courserole';
+ }
+ $dc_setcourse_code = (<<"SCRIPTTOP");
+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