';
+ $cellentry = ''.&mt('manual').' '.&mt('Change').'';
$manualcount ++;
if ($in{'lockedtype'}) {
$cellentry .= ' '.&mt('Unlock').' ';
@@ -2749,17 +3042,27 @@ END
if ($showcheckbox) {
$checkval = $user;
if ($context eq 'course') {
- if ($role eq 'st') {
- $checkval .= ':st';
- }
- $checkval .= ':'.$in{'section'};
- if ($role eq 'st') {
- $checkval .= ':'.$in{'type'}.':'.
- $in{'lockedtype'};
- }
+ if (($role eq 'co' || $role eq 'cc') &&
+ ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
+ $showcheckbox = 0;
+ } else {
+ if ($role eq 'st') {
+ $checkval .= ':st';
+ }
+ $checkval .= ':'.$in{'section'};
+ if ($role eq 'st') {
+ $checkval .= ':'.$in{'type'}.':'.
+ $in{'lockedtype'}.':'.
+ $in{'credits'};
+ }
+ }
+ }
+ if ($showcheckbox) {
+ $r->print(' ');
+ } else {
+ $r->print(' ');
}
- $r->print(' ');
} else {
$r->print(' ');
}
@@ -2778,43 +3081,36 @@ END
$showitem = $ltstatus{$in{$item}};
}
$r->print(''.$showitem.' '."\n");
- } else {
- $r->print(''.$in{$item}.' '."\n");
- }
- }
- if (($context eq 'course') && ($mode ne 'autoenroll')) {
- if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
- if ($displayclickers eq 'on') {
- my $clickers =
+ } elsif ($item eq 'photo') {
+ if (($context eq 'course') && ($mode ne 'autoenroll') &&
+ ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
+ if ($role eq 'st') {
+ $r->print(' ');
+ } else {
+ $r->print(' ');
+ }
+ }
+ } elsif ($item eq 'clicker') {
+ if (($context eq 'course') && ($mode ne 'autoenroll')) {
+ if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
+ my $clickers =
(&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
- if ($clickers!~/\w/) { $clickers='-'; }
- $r->print(''.$clickers.' ');
- } else {
- $r->print(' ');
- }
- if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
- if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
- $r->print(' ');
+ if ($clickers!~/\w/) { $clickers='-'; }
+ $r->print(''.$clickers.' ');
} else {
- $r->print(' ');
- }
+ $r->print(' '."\n");
+ }
}
+ } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
+ $r->print(''.$in{$item}.' '."\n");
+ } else {
+ $r->print(''.$in{$item}.' '."\n");
}
}
$r->print(&Apache::loncommon::end_data_table_row());
} elsif ($mode eq 'csv') {
next if (! defined($CSVfile));
# no need to bother with $linkto
- if (! defined($in{'start'}) || $in{'start'} == 0) {
- $in{'start'} = &mt('none');
- } else {
- $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
- }
- if (! defined($in{'end'}) || $in{'end'} == 0) {
- $in{'end'} = &mt('none');
- } else {
- $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
- }
my @line = ();
foreach my $item (@cols) {
push @line,&Apache::loncommon::csv_translate($in{$item});
@@ -2824,9 +3120,9 @@ END
my $col = 0;
foreach my $item (@cols) {
if ($item eq 'start' || $item eq 'end') {
- if (defined($item) && $item != 0) {
+ if ((defined($in{$item})) && ($in{$item} != 0)) {
$excel_sheet->write($row,$col++,
- &Apache::lonstathelpers::calc_serial($in{item}),
+ &Apache::lonstathelpers::calc_serial($in{$item}),
$format->{'date'});
} else {
$excel_sheet->write($row,$col++,'none');
@@ -2842,10 +3138,10 @@ END
$r->print(&Apache::loncommon::end_data_table().' ');
} elsif ($mode eq 'excel') {
$excel_workbook->close();
- $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '',' ')."
\n");
+ $r->print(''.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '',' ')."
\n");
} elsif ($mode eq 'csv') {
close($CSVfile);
- $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '',' ')."
\n");
+ $r->print(''.&mt('[_1]Your CSV file[_2] is ready for download.', '',' ')."
\n");
$r->rflush();
}
if ($mode eq 'autoenroll') {
@@ -3007,6 +3303,7 @@ sub select_actions {
chgdates => "Change starting/ending dates",
chgsec => "Change section associated with user roles",
);
+ # FIXME Add an option to change credits for student roles.
my ($output,$options,%choices);
# FIXME Disable actions for now for roletype=course in domain context
if ($context eq 'domain' && $setting eq 'course') {
@@ -3014,15 +3311,20 @@ sub select_actions {
}
if ($context eq 'course') {
if ($env{'form.showrole'} ne 'Any') {
- if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
- $env{'request.course.id'})) {
- if ($env{'request.course.sec'} eq '') {
- return;
- } else {
- if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
- return;
- }
- }
+ my $showactions;
+ if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
+ $env{'request.course.id'})) {
+ $showactions = 1;
+ } elsif ($env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
+ $showactions = 1;
+ }
+ }
+ unless ($showactions) {
+ unless (&is_courseowner($env{'request.course.id'},
+ $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
+ return;
+ }
}
}
}
@@ -3129,11 +3431,13 @@ ENDTWO
}
sub date_section_selector {
- my ($context,$permission,$crstype) = @_;
+ my ($context,$permission,$crstype,$showcredits) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
- my $sec_js = &setsections_javascript($formname,$groupslist);
+ my $sec_js =
+ &setsections_javascript($formname,$groupslist,undef,undef,$crstype,
+ $showcredits);
my $output = <<"END";
-
END
my ($indexhash,$keylist) = &make_keylist_array();
@@ -3548,17 +3862,20 @@ END
}
}
if (!$studentcount) {
+ my $msg = '';
if ($crstype eq 'Community') {
- $r->print(&mt('There are no members to drop.'));
+ $msg = &mt('There are no members to drop.');
} else {
- $r->print(&mt('There are no students to drop.'));
+ $msg = &mt('There are no students to drop.');
}
+ $r->print('
'.$msg.'
');
return;
}
my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
$classlist,$keylist,$cdom,$cnum);
my %lt=&Apache::lonlocal::texthash('usrn' => "username",
'dom' => "domain",
+ 'id' => "ID",
'sn' => "student name",
'mn' => "member name",
'sec' => "section",
@@ -3577,7 +3894,7 @@ END
$lt{'usrn'}
$lt{'dom'}
- ID
+ $lt{'id'}
$nametitle
$lt{'sec'}
$lt{'start'}
@@ -3591,21 +3908,21 @@ END
$r->print(<
- $lt{'usrn'}
+ $lt{'usrn'}
- $lt{'dom'}
+ $lt{'dom'}
- ID
+ $lt{'id'}
- $nametitle
+ $nametitle
- $lt{'sec'}
+ $lt{'sec'}
- $lt{'start'}
+ $lt{'start'}
- $lt{'end'}
+ $lt{'end'}
- $lt{'groups'}
+ $lt{'groups'}
END
$r->print(&Apache::loncommon::end_data_table_header_row());
@@ -3676,7 +3993,6 @@ END
$btn = $lt{'dm'};
}
$r->print(<<"END");
-
@@ -3698,16 +4014,17 @@ sub print_first_users_upload_form {
$str .= ' ';
$str .= ' ';
+ $str .= &Apache::grades::checkforfile_js();
+
$str .= '
'.&mt('Upload a file containing information about users').' '."\n";
# Excel and CSV Help
- $str .= ''
+ $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",
+ .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
&mt("How do I create a CSV file from a spreadsheet"))
- .'
'."\n";
+ ."
\n";
$str .= &Apache::lonhtmlcommon::start_pick_box()
.&Apache::lonhtmlcommon::row_title(&mt('File'));
if (&Apache::lonlocal::current_language() ne 'en') {
@@ -3728,7 +4045,8 @@ sub print_first_users_upload_form {
.&Apache::lonhtmlcommon::end_pick_box();
$str .= ''
- .' '
+ .' '
.'
';
$r->print($str);
@@ -3737,7 +4055,7 @@ sub print_first_users_upload_form {
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$showcredits) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -3758,25 +4076,17 @@ sub upfile_drop_add {
}
#
# Store the field choices away
- foreach my $field (qw/username names
- fname mname lname gen id sec ipwd email role domain/) {
+ my @storefields = qw/username names fname mname lname gen id
+ sec ipwd email role domain inststatus/;
+ if ($showcredits) {
+ push (@storefields,'credits');
+ }
+ my %fieldstype;
+ foreach my $field (@storefields) {
$env{'form.'.$field.'_choice'}=$fields{$field};
+ $fieldstype{$field.'_choice'} = 'scalar';
}
- &Apache::loncommon::store_course_settings('enrollment_upload',
- { 'username_choice' => 'scalar',
- 'names_choice' => 'scalar',
- 'fname_choice' => 'scalar',
- 'mname_choice' => 'scalar',
- 'lname_choice' => 'scalar',
- 'gen_choice' => 'scalar',
- 'id_choice' => 'scalar',
- 'sec_choice' => 'scalar',
- 'ipwd_choice' => 'scalar',
- 'email_choice' => 'scalar',
- 'role_choice' => 'scalar',
- 'domain_choice' => 'scalar',
- 'inststatus_choice' => 'scalar'});
- #
+ &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
my ($cid,$crstype,$setting);
if ($context eq 'domain') {
$setting = $env{'form.roleaction'};
@@ -3844,19 +4154,30 @@ sub upfile_drop_add {
$amode = ''; # This causes the loop below to be skipped
}
}
- my ($defaultsec,$defaultrole);
+ my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
if ($context eq 'domain') {
if ($setting eq 'domain') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($setting eq 'course') {
$defaultrole = $env{'form.courserole'};
$defaultsec = $env{'form.sections'};
- }
+ if ($showcredits) {
+ $commoncredits = $env{'form.credits'};
+ if ($crstype ne 'Community') {
+ my %coursehash=&Apache::lonnet::coursedescription($cid);
+ $defaultcredits = $coursehash{'internal.defaultcredits'};
+ }
+ }
+ }
} elsif ($context eq 'author') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($context eq 'course') {
$defaultrole = $env{'form.defaultrole'};
$defaultsec = $env{'form.sections'};
+ if ($showcredits) {
+ $commoncredits = $env{'form.credits'};
+ $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
+ }
}
# Check to see if user information can be changed
my @userinfo = ('firstname','middlename','lastname','generation',
@@ -3966,7 +4287,8 @@ sub upfile_drop_add {
official => 'Institutional',
unofficial => 'Non-institutional',
);
- map { $cancreate{$_} = &can_create_user($domain,$context,$_); } keys(%longtypes);
+ my $newuserdom = $env{'request.role.domain'};
+ map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
# Get new users list
foreach my $line (@userdata) {
my @secs;
@@ -4000,17 +4322,23 @@ sub upfile_drop_add {
if ($entries{$fields{'username'}} =~ /\s/) {
$nowhitespace = ' - '.&mt('usernames may not contain spaces.');
}
- $r->print(' '.
- &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
- ''.$entries{$fields{'username'}}.' ',$fname,$mname,$lname,$gen).
- $nowhitespace);
+ $r->print(
+ ' '.
+ &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$entries{$fields{'username'}}.' "',
+ $fname,$mname,$lname,$gen).
+ $nowhitespace);
next;
} else {
+ $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
if ($entries{$fields{'domain'}}
ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
- $r->print(' '. ''.$entries{$fields{'domain'}}.
- ' : '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
- next;
+ $r->print(
+ ' '.
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$entries{$fields{'domain'}}.' "',
+ $fname,$mname,$lname,$gen));
+ next;
}
my $username = $entries{$fields{'username'}};
my $userdomain = $entries{$fields{'domain'}};
@@ -4064,6 +4392,7 @@ sub upfile_drop_add {
# determine email address
my $email='';
if (defined($fields{'email'})) {
+ $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
if (defined($entries{$fields{'email'}})) {
$email=$entries{$fields{'email'}};
unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
@@ -4110,34 +4439,57 @@ sub upfile_drop_add {
$role = $defaultrole;
}
# Clean up whitespace
- foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
+ foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
$$_ =~ s/(\s+$|^\s+)//g;
}
+ my $credits;
+ if ($showcredits) {
+ if (($role eq 'st') && ($crstype ne 'Community')) {
+ $credits = $entries{$fields{'credits'}};
+ if ($credits ne '') {
+ $credits =~ s/[^\d\.]//g;
+ }
+ if ($credits eq '') {
+ $credits = $commoncredits;
+ }
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
+ }
+ }
# check against rules
my $checkid = 0;
my $newuser = 0;
my (%rulematch,%inst_results,%idinst_results);
my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
if ($uhome eq 'no_host') {
- if ($userdomain ne $domain) {
- $r->print(' '.
- &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
- ''.$username.' ',$userdomain).' '.
- &mt('The user does not already exist, and you may not create a new user in a different domain.'));
+ if ($userdomain ne $newuserdom) {
+ if ($context eq 'course') {
+ $r->print(' '.
+ &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
+ ''.$username.' ',$userdomain).' ');
+ } elsif ($context eq 'author') {
+ $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.',
+ ''.$username.' ',$userdomain).' ');
+ } else {
+ $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
+ ''.$username.' ',$userdomain).' ');
+ }
+ $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
next;
}
$checkid = 1;
$newuser = 1;
- my $user = $username.':'.$domain;
+ my $user = $username.':'.$newuserdom;
my $checkhash;
my $checks = { 'username' => 1 };
- $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
+ $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
&Apache::loncommon::user_rule_check($checkhash,$checks,
\%alerts,\%rulematch,\%inst_results,\%curr_rules,
\%got_rules);
if (ref($alerts{'username'}) eq 'HASH') {
- if (ref($alerts{'username'}{$domain}) eq 'HASH') {
- if ($alerts{'username'}{$domain}{$username}) {
+ if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') {
+ if ($alerts{'username'}{$newuserdom}{$username}) {
$r->print(' '.
&mt('[_1]: matches the username format at your institution, but is not known to your directory service.',''.$username.' ').' '.
&mt('Consequently, the user was not created.'));
@@ -4154,7 +4506,7 @@ sub upfile_drop_add {
unless ($cancreate{$usertype}) {
my $showtype = $longtypes{$usertype};
$r->print(' '.
- &mt("[_1]: The user does not exist, and you are not permitted to create users of type: $showtype.",''.$username.' '));
+ &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].',''.$username.' ',$showtype));
next;
}
} else {
@@ -4235,7 +4587,7 @@ sub upfile_drop_add {
$fname,$mname,$lname,$gen,$sec,$enddate,
$startdate,$env{'form.forceid'},
$desiredhost,$email,'manual','',$cid,
- '',$context,$inststatus);
+ '',$context,$inststatus,$credits);
$userresult = $roleresult;
} else {
if ($role ne '') {
@@ -4330,9 +4682,9 @@ sub upfile_drop_add {
# Get current classlist
my $classlist = &Apache::loncoursedata::get_classlist();
if (! defined($classlist)) {
- $r->print(''.
+ $r->print(''."\n");
} elsif (ref($classlist) eq 'HASH') {
# Remove the students we just added from the list of students.
@@ -4453,18 +4805,20 @@ sub print_drop_menu {
$heading = &mt("Drop Students");
}
$r->print(''.$heading.' '."\n".
- ''. &Apache::loncommon::end_page());
+ $r->print('');
return;
}
@@ -4507,7 +4861,7 @@ sub update_user_list {
foreach my $item (@changelist) {
my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
@sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
- $nothingtodo,$keepnosection);
+ $nothingtodo,$keepnosection,$credits);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -4520,7 +4874,8 @@ sub update_user_list {
$scope = $scopestem.'/'.$sec;
}
} elsif ($context eq 'course') {
- ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
+ ($uname,$udom,$role,$sec,$type,$locktype,$credits) =
+ split(/\:/,$item);
$cid = $env{'request.course.id'};
$scopestem = '/'.$cid;
$scopestem =~s/\_/\//g;
@@ -4539,7 +4894,7 @@ sub update_user_list {
} elsif ($setting eq 'author') {
($uname,$udom,$role,$scope) = split(/\:/,$item);
} elsif ($setting eq 'course') {
- ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits) =
split(/\:/,$item);
$scope = '/'.$cid;
$scope =~s/\_/\//g;
@@ -4562,7 +4917,7 @@ sub update_user_list {
$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);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result =
&Apache::lonnet::revokerole($udom,$uname,$scope,$role,
@@ -4570,7 +4925,7 @@ sub update_user_list {
}
} 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);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits);
}
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
@@ -4583,7 +4938,7 @@ 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,'',$context);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
@@ -4591,14 +4946,14 @@ sub update_user_list {
}
} 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);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} 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);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
$result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
$start,'','',$context);
@@ -4668,7 +5023,7 @@ sub update_user_list {
} else {
if ($role eq 'st') {
$result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits);
} else {
my $newscope = $scopestem;
$result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
@@ -4682,7 +5037,7 @@ sub update_user_list {
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);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
if (@newsecs > 1) {
my $showsingle;
if ($newsec eq '') {
@@ -4793,7 +5148,7 @@ sub update_user_list {
}
}
}
- $r->print(''.&mt("$result_text{'ok'}{$choice} for [quant,_1,user role,user roles,no user roles].",$count).'
');
+ $r->print(''.&mt("$result_text{'ok'}{$choice} [quant,_1,user role,user roles,no user roles].",$count).'
');
if ($count > 0) {
if ($choice eq 'revoke' || $choice eq 'drop') {
$r->print(''.&mt('Re-enabling will re-activate data for the role.').'
');
@@ -4810,7 +5165,10 @@ sub update_user_list {
if ($choice eq 'drop') {
$linktext = &mt('Display current class roster');
}
- $r->print(''.$linktext.' '."\n");
+ $r->print(
+ &Apache::lonhtmlcommon::actionbox(
+ [''.$linktext.' '])
+ .''."\n");
}
sub dates_feedback {
@@ -4818,7 +5176,7 @@ sub dates_feedback {
my $dates;
if ($start < $now) {
if ($end == 0) {
- $dates .= &mt('role(s) active now; no end date');
+ $dates = &mt('role(s) active now; no end date');
} elsif ($end > $now) {
$dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
} else {
@@ -4971,14 +5329,18 @@ sub get_groupslist {
}
sub setsections_javascript {
- my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
+ my ($formname,$groupslist,$mode,$checkauth,$crstype,$showcredits) = @_;
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 (($crstype eq 'Course') && ($showcredits)) {
+ $checkincluded = "((role == 'st') && (formname.elements[i-2].checked == true)) || ((role != 'st') && (formname.elements[i-1].checked == true))";
+ } else {
+ $checkincluded = 'formname.elements[i-1].checked == true';
+ }
if ($checkauth) {
$finish = "var authcheck = auth_check();\n".
" if (authcheck == 'ok') {\n".
@@ -4989,7 +5351,7 @@ sub setsections_javascript {
}
$rolecode = "var match = str.split('_');
var role = match[3];\n";
- } elsif ($formname eq 'enrollstudent') {
+ } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
$checkincluded = 'formname.name == "'.$formname.'"';
if ($checkauth) {
$finish = "var authcheck = auth_check();\n".
@@ -5015,7 +5377,7 @@ sub setsections_javascript {
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.',
inco => 'In each community, each user may only have one member role at a time.',
- youh => 'You had selected ',
+ 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.',
@@ -5037,8 +5399,8 @@ function setSections(formname,crstype) {
var checkcurr = str.match(re1);
if (checkcurr != null) {
var num = i;
+ $rolecode
if ($checkincluded) {
- $rolecode
if (role == 'cc' || role == 'co') {
if (role == 'cc') {
alert("$alerts{'secd'}\\n$alerts{'accr'}");
@@ -5235,18 +5597,40 @@ sub can_modify_userinfo {
}
sub check_usertype {
- my ($dom,$uname,$rules) = @_;
+ my ($dom,$uname,$rules,$curr_rules,$got_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;
+ if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
+ if (!$got_rules->{$dom}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$dom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $item ('username','id') {
+ if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+ $curr_rules->{$dom}{$item} =
+ $domconfig{'usercreation'}{$item.'_rule'};
+ }
+ }
+ }
+ $got_rules->{$dom} = 1;
+ }
+ if (ref($rules) eq 'HASH') {
+ my @user_rules;
+ if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
+ foreach my $rule (keys(%{$rules})) {
+ if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
+ push(@user_rules,$rule);
+ }
+ }
+ }
+ 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;
+ }
}
}
}
@@ -5317,6 +5701,22 @@ sub get_permission {
if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
$permission{'grp_manage'} = 1;
}
+ if ($permission{'cusr'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my %coursehash = (
+ 'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
+ 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
+ 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
+ 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
+ );
+ my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
+ if (ref($managed_by_cc) eq 'ARRAY') {
+ if (@{$managed_by_cc}) {
+ $permission{'selfenrolladmin'} = 1;
+ }
+ }
+ }
} elsif ($context eq 'author') {
$permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
$permission{'view'} = $permission{'cusr'};
@@ -5389,7 +5789,7 @@ sub get_course_identity {
}
sub dc_setcourse_js {
- my ($formname,$mode,$context) = @_;
+ my ($formname,$mode,$context,$showcredits) = @_;
my ($dc_setcourse_code,$authen_check);
my $cctext = &Apache::lonnet::plaintext('cc');
my $cotext = &Apache::lonnet::plaintext('co');
@@ -5475,7 +5875,7 @@ function setCourse() {
}
SCRIPTTOP
if ($mode ne 'upload') {
- $dc_setcourse_code .= (<<"ENDSCRIPT");
+ $dc_setcourse_code .= (<<"SCRIPTMID");
var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
var numcourse = getIndex(document.$formname.dccourse);
if (numcourse == "-1") {
@@ -5501,6 +5901,16 @@ SCRIPTTOP
if (numend != "-1") {
document.$formname.elements[numend].name = "end"+coursename
}
+SCRIPTMID
+ if ($showcredits) {
+ $dc_setcourse_code .= < 'Users allowed to self-enroll',
+ registered => 'Registration status (official courses)' ,
+ enroll_dates => 'Dates self-enrollment available',
+ access_dates => 'Access dates for self-enrolling users',
+ section => "Self-enrolling users' section",
+ approval => 'Processing of requests',
+ limit => 'Enrollment limit',
+ );
+ return (\@row,\%lt);
+}
+
+sub selfenroll_default_descs {
+ my %desc = (
+ types => {
+ dom => &mt('Course domain'),
+ all => &mt('Any domain'),
+ '' => &mt('None'),
+ },
+ limit => {
+ none => &mt('No limit'),
+ allstudents => &mt('Limit by total students'),
+ selfenrolled => &mt('Limit by total self-enrolled'),
+ },
+ approval => {
+ '0' => &mt('Processed automatically'),
+ '1' => &mt('Queued for approval'),
+ '2' => &mt('Queued, pending validation'),
+ },
+ registered => {
+ 0 => 'No registration required',
+ 1 => 'Registered students only',
+ },
+ );
+ return %desc;
+}
+
+sub selfenroll_validation_types {
+ my @items = ('url','fields','button','markup');
+ my %names = &Apache::lonlocal::texthash (
+ url => 'Web address of validation server/script',
+ fields => 'Form fields to send to validator',
+ button => 'Text for validation button',
+ markup => 'Validation description (HTML)',
+ );
+ my @fields = ('username','domain','uniquecode','course','token','coursetype','description');
+ return (\@items,\%names,\@fields);
+}
+
+sub get_extended_type {
+ my ($cdom,$cnum,$crstype,$current) = @_;
+ my $type = 'unofficial';
+ my %settings;
+ if (ref($current) eq 'HASH') {
+ %settings = %{$current};
+ } else {
+ %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
+ }
+ if ($crstype eq 'Community') {
+ $type = 'community';
+ } elsif ($settings{'internal.coursecode'}) {
+ $type = 'official';
+ } elsif ($settings{'internal.textbook'}) {
+ $type = 'textbook';
+ }
+ return $type;
+}
+
+sub selfenrollment_administration {
+ my ($cdom,$cnum,$crstype,$coursehash) = @_;
+ my %settings;
+ if (ref($coursehash) eq 'HASH') {
+ %settings = %{$coursehash};
+ } else {
+ %settings = &Apache::lonnet::get('environment',
+ ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
+ 'internal.coursecode','internal.textbook'],$cdom,$cnum);
+ }
+ my ($possconfigs) = &get_selfenroll_titles();
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+ my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
+
+ my (@in_course,@in_domain);
+ if ($settings{'internal.selfenrollmgrcc'} ne '') {
+ @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
+ my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
+ unless (@diffs) {
+ return (\@in_course,\@in_domain);
+ }
+ }
+ if ($settings{'internal.selfenrollmgrdc'} ne '') {
+ my @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
+ my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
+ unless (@diffs) {
+ return (\@in_course,\@in_domain);
+ }
+ }
+ my @combined = @in_course;
+ push(@combined,@in_domain);
+ my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
+ unless (@diffs) {
+ return (\@in_course,\@in_domain);
+ }
+ if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
+ push(@in_course,@diffs);
+ } else {
+ my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
+ foreach my $item (@diffs) {
+ if (grep(/^\Q$item\E$/,@defaultdc)) {
+ push(@in_domain,$item);
+ } else {
+ push(@in_course,$item);
+ }
+ }
+ }
+ return (\@in_course,\@in_domain);
+}
+
1;