[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm

raeburn raeburn at source.lon-capa.org
Mon Jul 10 09:55:36 EDT 2017


raeburn		Mon Jul 10 13:55:36 2017 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  - Bug 6131
    - Recursive parameters for overview and newoverview (i.e., non-table mode)
      Use Yes/No radio buttons for each Map/folder item to set recursion
      for that item, instead of separate "Map/folder" and "Recursive" items.
  
  
-------------- next part --------------
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.575 loncom/interface/lonparmset.pm:1.576
--- loncom/interface/lonparmset.pm:1.575	Mon Jul 10 13:37:59 2017
+++ loncom/interface/lonparmset.pm	Mon Jul 10 13:55:36 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.575 2017/07/10 13:37:59 raeburn Exp $
+# $Id: lonparmset.pm,v 1.576 2017/07/10 13:55:36 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3537,7 +3537,7 @@
 # @param {boolean} $readonly - true if values cannot be edited (otherwise more columns are added)
 # @returns {string}
 sub tablestart {
-    my ($readonly) = @_;
+    my ($readonly,$is_map) = @_;
     if ($tableopen) {
         return '';
     } else {
@@ -3546,7 +3546,11 @@
         if ($readonly) {
             $output .= '<th>'.&mt('Current value').'</th>';
         } else {
-            $output .= '<th>'.&mt('Delete').'</th><th>'.&mt('Set to ...').'</th>';
+            $output .= '<th>'.&mt('Delete').'</th>'.
+                       '<th>'.&mt('Set to ...').'</th>';
+            if ($is_map) {
+                $output .= '<th>'.&mt('Recursive?').'</th>';
+            }
         }
         $output .= '</tr>';
         return $output;
@@ -3625,6 +3629,8 @@
     my %newdata=();
     undef %newdata;
     my @deldata=();
+    my @delrec=();
+    my @delnonrec=();
     undef @deldata;
     my ($got_chostname,$chostname,$cmajor,$cminor);
     my $now = time;
@@ -3632,11 +3638,27 @@
         if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
             my $cmd=$1;
             my $thiskey=$2;
-            next if ($cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny');
+            my ($altkey,$recursive,$tkey,$tkeyrec,$tkeynonrec);
+            next if ($cmd eq 'rec' || $cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny');
+            if ((($cmd eq 'set') || ($cmd eq 'datepointer') || ($cmd eq 'dateinterval') || ($cmd eq 'del')) && 
+                 ($thiskey =~ /(?:sequence|page)\Q___(all)\E/)) {
+                unless ($thiskey =~ /(encrypturl|hiddenresource)$/) {
+                    $altkey = $thiskey;
+                    $altkey =~ s/\Q___(all)\E/___(rec)/;
+                    if ($env{'form.rec_'.$thiskey}) {
+                        $recursive = 1;
+                    }
+                }
+            }
             my ($tuname,$tudom)=&extractuser($thiskey);
-            my $tkey=$thiskey;
             if ($tuname) {
+                $tkey=$thiskey;
                 $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
+                if ($altkey) {
+                    $tkeynonrec = $tkey; 
+                    $tkeyrec = $altkey;
+                    $tkeyrec=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
+                }
             }
             if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
                 my ($data, $typeof, $text, $name, $valchk, $valmatch, $namematch);
@@ -3720,7 +3742,7 @@
                     $typeof=$env{'form.typeof_'.$thiskey};
                     $text = &mt('Saved modified date for');
                 }
-                if ($thiskey =~ m{\.(?:sequence|page)___\(rec\)}) {
+                if ($recursive) {
                     $namematch = 'maplevelrecurse';
                 }
                 if (($name ne '') || ($namematch ne '')) {
@@ -3767,54 +3789,195 @@
                         next;
                     }
                 }
-                if (defined($data) and $$olddata{$thiskey} ne $data) {
-                    if ($tuname) {
-                        if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
-                                            $tkey.'.type' => $typeof},
-                                    $tudom,$tuname) eq 'ok') {
-                            &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
-                            $r->print('<br />'.$text.' '.
-                                &Apache::loncommon::plainname($tuname,$tudom));
+                my ($reconlychg,$haschange,$storekey);
+                if ($tuname) {
+                    my $ustorekey;
+                    if ($altkey) {
+                        if ($recursive) {
+                            if (exists($$olddata{$thiskey})) {
+                                if ($$olddata{$thiskey} eq $data) {
+                                    $reconlychg = 1;
+                                }
+                                &Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname);
+                            }
+                            if (exists($$olddata{$altkey})) {
+                                if (defined($data) && $$olddata{$altkey} ne $data) {
+                                    $haschange = 1;
+                                }
+                            } elsif ((!$reconlychg) && ($data ne '')) {
+                                $haschange = 1;
+                            }
+                            $ustorekey = $tkeyrec;
+                        } else {
+                            if (exists($$olddata{$altkey})) {
+                                if ($$olddata{$altkey} eq $data) {
+                                    $reconlychg = 1;
+                                }
+                                &Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname);
+                            }
+                            if (exists($$olddata{$thiskey})) {
+                                if (defined($data) && $$olddata{$thiskey} ne $data) {
+                                    $haschange = 1;
+                                }
+                            } elsif ((!$reconlychg) && ($data ne '')) {
+                                $haschange = 1;
+                            }
+                            $ustorekey = $tkeynonrec;
+                        }
+                    } else {
+                        if (exists($$olddata{$tkey})) {
+                            if (defined($data) && $$olddata{$tkey} ne $data) {
+                                $haschange = 1;
+                            }
+                            $ustorekey = $tkey;
+                        }
+                    }
+                    if ($haschange || $reconlychg)  {
+                        unless ($env{'form.del_'.$thiskey}) {
+                            if (&Apache::lonnet::put('resourcedata',{$ustorekey=>$data,
+                                                                     $ustorekey.'.type' => $typeof},
+                                                                     $tudom,$tuname) eq 'ok') {
+                                &log_parmset({$ustorekey=>$data,$ustorekey.'.type' => $typeof},0,$tuname,$tudom);
+                                $r->print('<br />'.$text.' '.
+                                          &Apache::loncommon::plainname($tuname,$tudom));
+                            } else {
+                                $r->print('<div class="LC_error">'.
+                                          &mt('Error saving parameters').'</div>');
+                            }
+                            &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
+                        }
+                    }
+                } else {
+                    if ($altkey) {
+                        if ($recursive) {
+                            if (exists($$olddata{$thiskey})) {
+                                if ($$olddata{$thiskey} eq $data) {
+                                    $reconlychg = 1;
+                                }
+                                push(@delnonrec,($thiskey,$thiskey.'.type'));
+                            }
+                            if (exists($$olddata{$altkey})) {
+                                if (defined($data) && $$olddata{$altkey} ne $data) {
+                                    $haschange = 1;
+                                }
+                            } elsif (($data ne '') && (!$reconlychg)) {
+                                $haschange = 1;
+                            }
+                            $storekey = $altkey;
                         } else {
-                            $r->print('<div class="LC_error">'.
-                                &mt('Error saving parameters').'</div>');
+                            if (exists($$olddata{$altkey})) {
+                                if ($$olddata{$altkey} eq $data) {
+                                    $reconlychg = 1;
+                                }
+                                push(@delrec,($altkey,$altkey.'.type'));
+                            } 
+                            if (exists($$olddata{$thiskey})) {
+                                if (defined($data) && $$olddata{$thiskey} ne $data) {
+                                    $haschange = 1;
+                                }
+                            } elsif (($data ne '') && (!$reconlychg)) {
+                                $haschange = 1;
+                            }
+                            $storekey = $thiskey;
                         }
-                        &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
                     } else {
-                        $newdata{$thiskey}=$data;
-                        $newdata{$thiskey.'.type'}=$typeof;
+                        if (defined($data) && $$olddata{$thiskey} ne $data) {
+                            $haschange = 1;
+                            $storekey = $thiskey;
+                        }
+                    }
+                }
+                if ($reconlychg || $haschange) {
+                    unless ($env{'form.del_'.$thiskey}) {
+                        $newdata{$storekey}=$data;
+                        $newdata{$storekey.'.type'}=$typeof;
                     }
                 }
             } elsif ($cmd eq 'del') {
                 if ($tuname) {
-                    if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
-                            &log_parmset({$tkey=>''},1,$tuname,$tudom);
-                        $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
+                    my $error;
+                    if ($altkey) {  
+                        if (exists($$olddata{$altkey})) {
+                            if (&Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname) eq 'ok') {
+                                &log_parmset({$tkeyrec=>''},1,$tuname,$tudom);
+                                if ($recursive) {
+                                    $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
+                                }
+                            } elsif ($recursive) {
+                                $error = 1;
+                            }
+                        }
+                        if (exists($$olddata{$thiskey})) {
+                            if (&Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname) eq 'ok') {
+                                &log_parmset({$tkeynonrec=>''},1,$tuname,$tudom);
+                                unless ($recursive) {
+                                    $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
+                                }
+                            } elsif (!$recursive) {
+                                $error = 1;
+                            }
+                        }
                     } else {
+                        if (exists($$olddata{$thiskey})) {
+                            if (&Apache::lonnet::del('resourcedata',[$tkey,$tkey.'.type'],$tudom,$tuname) eq 'ok') {
+                                &log_parmset({$tkey=>''},1,$tuname,$tudom);
+                                $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
+                            } else {
+                                $error = 1;
+                            }
+                        }
+                    }
+                    if ($error) { 
                         $r->print('<div class="LC_error">'.
                             &mt('Error deleting parameters').'</div>');
                     }
                     &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
                 } else {
-                    push (@deldata,$thiskey,$thiskey.'.type');
+                    if ($altkey) {
+                        if (exists($$olddata{$altkey})) {
+                            unless (grep(/^\Q$altkey\E$/, at delrec)) {
+                                push(@deldata,($altkey,$altkey.'.type'));
+                            }
+                        }
+                        if (exists($$olddata{$thiskey})) {
+                            unless (grep(/^\Q$thiskey\E$/, at delnonrec)) {
+                                push(@deldata,($thiskey,$thiskey.'.type'));
+                            }
+                        }
+                    } elsif (exists($$olddata{$thiskey})) {
+                        push(@deldata,($thiskey,$thiskey.'.type'));
+                    }
                 }
             }
         }
     }
 # Store all course level
     my $delentries=$#deldata+1;
