'.&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').
+ &mt('Note: This will not take effect if the user already exists.').
&Apache::loncommon::help_open_topic('Auth_Options').
"
\n";
@@ -712,42 +769,45 @@ sub print_upload_manager_footer {
}
if ($context eq 'author') {
$Str .= '
'.&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.'
';
+ $Str .= '';
$r->print($Str);
return;
}
@@ -755,24 +815,25 @@ sub print_upload_manager_footer {
sub forceid_change {
my ($context) = @_;
my $output =
- "
".&mt('ID/Student Number')."
\n".
+ "
".&mt('Student/Employee ID')."
\n".
"
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')." \n";
+ &mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs').
+ ' '."\n".
+ &mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
- $output .= '
'."\n";
+ &mt('Update Student/Employee ID in courses in which user is active/future student,[_1](if forcing change).',' ').
+ ''."\n";
}
+ $output .= '';
return $output;
}
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -802,6 +863,7 @@ sub print_upload_manager_form {
'ipwd_choice' => 'scalar',
'email_choice' => 'scalar',
'role_choice' => 'scalar',
+ 'domain_choice' => 'scalar',
};
my $defdom = $env{'request.role.domain'};
if ($context eq 'course') {
@@ -816,7 +878,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) {
@@ -827,11 +890,12 @@ sub print_upload_manager_form {
['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'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -850,11 +914,14 @@ sub print_upload_manager_form {
}
$r->print('
');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context);
+ $context,$permission);
}
sub setup_date_selectors {
- my ($starttime,$endtime,$mode,$nolink) = @_;
+ 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') {
@@ -877,11 +944,11 @@ sub setup_date_selectors {
}
my $startdateform =
- &Apache::lonhtmlcommon::date_setter('studentform','startdate',$starttime,
+ &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
undef,undef,undef,undef,undef,undef,undef,$nolink);
my $enddateform =
- &Apache::lonhtmlcommon::date_setter('studentform','enddate',$endtime,
+ &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
undef,undef,undef,undef,undef,undef,undef,$nolink);
if ($mode eq 'create_enrolldates') {
@@ -905,8 +972,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;
}
@@ -914,29 +988,32 @@ sub get_dates_from_form {
}
sub date_setting_table {
- my ($starttime,$endtime,$mode,$bulkaction) = @_;
+ my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_;
my $nolink;
if ($bulkaction) {
$nolink = 1;
}
my ($startform,$endform) =
- &setup_date_selectors($starttime,$endtime,$mode,$nolink);
+ &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
my $dateDefault;
if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
$dateDefault = ' ';
} elsif ($mode ne 'author' && $mode ne 'domain') {
if (($bulkaction eq 'reenable') ||
($bulkaction eq 'activate') ||
- ($bulkaction eq 'chgdates')) {
- $dateDefault = ''.
- '';
+ ($bulkaction eq 'chgdates') ||
+ ($env{'form.action'} eq 'upload')) {
+ if ($env{'request.course.sec'} eq '') {
+ $dateDefault = ''.
+ '';
+ }
}
}
my $perpetual = '';
if ($mode eq 'create_enrolldates') {
@@ -951,7 +1028,7 @@ sub date_setting_table {
'LC_oddrow_value')."\n".
$endform.' '.$perpetual.
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box().' ';
+ &Apache::lonhtmlcommon::end_pick_box();
if ($dateDefault) {
$result .= $dateDefault.' '."\n";
}
@@ -962,20 +1039,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 +1089,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().
'
\n");
+ "\n".''.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n");
if ($env{'form.coursepick'}) {
$r->print(''.&mt('Searching').' ...
');
}
@@ -1273,37 +1343,31 @@ sub print_userlist {
}
$r->rflush();
if ($context eq 'course') {
- my $classlist = &Apache::loncoursedata::get_classlist();
- my $secidx = &Apache::loncoursedata::CL_SECTION();
- foreach my $student (keys(%{$classlist})) {
- if (exists($permission->{'view_section'})) {
- if ($classlist->{$student}[$secidx] ne $permission->{'view_section'}) {
- next;
- } else {
- $userlist{$student} = $classlist->{$student};
- }
- } else {
- $userlist{$student} = $classlist->{$student};
+ if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
+ my $classlist = &Apache::loncoursedata::get_classlist();
+ if (ref($classlist) eq 'HASH') {
+ %userlist = %{$classlist};
}
}
- my $cid =$env{'request.course.id'};
- my $cdom=$env{'course.'.$cid.'.domain'};
- my $cnum=$env{'course.'.$cid.'.num'};
- my $showroles;
- if ($env{'form.showrole'} ne 'Any') {
- $showroles = [$env{'form.showrole'}];
- } else {
- $showroles = undef;
+ if ($env{'form.showrole'} ne 'st') {
+ my $showroles;
+ if ($env{'form.showrole'} ne 'Any') {
+ $showroles = [$env{'form.showrole'}];
+ } else {
+ $showroles = undef;
+ }
+ my $withsec = 1;
+ my $hidepriv = 1;
+ my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
+ \@statuses,$showroles,undef,$withsec,$hidepriv);
+ &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
+ \%advrolehash,$permission);
}
- my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
- \@statuses,$showroles);
- &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
- \%advrolehash,$permission);
} else {
my (%cstr_roles,%dom_roles);
if ($context eq 'author') {
# List co-authors and assistant co-authors
- my @possroles = ('ca','aa');
+ my @possroles = &roles_by_context($context);
%cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
\@statuses,\@possroles);
&gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
@@ -1328,12 +1392,12 @@ sub print_userlist {
} else {
my @possroles;
if ($env{'form.showrole'} eq 'Any') {
- @possroles = ('ca','aa');
+ @possroles = &roles_by_context('author');
} else {
@possroles = ($env{'form.showrole'});
}
foreach my $author (sort(keys(%{$dom_roles{$key}}))) {
- my ($role,$authorname,$authordom) = split(/:/,$author);
+ my ($role,$authorname,$authordom) = split(/:/,$author,-1);
my $extent = '/'.$authordom.'/'.$authorname;
%{$coauthors{$extent}} =
&Apache::lonnet::get_my_roles($authorname,
@@ -1347,19 +1411,16 @@ sub print_userlist {
} elsif ($env{'form.roletype'} eq 'course') {
if ($env{'form.coursepick'}) {
my %courses = &process_coursepick();
- my %allusers;
+ my %allusers;
+ my $hidepriv = 1;
foreach my $cid (keys(%courses)) {
- my %coursehash =
- &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
- my $cdom = $coursehash{'domain'};
- my $cnum = $coursehash{'num'};
+ my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
next if ($cnum eq '' || $cdom eq '');
- my $cdesc = $coursehash{'description'};
+ my $custom = 1;
my (@roles,@sections,%access,%users,%userdata,
%statushash);
if ($env{'form.showrole'} eq 'Any') {
- @roles = &course_roles($context);
- unshift(@roles,'cr');
+ @roles = &course_roles($context,undef,$custom);
} else {
@roles = ($env{'form.showrole'});
}
@@ -1369,7 +1430,7 @@ sub print_userlist {
foreach my $type (@statuses) {
$access{$type} = $type;
}
- &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash);
+ &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
foreach my $user (keys(%userdata)) {
next if (ref($userinfo{$user}) eq 'HASH');
foreach my $item ('fullname','id') {
@@ -1420,13 +1481,111 @@ sub print_userlist {
$permission,$env{'form.Status'},\%userlist,$keylist);
}
if (!$usercount) {
- $r->print(' '.&mt('There are no users matching the search criteria.'));
+ $r->print(' '
+ .&mt('There are no users matching the search criteria.')
+ .''
+ );
}
}
$r->print('');
}
+sub role_filter {
+ my ($context) = @_;
+ my $output;
+ my $roleselected = '';
+ if ($env{'form.showrole'} eq 'Any') {
+ $roleselected = ' selected="selected" ';
+ }
+ my ($role_select);
+ if ($context eq 'domain') {
+ $role_select = &domain_roles_select();
+ $output = '';
+ } else {
+ $role_select = ''."\n".
+ '';
+ my @poss_roles = &curr_role_permissions($context);
+ foreach my $role (@poss_roles) {
+ $roleselected = '';
+ if ($role eq $env{'form.showrole'}) {
+ $roleselected = ' selected="selected" ';
+ }
+ my $plrole;
+ if ($role eq 'cr') {
+ $plrole = &mt('Custom role');
+ } else {
+ $plrole=&Apache::lonnet::plaintext($role);
+ }
+ $role_select .= '';
+ }
+ $role_select .= '';
+ $output = '';
+ }
+ return $output;
+}
+
+sub section_group_filter {
+ my ($cnum,$cdom) = @_;
+ my @filters;
+ if ($env{'request.course.sec'} eq '') {
+ @filters = ('sec');
+ }
+ push(@filters,'grp');
+ my %name = (
+ sec => 'secfilter',
+ grp => 'grpfilter',
+ );
+ my %title = &Apache::lonlocal::texthash (
+ sec => 'Section(s)',
+ grp => 'Group(s)',
+ all => 'all',
+ none => 'none',
+ );
+ my $output;
+ foreach my $item (@filters) {
+ my ($markup,@options);
+ if ($env{'form.'.$name{$item}} eq '') {
+ $env{'form.'.$name{$item}} = 'all';
+ }
+ if ($item eq 'sec') {
+ if ($env{'form.showrole'} eq 'cc') {
+ $env{'form.'.$name{$item}} = 'none';
+ }
+ my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
+ @options = sort(keys(%sections_count));
+ } elsif ($item eq 'grp') {
+ my %curr_groups = &Apache::longroup::coursegroups();
+ @options = sort(keys(%curr_groups));
+ }
+ if (@options > 0) {
+ my $currsel;
+ $markup = ''."\n";
+ foreach my $option ('all','none',@options) {
+ $currsel = '';
+ if ($env{'form.'.$name{$item}} eq $option) {
+ $currsel = ' selected="selected" ';
+ }
+ $markup .= ' '."\n";
+ }
+ $markup .= ''."\n";
+ $output .= (' 'x3).'';
+ }
+ }
+ return $output;
+}
+
sub list_submit_button {
my ($text) = @_;
return '';
@@ -1434,20 +1593,34 @@ sub list_submit_button {
sub gather_userinfo {
my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
+ my $viewablesec;
+ if ($context eq 'course') {
+ $viewablesec = &viewable_section($permission);
+ }
foreach my $item (keys(%{$rolehash})) {
- @{$userlist->{$item}} = ();
my %userdata;
- if ($context eq 'author' || $context eq 'course') {
+ if ($context eq 'author') {
($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
split(/:/,$item);
($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
+ } elsif ($context eq 'course') {
+ ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
+ $userdata{'section'}) = split(/:/,$item,-1);
+ ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
+ if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
+ next if ($viewablesec ne $userdata{'section'});
+ }
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
split(/:/,$item);
($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($env{'form.roletype'} eq 'author') {
if (ref($rolehash->{$item}) eq 'HASH') {
$userdata{'extent'} = $item;
@@ -1456,7 +1629,8 @@ sub gather_userinfo {
($userdata{'start'},$userdata{'end'}) =
split(/:/,$rolehash->{$item}{$key});
my $uniqid = $key.':'.$item;
- &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,
+ $indexhash,$uniqid,$userlist);
}
}
} elsif ($env{'form.roletype'} eq 'course') {
@@ -1471,13 +1645,14 @@ sub gather_userinfo {
my $space = ', ';
if ($format eq 'html' || $format eq 'view') {
$spanstart = '';
- if ($permission->{'cusr'}) {
- if ($numcids > 1) {
- $spanstart .= '';
- } else {
- $spanstart .= '';
- }
- }
+ # FIXME: actions on courses disabled for now
+# if ($permission->{'cusr'}) {
+# if ($numcids > 1) {
+# $spanstart .= ' ';
+# } else {
+# $spanstart .= ' ';
+# }
+# }
$spanend = ' ';
$space = ', ';
}
@@ -1485,13 +1660,20 @@ sub gather_userinfo {
$rolehash->{$item}{$cid}{'desc'}.$space;
if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
- $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
+ if (($env{'form.Status'} eq 'Any') ||
+ ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
+ $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
+ $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
+ }
}
}
}
}
}
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ if ($userdata{'status'} ne '') {
+ &build_user_record($context,\%userdata,$userinfo,
+ $indexhash,$item,$userlist);
+ }
}
}
}
@@ -1499,14 +1681,15 @@ sub gather_userinfo {
}
sub build_user_record {
- my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
+ my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
- &process_date_info($userdata);
+ if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
+ &process_date_info($userdata);
+ }
my $username = $userdata->{'username'};
my $domain = $userdata->{'domain'};
if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
- $userdata->{'fullname'} =
- $userinfo->{$username.':'.$domain}{'fullname'};
+ $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
$userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
} else {
&aggregate_user_info($domain,$username,$userinfo);
@@ -1690,6 +1873,8 @@ sub make_keylist_array {
$index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
$index->{'role'} = &Apache::loncoursedata::CL_ROLE();
$index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
+ $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
+ $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
foreach my $key (keys(%{$index})) {
$keylist->[$index->{$key}] = $key;
}
@@ -1723,22 +1908,25 @@ sub aggregate_user_info {
sub process_date_info {
my ($userdata) = @_;
my $now = time;
- $userdata->{'status'} = 'Active';
+ $userdata->{'status'} = &mt('Active');
if ($userdata->{'start'} > 0) {
if ($now < $userdata->{'start'}) {
- $userdata->{'status'} = 'Future';
+ $userdata->{'status'} = &mt('Future');
}
}
if ($userdata->{'end'} > 0) {
if ($now > $userdata->{'end'}) {
- $userdata->{'status'} = 'Expired';
+ $userdata->{'status'} = &mt('Expired');
}
}
return;
}
sub show_users_list {
- my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
+ my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
+ if ($formname eq '') {
+ $formname = 'studentform';
+ }
#
# Variables for excel output
my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -1753,27 +1941,32 @@ sub show_users_list {
} else {
push(@sortable,'extent');
}
+ if ($mode eq 'pickauthor') {
+ @sortable = ('username','fullname','email','status');
+ }
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'};
- $cdom = $env{'course.'.$cid.'.domain'};
- $cnum = $env{'course.'.$cid.'.num'};
+ $cid = $env{'request.course.id'};
+ ($cnum,$cdom) = &get_course_identity($cid);
($classgroups) = &Apache::loncoursedata::get_group_memberships(
$userlist,$keylist,$cdom,$cnum);
- if (! exists($env{'form.displayphotos'})) {
- $env{'form.displayphotos'} = 'off';
- }
- $displayphotos = $env{'form.displayphotos'};
- if (! exists($env{'form.displayclickers'})) {
- $env{'form.displayclickers'} = 'off';
- }
- $displayclickers = $env{'form.displayclickers'};
- if ($env{'course.'.$cid.'.internal.showphoto'}) {
- $r->print('
+ if ($mode eq 'autoenroll') {
+ $env{'form.showrole'} = 'st';
+ } else {
+ if (! exists($env{'form.displayphotos'})) {
+ $env{'form.displayphotos'} = 'off';
+ }
+ $displayphotos = $env{'form.displayphotos'};
+ if (! exists($env{'form.displayclickers'})) {
+ $env{'form.displayclickers'} = 'off';
+ }
+ $displayclickers = $env{'form.displayclickers'};
+ if ($env{'course.'.$cid.'.internal.showphoto'}) {
+ $r->print('
- ');
- }
- $r->print(<print(<
END
+ }
}
- unless ($mode eq 'autoenroll') {
+ if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
- my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
- my $singconfirm = &mt(' for a single user');
- my $multconfirm = &mt(' for multiple users');
- my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
+ my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
+ my $verify_action_js = &bulkaction_javascript($formname);
$r->print(<
$check_uncheck_js
-function verify_action (field) {
- var numchecked = 0;
- var singconf = '$singconfirm';
- var multconf = '$multconfirm';
- if (field.length > 0) {
- for (i = 0; i < field.length; i++) {
- if (field[i].checked == true) {
- numchecked ++;
- }
- }
- } else {
- if (field.checked == true) {
- numchecked ++;
- }
- }
- if (numchecked == 0) {
- alert("$alert");
- }
- else {
- var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
- if (numchecked == 1) {
- message += singconf;
- }
- else {
- message += multconf;
- }
- if (confirm(message)) {
- document.studentform.phase.value = 'bulkchange';
- document.studentform.submit();
- }
- }
-}
+$verify_action_js
function username_display_launch(username,domain) {
var target;
- for (var i=0; i
@@ -1874,44 +2051,50 @@ END
'role' => "role",
'type' => "enroll type/action",
'email' => "email address",
- 'clicker' => "clicker id",
'photo' => "photo",
'extent' => "extent",
'pr' => "Proceed",
'ca' => "check all",
'ua' => "uncheck all",
'ac' => "Action to take for selected users",
- 'link' => "Behavior of username links",
+ 'link' => "Behavior of clickable username link for each user",
'aboutme' => "Display a user's personal page",
+ 'owin' => "Open in a new window",
'modify' => "Modify a user's information",
+ 'clicker' => "Clicker-ID",
);
if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
$lt{'extent'} = &mt('Course(s): description, section(s), status');
} elsif ($context eq 'author') {
$lt{'extent'} = &mt('Author');
}
- my @cols = ('username','domain','id','fullname');
- if ($context eq 'course') {
- push(@cols,'section');
- }
- if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
- push(@cols,('start','end'));
- }
- if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
- push(@cols,'role');
- }
- if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
- $env{'form.roletype'} eq 'course')) {
- push (@cols,'extent');
- }
- if (($statusmode eq 'Any') &&
- (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
- push(@cols,'status');
- }
- if ($context eq 'course') {
- push(@cols,'groups');
+ my @cols;
+ if ($mode eq 'pickauthor') {
+ @cols = ('username','fullname','status','email');
+ } else {
+ @cols = ('username','domain','id','fullname');
+ if ($context eq 'course') {
+ push(@cols,'section');
+ }
+ if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
+ push(@cols,('start','end'));
+ }
+ if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
+ push(@cols,'role');
+ }
+ if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
+ $env{'form.roletype'} eq 'course')) {
+ push (@cols,'extent');
+ }
+ if (($statusmode eq 'Any') &&
+ (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
+ push(@cols,'status');
+ }
+ if ($context eq 'course') {
+ push(@cols,'groups');
+ }
+ push(@cols,'email');
}
- push(@cols,'email');
my $rolefilter = $env{'form.showrole'};
if ($env{'form.showrole'} eq 'cr') {
@@ -1919,83 +2102,134 @@ END
} elsif ($env{'form.showrole'} ne 'Any') {
$rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
}
- my $results_description = &results_header_row($rolefilter,$statusmode,
- $context);
- $r->print(''.$results_description.' ');
- my ($output,$actionselect);
- if ($mode eq 'html' || $mode eq 'view') {
- if ($permission->{'cusr'}) {
- $actionselect = &select_actions($context,$setting,$statusmode);
- }
- $r->print(<print(''.$results_description.'
');
+ }
+ my ($output,$actionselect,%canchange,%canchangesec);
+ if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
+ if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
+ if ($permission->{'cusr'}) {
+ $actionselect = &select_actions($context,$setting,$statusmode,$formname);
+ }
+ $r->print(<
END
- if ($mode ne 'autoenroll') {
- $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 .= ' ';
- }
- $output .= ' ';
- } else {
- $output .= &mt("Click on a username to view the user's personal page.").' ';
- }
- if ($actionselect) {
- $output .= <<"END";
-$lt{'ac'}: $actionselect
';
$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";
+ &mt("How do I create a CSV file from a spreadsheet"));
+ $str .= "
\n";
+ $str .= "
\n";
+ $str .= '
\n";
+ $str .= ''." \n";
$str .= &Apache::loncommon::end_page();
$r->print($str);
return;
@@ -2820,7 +3393,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);}
@@ -2835,10 +3408,14 @@ sub upfile_drop_add {
$fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('
\n".
- &mt('Roles added for [_1] users. If user is active, the new role will be available when the user next logs in to LON-CAPA.',$counts{'role'})."
\n");
+ &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."\n");
+ } else {
+ $r->print('
'.&mt('No roles added').'
');
}
if ($counts{'auth'} > 0) {
$r->print("
\n".
@@ -3154,23 +3913,22 @@ sub upfile_drop_add {
$counts{'auth'})."
\n");
}
$r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
- $r->print('');
#####################################
- # 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'}}.
@@ -3178,10 +3936,13 @@ 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 {
@@ -3225,14 +3986,14 @@ sub print_namespacing_alerts {
}
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'} ++;
@@ -3242,7 +4003,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'} ++;
@@ -3252,7 +4013,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'} ++;
@@ -3260,32 +4021,34 @@ 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) = @_;
+ $r->print('
'.&mt("Drop Students").'
'."\n".
+ ''. &Apache::loncommon::end_page());
return;
}
-
# ================================================================== Phase four
sub update_user_list {
@@ -3293,20 +4056,26 @@ sub update_user_list {
my $now = time;
my $count=0;
my @changelist;
- if ($choice ne '') {
- @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
- } else {
+ 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',
+ '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);
@@ -3316,7 +4085,18 @@ sub update_user_list {
foreach my $item (@changelist) {
my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
$scopestem);
- if ($context eq 'course') {
+ 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;
@@ -3346,30 +4126,32 @@ sub update_user_list {
}
}
my $plrole = &Apache::lonnet::plaintext($role);
- my ($uid,$first,$middle,$last,$gene,$sec);
my $start = $env{'form.'.$item.'_start'};
my $end = $env{'form.'.$item.'_end'};
- # revoke or delete user role
- if ($choice eq 'revoke') {
+ 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);
+ &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);
+ &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
+ '','',$context);
}
} elsif ($choice eq 'delete') {
- $start = -1;
- $end = -1;
if ($role eq 'st') {
-# FIXME - how does role deletion affect classlist?
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
- } else {
- $result =
- &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
- 0,1);
- }
+ &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') {
@@ -3378,25 +4160,25 @@ sub update_user_list {
}
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);
+ $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);
+ $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);
+ $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);
+ $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);
+ $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);
+ $start,'','',$context);
}
} elsif ($choice eq 'chgsec') {
my (@newsecs,$revresult,$nochg,@retained);
@@ -3409,36 +4191,52 @@ sub update_user_list {
if (@newsecs == 0) {
$result = &mt('No change in section assignment (none)');
$nochg = 1;
- }
- } else {
- if (!grep(/^\Q$sec\E$/,@newsecs)) {
+ } else {
$revresult =
- &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
+ &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 {
- push(@retained,$sec);
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
}
}
} else {
- push(@retained,$sec);
+ if ($sec eq '') {
+ $nochg = 1;
+ } else {
+ push(@retained,$sec);
+ }
}
# add new sections
if (@newsecs == 0) {
if (!$nochg) {
- if ($sec ne '') {
- if ($role eq 'st') {
- $result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
- } else {
- my $newscope = $scopestem;
- $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
- }
+ 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);
+ $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 '') {
@@ -3452,19 +4250,39 @@ sub update_user_list {
}
}
}
+ 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("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
- $plrole,$scope,$uname.':'.$udom).' ');
+ $plrole,$extent,$uname.':'.$udom).' ');
$count++;
} else {
$r->print(
- &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
- $plrole,$scope,$uname.':'.$udom,$result).' ');
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
+ $plrole,$extent,$uname.':'.$udom,$result).' ');
+ }
+ }
+ $r->print(''."\n");
}
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)) {
if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
- my $result =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
+ my %user;
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
return &mt('Drop from classlist: [_1]',
''.$result.'').' ';
}
@@ -3555,21 +4373,53 @@ sub set_login {
}
sub course_sections {
- my ($sections_count,$role) = @_;
+ my ($sections_count,$role,$current_sec) = @_;
my $output = '';
my @sections = (sort {$a <=> $b} keys %{$sections_count});
- if (scalar(@sections) == 1) {
+ my $numsec = scalar(@sections);
+ my $is_selected = ' selected="selected" ';
+ if ($numsec <= 1) {
$output = ''."\n".
- ' '."\n".
- ' '."\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 = ''."\n";
+ if ($role eq 'st') {
+ $output .= '>'."\n".
+ ' '."\n";
+ if ($current_sec eq 'none') {
+ $output .=
+ ' \n";
+ } else {
+ $output .=
+ ' \n";
+ }
+ } else {
+ $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
+ }
foreach my $sec (@sections) {
- $output .= '\n";
+ if ($current_sec eq $sec) {
+ $output .= '\n";
+ } else {
+ $output .= '\n";
+ }
}
}
$output .= '';
@@ -3587,16 +4437,41 @@ sub get_groupslist {
}
sub setsections_javascript {
- my ($form,$groupslist) = @_;
- my ($checkincluded,$finish,$roleplace,$setsection_js);
- if ($form eq 'cu') {
+ my ($formname,$groupslist,$mode,$checkauth) = @_;
+ 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';
- $finish = 'formname.submit()';
- $roleplace = 3;
+ 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 == "'.$form.'"';
+ $checkincluded = 'formname.name == "'.$formname.'"';
$finish = "seccheck = 'ok';";
- $roleplace = 1;
+ $rolecode = "var match = str.split('_');
+ var role = match[1];\n";
$setsection_js = "var seccheck = 'alert';";
}
my %alerts = &Apache::lonlocal::texthash(
@@ -3621,8 +4496,7 @@ function setSections(formname) {
var checkcurr = str.match(re1);
if (checkcurr != null) {
if ($checkincluded) {
- var match = str.split('_');
- var role = match[$roleplace];
+ $rolecode
if (role == 'cc') {
alert("$alerts{'secd'}\\n$alerts{'accr'}");
}
@@ -3693,5 +4567,449 @@ ENDSECCODE
return $setsection_js;
}
+sub can_create_user {
+ my ($dom,$context,$usertype) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my $cancreate = 1;
+ if (&Apache::lonnet::allowed('mau',$dom)) {
+ return $cancreate;
+ }
+ if (ref($domconf{'usercreation'}) eq 'HASH') {
+ if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
+ if ($context eq 'course' || $context eq 'author') {
+ my $creation = $domconf{'usercreation'}{'cancreate'}{$context};
+ if ($creation eq 'none') {
+ $cancreate = 0;
+ } elsif ($creation ne 'any') {
+ if (defined($usertype)) {
+ if ($creation ne $usertype) {
+ $cancreate = 0;
+ }
+ }
+ }
+ }
+ }
+ }
+ 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 ($context eq 'selfcreate') {
+ $testrole = $role;
+ } else {
+ 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;
+ if (ref($rules) eq 'HASH') {
+ my @user_rules = keys(%{$rules});
+ if (@user_rules > 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) = @_;
+ my @allroles;
+ if ($context eq 'course') {
+ @allroles = ('st','ad','ta','ep','in','cc');
+ if ($custom) {
+ push(@allroles,'cr');
+ }
+ } elsif ($context eq 'author') {
+ @allroles = ('ca','aa');
+ } elsif ($context eq 'domain') {
+ @allroles = ('li','dg','sc','au','dc');
+ }
+ return @allroles;
+}
+
+sub get_permission {
+ my ($context,$roles) = @_;
+ my %permission;
+ if ($context eq 'course') {
+ my $custom = 1;
+ my @allroles = &roles_by_context($context,$custom);
+ 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,%customroles) = @_;
+ my (@possible_roles,@permitted_roles);
+ @possible_roles = &curr_role_permissions($context,$setting,1);
+ 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 %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)) {
+ 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 = "";
+ }
+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") {
+ 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 in the current domain',
+ inea => 'In each course, each user may only have one student 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',
+ 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'
+ );
+ 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;