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

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 08 Dec 2006 00:29:02 -0000


raeburn		Thu Dec  7 19:29:02 2006 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm 
  Log:
  Bugs 1402 and 4309.
  
  When a discussion posting is hidden or deleted, if that post was the last discussion item, then the entry in discussiontimes.db for the resource is set back to the timestamp of the most recent unhidden or undeleted post.
  
  
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.230 loncom/interface/lonfeedback.pm:1.231
--- loncom/interface/lonfeedback.pm:1.230	Wed Dec  6 14:06:40 2006
+++ loncom/interface/lonfeedback.pm	Thu Dec  7 19:28:59 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.230 2006/12/06 19:06:40 albertel Exp $
+# $Id: lonfeedback.pm,v 1.231 2006/12/08 00:28:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -107,7 +107,7 @@
 	$crs.='_'.$env{'request.course.sec'};
     }
     $crs=~s/\_/\//g;
-    unless ($ressymb) {	$ressymb=&Apache::lonnet::symbread(); }
+    unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
     unless ($ressymb) { return ''; }
     $ressymb=&wrap_symb($ressymb);
     my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
@@ -2816,10 +2816,11 @@
 	$contrib{'anonymous'}='true';
     }
     if (($symb) && ($email)) {
+        my $now = time;
         if ($env{'form.editdisc'}) {
             $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
             $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
-            $contrib{'timestamp'} = time;
+            $contrib{'timestamp'} = $now;
             $contrib{'history'} = '';
             my $numoldver = 0;
             my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
@@ -2870,7 +2871,7 @@
                      $env{'course.'.$env{'request.course.id'}.'.domain'},
 		     $env{'course.'.$env{'request.course.id'}.'.num'});
         }
-        my %storenewentry=($symb => time);
+        my %storenewentry=($symb => $now);
         $status.='<br />'.&mt('Updating discussion time').': '.
         &Apache::lonnet::put('discussiontimes',\%storenewentry,
                      $env{'course.'.$env{'request.course.id'}.'.domain'},
@@ -2891,6 +2892,48 @@
     return $status.'<br />';   
 }
 
+sub get_discussion_info {
+    my ($idx,%contrib) = @_;
+    my $changelast = 0;
+    my $count = 0;
+    my $hiddenflag = 0;
+    my $deletedflag = 0;
+    my ($hidden,$deleted,%info,$newlastdisc);
+    my $version = $contrib{'version'};
+    if ($version) {
+        for (my $id=$version; $id>0; $id--) {
+            my $vkeys=$contrib{$id.':keys'};
+            my @keys=split(/:/,$vkeys);
+            if (grep(/^hidden$/,@keys)) {
+                if (!$hiddenflag) {
+                    $hidden = $contrib{$id.':hidden'};
+                    $hiddenflag = 1;
+                }
+            } elsif (grep(/^deleted$/,@keys)) {
+                if (!$deletedflag) {
+                    $deleted = $contrib{$id.':deleted'};
+                    $deletedflag = 1;
+                }
+            } else {
+                if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
+                    $count++;
+                    $info{$count}{'id'} = $id;
+                    $info{$count}{'timestamp'}=$contrib{$id.':timestamp'}; 
+                }
+            }
+        }
+        if ($info{'1'}{'id'} == $idx) {
+            $changelast = 1;
+            if ($count > 1) { 
+                $newlastdisc =  $info{'2'}{'timestamp'};
+            } else {
+                $newlastdisc = 0;
+            }
+        }
+    }
+    return ($changelast,$newlastdisc);
+}
+
 # ----------------------------------------------------------- Preview function
 
 sub show_preview {
@@ -3559,7 +3602,16 @@
       if ( ($env{'form.hide'}) && (!$seeid) ) {
 	  $newhash{'studenthidden'} = $currentstudenthidden;
       }
-
+      if ($env{'form.hide'}) {
+          my $changelast = 0;
+          my $newlast;
+          ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
+          if ($changelast) {
+              &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
+                     $env{'course.'.$env{'request.course.id'}.'.domain'},
+                     $env{'course.'.$env{'request.course.id'}.'.num'});
+          }
+      }
       &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
                            $env{'course.'.$env{'request.course.id'}.'.domain'},
 			   $env{'course.'.$env{'request.course.id'}.'.num'});
@@ -3588,6 +3640,11 @@
       my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                           $env{'course.'.$env{'request.course.id'}.'.domain'},
 		          $env{'course.'.$env{'request.course.id'}.'.num'});
+      my ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
+      if ($changelast) {
+          &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
+                   $env{'course.'.$env{'request.course.id'}.'.domain'},                   $env{'course.'.$env{'request.course.id'}.'.num'});
+      }
       my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
       &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
 			   $env{'course.'.$env{'request.course.id'}.'.domain'},