+    my @alldels;
+    if (@delrec) {
+        push(@alldels, at delrec);
+    }
+    if (@delnonrec) {
+        push(@alldels, at delnonrec);
+    }
+    if (@deldata) {
+        push(@alldels, at deldata);
+    }
     my @newdatakeys=keys(%newdata);
     my $putentries=$#newdatakeys+1;
-    if ($delentries) {
-        if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
-            my %loghash=map { $_ => '' } @deldata;
+    my ($delresult,$devalidate);
+    if (@alldels) {
+        if (&Apache::lonnet::del('resourcedata',\@alldels,$dom,$crs) eq 'ok') {
+            my %loghash=map { $_ => '' } @alldels;
             &log_parmset(\%loghash,1);
-            $r->print('<h2>'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'</h2>');
-        } else {
+            if ($delentries) {
+                $r->print('<h2>'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'</h2>');
+            }
+        } elsif ($delentries) {
             $r->print('<div class="LC_error">'.
                 &mt('Error deleting parameters').'</div>');
         }
-        &Apache::lonnet::devalidatecourseresdata($crs,$dom);
+        $devalidate = 1; 
     }
     if ($putentries) {
         if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
@@ -3824,6 +3987,9 @@
             $r->print('<div class="LC_error">'.
                 &mt('Error saving parameters').'</div>');
         }
+        $devalidate = 1; 
+    }
+    if ($devalidate) {
         &Apache::lonnet::devalidatecourseresdata($crs,$dom);
     }
 }
