[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonparmset.pm
raeburn
raeburn at source.lon-capa.org
Wed Feb 12 14:54:47 EST 2020
raeburn Wed Feb 12 19:54:47 2020 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface lonparmset.pm
Log:
- For 2.11
Backport 1.594, 1.595, 1.596
-------------- next part --------------
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.522.2.26 loncom/interface/lonparmset.pm:1.522.2.27
--- loncom/interface/lonparmset.pm:1.522.2.26 Sat Dec 1 15:34:55 2018
+++ loncom/interface/lonparmset.pm Wed Feb 12 19:54:47 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.522.2.26 2018/12/01 15:34:55 raeburn Exp $
+# $Id: lonparmset.pm,v 1.522.2.27 2020/02/12 19:54:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1592,9 +1592,37 @@
sub usermenu {
my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups,$pssymb)=@_;
my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
- &Apache::loncommon::selectstudent_link('parmform','uname','udom');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
+ &Apache::loncommon::selectstudent_link('parmform','uname','udom','condition').
+ &Apache::lonhtmlcommon::scripttag(<<ENDJS);
+function setCourseadv(form,caller) {
+ if (caller.value == 'st') {
+ form.courseadv.value = 'none';
+ } else {
+ form.courseadv.value = '';
+ }
+ return;
+}
+ENDJS
+ my (%chkroles,$stuonly,$courseadv);
+ if ($env{'form.userroles'} eq 'any') {
+ $chkroles{'any'} = ' checked="checked"';
+ } else {
+ $chkroles{'st'} = ' checked="checked"';
+ $courseadv = 'none';
+ }
+ my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+ if ($crstype eq 'Community') {
+ $stuonly = &mt('member only');
+ } else {
+ $stuonly = &mt('student only');
+ }
+ $chooseopt .= '<br /><span class="LC_cusr_subheading">'.
+ &mt("User's role").': '.
+ '<label><input type="radio" name="userroles" value="st"'.$chkroles{'st'}.' onclick="setCourseadv(this.form,this);" />'.
+ $stuonly.'</label> '.
+ '<label><input type="radio" name="userroles" value="any"'.$chkroles{'any'}.' onclick="setCourseadv(this.form,this);" />'.
+ &mt('any role').'</label><input type="hidden" id="courseadv" name="courseadv" value="'.$courseadv.'" /></span>';
my $sections='';
my %sectionhash = &Apache::loncommon::get_sections();
@@ -2136,25 +2164,124 @@
$csec=&Apache::lonnet::getsection($udom,$uname,
$env{'request.course.id'});
if ($csec eq '-1') {
- $message='<span class="LC_error">'.
- &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
- &mt("not in this course")."</span>";
- $uname='';
- $csec=$env{'form.csec'};
+ my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+ if ($env{'form.userroles'} eq 'any') {
+ if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
+ $csec = $env{'request.course.sec'};
+ $message = '<span class="LC_info">';
+ if ($crstype eq 'Community') {
+ $message .= &mt('User [_1] at domain [_2] has a non-member role in this community',
+ $uname,$udom);
+ } else {
+ $message .= &mt('User [_1] at domain [_2] has a non-student role in this course',
+ $uname,$udom);
+ }
+ $message .= '</span>';
+ } else {
+ my @possroles = ('in','ep','ta','cr');
+ if ($crstype eq 'Community') {
+ unshift(@possroles,'co');
+ } else {
+ unshift(@possroles,'cc');
+ }
+ my %not_student_roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',['active'],
+ \@possroles,[$udom],1,1);
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my %sections_by_role;
+ foreach my $role (keys(%not_student_roles)) {
+ if ($role =~ /^\Q$cnum:$cdom:\E([^:]+):(|[^:]+)$/) {
+ my ($rolename,$sec) = ($1,$2);
+ if ($rolename =~ m{^cr/}) {
+ $rolename = 'cr';
+ }
+ push(@{$sections_by_role{$rolename}},$sec);
+ }
+ }
+ my $numroles = scalar(keys(%sections_by_role));
+ if ($numroles) {
+ foreach my $role (@possroles) {
+ if (ref($sections_by_role{$role}) eq 'ARRAY') {
+ my @secs = sort { $a <=> $b } @{$sections_by_role{$role}};
+ $csec = $secs[0];
+ last;
+ }
+ }
+ }
+ if ($csec eq '-1') {
+ $message = '<span class="LC_warning">';
+ if ($crstype eq 'Community') {
+ $message .= &mt('User [_1] at domain [_2] does not have a role in this community',
+ $uname,$udom);
+ } else {
+ $message .= &mt('User [_1] at domain [_2] does not have a role in this course',
+ $uname,$udom);
+ }
+ $message .= '</span>';
+ $uname='';
+ if ($env{'request.course.sec'} ne '') {
+ $csec=$env{'request.course.sec'};
+ } else {
+ $csec=$env{'form.csec'};
+ }
+ $cgroup=$env{'form.cgroup'};
+ } else {
+ $message = '<span class="LC_info">';
+ if ($crstype eq 'Community') {
+ $message .= &mt('User [_1] at domain [_2] has a non-member role in this community',
+ $uname,$udom);
+ } else {
+ $message .= &mt('User [_1] at domain [_2] has a non-student role in this course',
+ $uname,$udom);
+ }
+ $message .= '</span>';
+ }
+ }
+ } else {
+ $message = '<span class="LC_warning">';
+ if ($crstype eq 'Community') {
+ $message .= &mt('User [_1] at domain [_2] does not have a member role in this community',
+ $uname,$udom);
+ } else {
+ $message .= &mt('User [_1] at domain [_2] does not have a student role in this course',
+ $uname,$udom);
+ }
+ $message .= '</span>';
+ $uname='';
+ if ($env{'request.course.sec'} ne '') {
+ $csec=$env{'request.course.sec'};
+ } else {
+ $csec=$env{'form.csec'};
+ }
+ $cgroup=$env{'form.cgroup'};
+ }
+ } elsif ($env{'request.course.sec'} ne '') {
+ if ($csec ne $env{'request.course.sec'}) {
+ $message='<span class="LC_warning">'.
+ &mt("User '[_1]' at domain '[_2]' not in section '[_3]'",
+ $uname,$udom,$env{'request.course.sec'}).
+ '</span>';
+ $uname='';
+ $csec=$env{'request.course.sec'};
+ }
$cgroup=$env{'form.cgroup'};
- } else {
+ }
+ if ($uname ne '') {
my %name=&Apache::lonnet::userenvironment($udom,$uname,
('firstname','middlename','lastname','generation','id'));
- $message="\n<p>\n".&mt("Full Name").": ".
- $name{'firstname'}.' '.$name{'middlename'}.' '
- .$name{'lastname'}.' '.$name{'generation'}.
- "<br />\n".&mt('Student/Employee ID').": ".$name{'id'}.'<p>';
- }
- @usersgroups = &Apache::lonnet::get_users_groups(
- $udom,$uname,$env{'request.course.id'});
- if (@usersgroups > 0) {
- unless (grep(/^\Q$cgroup\E$/, at usersgroups)) {
- $cgroup = $usersgroups[0];
+ $message .= "\n<p>\n".&mt('Full Name').': '
+ .$name{'firstname'}.' '.$name{'middlename'}.' '
+ .$name{'lastname'}.' '.$name{'generation'}
+ ."<br />\n".&mt('Student/Employee ID').': '.$name{'id'}.'</p>';
+ @usersgroups = &Apache::lonnet::get_users_groups(
+ $udom,$uname,$env{'request.course.id'});
+ if (@usersgroups > 0) {
+ unless (grep(/^\Q$cgroup\E$/, at usersgroups)) {
+ $cgroup = $usersgroups[0];
+ }
+ } else {
+ $cgroup = '';
}
}
}
@@ -3063,6 +3190,7 @@
$tableopen=0;
my $foundkeys=0;
my %keyorder=&standardkeyorder();
+ my $readonlyall = $readonly;
my ($secidx,%grouphash);
if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
@@ -3123,6 +3251,7 @@
my ($middle,$part,$name)=
($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
my $section=&mt('All Students');
+ $readonly = $readonlyall;
if ($middle=~/^\[(.*)\]/) {
my $issection=$1;
if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
@@ -3418,9 +3547,22 @@
#
sub dateshift {
- my ($shift)=@_;
+ my ($shift,$numchanges)=@_;
my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $sec = $env{'request.course.sec'};
+ my $secgrpregex;
+ if ($sec ne '') {
+ my @groups;
+ if ($env{'request.course.groups'} ne '') {
+ @groups = split(/:/,$env{'request.course.groups'});
+ }
+ if (@groups) {
+ $secgrpregex = '(?:'.join('|',($sec, at groups)).')';
+ } else {
+ $secgrpregex = $sec;
+ }
+ }
my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
# ugly retro fix for broken version of types
foreach my $key (keys %data) {
@@ -3435,7 +3577,11 @@
# go through all parameters and look for dates
foreach my $key (keys %data) {
if ($data{$key.'.type'}=~/^date_(start|end)$/) {
+ if ($sec ne '') {
+ next unless ($key =~ /^$env{'request.course.id'}\.\[$secgrpregex\]\./);
+ }
my $newdate=$data{$key}+$shift;
+ $$numchanges ++;
$storecontent{$key}=$newdate;
}
}
@@ -3794,9 +3940,21 @@
my ($r) = @_;
my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
-
+ my $sec = $env{'request.course.sec'};
&Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
text=>"Shifting Dates"});
+ my $submit_text = &mt('Shift all dates accordingly');
+ if ($sec ne '') {
+ my @groups;
+ if ($env{'request.course.groups'} ne '') {
+ @groups = split(/:/,$env{'request.course.groups'});
+ }
+ if (@groups) {
+ $submit_text = &mt("Shift dates set just for your section/group(s), accordingly");
+ } else {
+ $submit_text = &mt("Shift dates set just for your section, accordingly");
+ }
+ }
my $start_page=&Apache::loncommon::start_page('Shift Dates');
my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
$r->print($start_page.$breadcrumbs);
@@ -3811,7 +3969,7 @@
'</td></tr></table>'.
'<input type="hidden" name="action" value="dateshift2" />'.
'<input type="hidden" name="timebase" value="'.$env{'form.timebase'}.'" />'.
- '<input type="submit" value="'.&mt('Shift all dates accordingly').'" /></form>');
+ '<input type="submit" value="'.$submit_text.'" /></form>');
$r->print(&Apache::loncommon::end_page());
}
@@ -3819,20 +3977,54 @@
my ($r) = @_;
my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $sec = $env{'request.course.sec'};
&Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
text=>"Shifting Dates"});
my $start_page=&Apache::loncommon::start_page('Shift Dates');
my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
$r->print($start_page.$breadcrumbs);
my $timeshifted=&Apache::lonhtmlcommon::get_date_from_form('timeshifted');
- $r->print('<h2>'.&mt('Shift Dates').'</h2>'.
- '<p>'.&mt('Shifting all dates such that [_1] becomes [_2]',
- &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
- &Apache::lonlocal::locallocaltime($timeshifted)).'</p>');
+ $r->print('<h2>'.&mt('Shift Dates').'</h2>');
+ if ($sec ne '') {
+ my @groups;
+ if ($env{'request.course.groups'} ne '') {
+ @groups = split(/:/,$env{'request.course.groups'});
+ }
+ if (@groups) {
+ $r->print('<p>'.
+ &mt("Shift dates set just for your section/group(s), such that [_1] becomes [_2]",
+ &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
+ &Apache::lonlocal::locallocaltime($timeshifted)).
+ '</p>');
+ } else {
+ $r->print('<p>'.
+ &mt("Shift dates set just for your section, such that [_1] becomes [_2]",
+ &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
+ &Apache::lonlocal::locallocaltime($timeshifted)).
+ '</p>');
+ }
+ } else {
+ $r->print('<p>'.&mt('Shifting all dates such that [_1] becomes [_2]',
+ &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
+ &Apache::lonlocal::locallocaltime($timeshifted)).
+ '</p>');
+ }
my $delta=$timeshifted-$env{'form.timebase'};
- &dateshift($delta);
+ my $numchanges = 0;
+ my $result = &dateshift($delta,\$numchanges);
+ if ($result eq 'ok') {
+ $r->print(
+ &Apache::lonhtmlcommon::confirm_success(&mt('Completed shifting of [quant,_1,date setting]',
+ $numchanges)));
+ } elsif ($result eq 'con_delayed') {
+ $r->print(
+ &Apache::lonhtmlcommon::confirm_success(&mt('Queued shifting of [quant,_1,date setting]',
+ $numchanges)));
+ } else {
+ $r->print(
+ &Apache::lonhtmlcommon::confirm_success(&mt('An error occurred attempting to shift dates'),1));
+ }
$r->print(
- &Apache::lonhtmlcommon::confirm_success(&mt('Done')).
'<br /><br />'.
&Apache::lonhtmlcommon::actionbox(
['<a href="/adm/parmset">'.&mt('Content and Problem Settings').'</a>']));
@@ -4647,6 +4839,12 @@
}
if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
}
+ my $numgroups = 0;
+ my @groups;
+ if ($env{'request.course.groups'} ne '') {
+ @groups = split(/:/,$env{'request.course.groups'});
+ $numgroups = scalar(@groups);
+ }
foreach my $id (sort
{
if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
@@ -4687,7 +4885,8 @@
my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
&components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);
if ($env{'request.course.sec'} ne '') {
- next if (($issection ne '') && ($issection ne $env{'request.course.sec'}));
+ next if (($issection ne '') && (!(($issection eq $env{'request.course.sec'}) ||
+ ($numgroups && (grep(/^\Q$issection\E$/, at groups))))));
if ($uname ne '') {
my $stusection = &Apache::lonnet::getsection($uname,$udom,$env{'request.course.id'});
next if (($stusection ne '-1') && ($stusection ne $env{'request.course.sec'}));
More information about the LON-CAPA-cvs
mailing list