@@ -3895,7 +4061,7 @@
         }
     }
 
-    foreach my $thiskey (sort {
+    foreach my $key (sort {
         my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
         my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
 
@@ -3935,8 +4101,8 @@
 
         $result;
         
-    } keys(%{$listdata})) { # foreach my $thiskey
-
+    } keys(%{$listdata})) { # foreach my $key
+        my $thiskey = $key;
         if ($$listdata{$thiskey.'.type'}) {
             my $thistype=$$listdata{$thiskey.'.type'};
             if ($$resourcedata{$thiskey.'.type'}) {
@@ -3945,6 +4111,7 @@
             my ($middle,$part,$name)=
                 ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
             my $section=&mt('All Students');
+            my $showval = $$resourcedata{$thiskey}; 
             if ($middle=~/^\[(.*)\]/) {
                 my $issection=$1;
                 if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
@@ -3977,12 +4144,37 @@
             $middle=~s/\.+$//;
             $middle=~s/^\.+//;
             my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
-            if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
-                my $mapurl = $1;
-                my $maplevel = $2;
+            my ($is_map,$is_recursive,$mapurl,$maplevel);
+            if ($caller eq 'overview') {
+                if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
+                    $mapurl = $1;
+                    $maplevel = $2;
+                    $is_map = 1;
+                }
+            } elsif ($caller eq 'newoverview') {
+                if ($middle=~/^(.+)\_\_\_\((all)\)$/) {
+                    $mapurl = $1;
+                    $maplevel = $2;
+                    $is_map = 1;
+                }
+            }
+            if ($is_map) {
                 my $leveltitle = &mt('Folder/Map');
-                if ($maplevel eq 'rec') {
-                    $leveltitle = &mt('Recursive');
+                unless (($name eq 'hiddenresource') || ($name eq 'encrypturl')) {   
+                    if ($caller eq 'newoverview') {
+                        my $altkey = $thiskey;
+                        $altkey =~ s/\Q___(all)\E/___(rec)/;
+                        if ((exists($$resourcedata{$altkey})) & (!exists($$resourcedata{$thiskey}))) {
+                            $is_recursive = 1;
+                            if ($$resourcedata{$altkey.'.type'}) {
+                                $thistype=$$resourcedata{$altkey.'.type'};
+                            }
+                            $showval = $$resourcedata{$altkey};
+                        }
+                    } elsif (($caller eq 'overview') && ($maplevel eq 'rec')) {
+                        $thiskey =~ s/\Q___(rec)\E/___(all)/;
+                        $is_recursive = 1;
+                    }
                 }
                 $realm='<span class="LC_parm_scope_folder">'.$leveltitle.': '.&Apache::lonnet::gettitle($mapurl).' <br /><span class="LC_parm_folder">('.$mapurl.')</span></span>';
             } elsif ($middle) {
@@ -4024,7 +4216,7 @@
     # Ready to print
     #
             my $parmitem = &standard_parameter_names($name);
-            $r->print(&tablestart($readonly).
+            $r->print(&tablestart($readonly,$is_map).
                 &Apache::loncommon::start_data_table_row().
                 '<td><b>'.&mt($parmitem).
                 '</b></td>');
@@ -4044,30 +4236,48 @@
                 $r->print(
                     &Apache::lonhtmlcommon::date_setter('parmform',
                                                         $jskey,
-                                                        $$resourcedata{$thiskey},
+                                                        $showval,
                                                         '',1,$state));
                 unless  ($readonly) {
                     $r->print(
     '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
-    (($$resourcedata{$thiskey}!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$$resourcedata{$thiskey}.'">'.
+    (($showval!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$showval.'">'.
     &mt('Shift all dates based on this date').'</a></span>':'').
-    &date_sanity_info($$resourcedata{$thiskey})
+    &date_sanity_info($showval)
                     );
                 }
             } elsif ($thistype eq 'date_interval') {
                 $r->print(&date_interval_selector($thiskey,$name,
-                        $$resourcedata{$thiskey},$readonly));
+                          $showval,$readonly));
             } elsif ($thistype =~ m/^string/) {
                 $r->print(&string_selector($thistype,$thiskey,
-                        $$resourcedata{$thiskey},$name,$readonly));
+                          $showval,$name,$readonly));
             } else {
-                $r->print(&default_selector($thiskey,$$resourcedata{$thiskey},$readonly));
+                $r->print(&default_selector($thiskey,$showval,$readonly));
             }
             unless ($readonly) {
                 $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
                         $thistype.'" />');
             }
-            $r->print('</td>'.&Apache::loncommon::end_data_table_row());
+            $r->print('</td>');
+            if ($is_map) {
+                if (($name eq 'encrypturl') || ($name eq 'hiddenresource')) {
+                    $r->print('<td><table><tr><td>'.&mt('Yes').'</td></tr></table></td>');
+                } else {
+                    my ($disabled,$recon,$recoff);
+                    if ($readonly) {
+                        $disabled = ' disabled="disabled"';
+                    }
+                    if ($is_recursive) {
+                        $recon = ' checked="checked"';
+                    } else {
+                        $recoff = ' checked="checked"';
+                    }
+                    $r->print('<td><table><tr><td><label><input type="radio" name="rec_'.$thiskey.'" value="1"'.$recon.$disabled.' />'.&mt('Yes').'</label>'.
+                              '</td><td><label><input type="radio" name="rec_'.$thiskey.'" value="0"'.$recoff.$disabled.' />'.&mt('No').'</label></td></tr></table></td>');
+                }
+            }
+            $r->print(&Apache::loncommon::end_data_table_row());
         }
     }
     return $foundkeys;
@@ -4941,9 +5151,6 @@
                     my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
                     $$listdata{$newparmkey}=1;
                     $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
-                    $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(rec).'.$part.'.'.$cat;
-                    $$listdata{$newparmkey}=1;
-                    $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
                 }
             } else {
 # resource-level parameter


More information about the LON-CAPA-cvs mailing list