Diff for /loncom/interface/lonfeedback.pm between versions 1.322 and 1.327

version 1.322, 2012/01/05 21:18:49 version 1.327, 2012/01/07 03:01:11
Line 827  sub action_links_bar { Line 827  sub action_links_bar {
         $discussion .= '&previous='.$prevread;          $discussion .= '&previous='.$prevread;
     }      }
     $discussion .= &group_args($group);      $discussion .= &group_args($group);
     $discussion .= '">'.&mt('Export').'</a></td>';      $discussion .= '">'.&mt('Export').'</a>';
       if (&Apache::lonnet::allowed('rin',$env{'request.course.id'})) {
           $discussion .= '&nbsp;&nbsp;';
           $discussion .='<a href="/adm/feedback?undeleteall='.$escsymb;
           if ($newpostsflag) {
               $discussion .= '&amp;previous='.$prevread;
           }
           $discussion .= &group_args($group);
           $discussion .= '">'.&mt('Undelete all deleted entries').'</a>';
       }
       $discussion.='</td>';
     if ($newpostsflag) {      if ($newpostsflag) {
         if (!$markondisp) {          if (!$markondisp) {
             $discussion .='<td class="LC_disc_action_right"><a href="/adm/preferences?action=changediscussions';              $discussion .='<td class="LC_disc_action_right"><a href="/adm/preferences?action=changediscussions';
Line 931  sub build_posting_display { Line 941  sub build_posting_display {
     my $skip_group_check = 0;      my $skip_group_check = 0;
     my $symb=&Apache::lonenc::check_decrypt($ressymb);      my $symb=&Apache::lonenc::check_decrypt($ressymb);
     my $escsymb=&escape($ressymb);      my $escsymb=&escape($ressymb);
   # These are the discussion contributions
     my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},      my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
   $env{'course.'.$env{'request.course.id'}.'.domain'},    $env{'course.'.$env{'request.course.id'}.'.domain'},
   $env{'course.'.$env{'request.course.id'}.'.num'});    $env{'course.'.$env{'request.course.id'}.'.num'});
   # And these are the likes/unlikes
     my %likes=&Apache::lonnet::dump('disclikes',      my %likes=&Apache::lonnet::dump('disclikes',
                           $env{'course.'.$env{'request.course.id'}.'.domain'},                            $env{'course.'.$env{'request.course.id'}.'.domain'},
                           $env{'course.'.$env{'request.course.id'}.'.num'},                            $env{'course.'.$env{'request.course.id'}.'.num'},
                           '^'.$symb.':');                            '^'.$symb.':');
     my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};      my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
   # Array with likes to figure out averages, etc.
       my @theselikes=();
   # Is the user allowed to see the real name behind anonymous postings?
     my $see_anonymous =       my $see_anonymous = 
  &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));   &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
   
     if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {      if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {
         $skip_group_check = 1;          $skip_group_check = 1;
     }      }
   # Deletions and hiddens are just lists. Split them up into a hash for quicker lookup
     my (%deletions,%hiddens);      my (%deletions,%hiddens);
     if ($contrib{'deleted'}) {      if ($contrib{'deleted'}) {
        my $deleted = $contrib{'deleted'};         my $deleted = $contrib{'deleted'};
Line 959  sub build_posting_display { Line 974  sub build_posting_display {
        $hidden =~ s/\.$//;         $hidden =~ s/\.$//;
        %hiddens = map { $_ => 1 } (split(/\.\./,$hidden));         %hiddens = map { $_ => 1 } (split(/\.\./,$hidden));
     }      }
   # Versions if store/restore are used to actually store the messages. 
     if ($contrib{'version'}) {      if ($contrib{'version'}) {
         my $oldest = $contrib{'1:timestamp'};          my $oldest = $contrib{'1:timestamp'};
         if ($prevread eq '0') {          if ($prevread eq '0') {
Line 969  sub build_posting_display { Line 985  sub build_posting_display {
             ($skiptest,$roleregexp,$secregexp,$statusregexp) =               ($skiptest,$roleregexp,$secregexp,$statusregexp) = 
                      &filter_regexp($rolefilter,$sectionpick,$statusfilter);                       &filter_regexp($rolefilter,$sectionpick,$statusfilter);
             $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;              $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
         }           }
   # We need to go through this twice, first to get the likes/dislikes, then to actually build the display
           for (my $id=1;$id<=$contrib{'version'};$id++) {
               my $idx=$id;
               next if ($contrib{$idx.':deleted'});
               next if ($contrib{$idx.':hidden'});
               unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
                   push(@theselikes,$likes{$symb.':'.$idx.':likes'});
               }
           }
   # Figure out average likes and standard deviation if there are enough discussions to warrant that
           my $ave=0;
           my $stddev=10000;
           if ($#theselikes>1) {
               my $sum=0;
               my $num=$#theselikes+1;
               foreach my $thislike (@theselikes) {
                   $sum+=$thislike;
               }
               $ave=$sum/$num;
               my $sumsq=0;
               foreach my $thislike (@theselikes) {
                   $sumsq+=($thislike-$ave)*($thislike-$ave);
               }
               $stddev=sqrt($sumsq/$num);
           }
   # Now we know the average likes $ave and the standard deviation $stddev
   # Get the boundaries for markup
           my $oneplus=$ave+$stddev;
           my $twoplus=$ave+2.*$stddev;
           my $oneminus=$ave-$stddev;
           my $twominus=$ave-2.*$stddev;
   #            &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev $twominus $oneminus $oneplus $twoplus");
   #
   # This is now the real loop. Go through all entries, pick up what we need
   # 
  for (my $id=1;$id<=$contrib{'version'};$id++) {   for (my $id=1;$id<=$contrib{'version'};$id++) {
     my $idx=$id;      my $idx=$id;
             next if ($contrib{$idx.':deleted'});              next if ($contrib{$idx.':deleted'});
             next if ($contrib{$idx.':hidden'});              next if ($contrib{$idx.':hidden'});
   # If we get here, we are actually going to display the message - we don't know where and we don't know if we display
   # previous edits, but it counts as one entry
             my $posttime = $contrib{$idx.':timestamp'};              my $posttime = $contrib{$idx.':timestamp'};
             if ($prevread <= $posttime) {              if ($prevread <= $posttime) {
                 $$newpostsflag = 1;                  $$newpostsflag = 1;
Line 1107  sub build_posting_display { Line 1160  sub build_posting_display {
                                 unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {                                  unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {
                                     $sender.='&nbsp;'.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group));                                      $sender.='&nbsp;'.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group));
                                 }                                  }
                                   my $thislikes=$likes{$symb.':'.$idx.':likes'};
                                   if ($thislikes>0) { 
                                       $sender.='&nbsp;('.&mt("[_1] likes",$thislikes).')';
                                   } elsif ($thislikes<0) {
                                       $sender.='&nbsp;('.&mt("[_1] unlikes",abs($thislikes)).')';
                                   }
                                 if (&editing_allowed($escsymb.':::'.$idx,$group)) {                                  if (&editing_allowed($escsymb.':::'.$idx,$group)) {
                                     if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {                                      if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
                                         $sender.=' '.                                          $sender.=' '.
Line 1289  sub build_posting_display { Line 1348  sub build_posting_display {
                             if ($$dischash{$toggkey}) {                              if ($$dischash{$toggkey}) {
                                 $$discussionitems[$idx].='&nbsp;&nbsp;'.$ctlink;                                  $$discussionitems[$idx].='&nbsp;&nbsp;'.$ctlink;
                             }                              }
   # Figure out size based on likes
                               my $thislikes=$likes{$symb.':'.$idx.':likes'};
                               my $likesize="100";
                               if ($thislikes>$twoplus) {
                                   $likesize="200";
                               } elsif ($thislikes>$oneplus) {
                                   $likesize="150";
                               }
                               if ($thislikes<$twominus) {
                                   $likesize="50";
                               } elsif ($thislikes<$oneminus) {
                                   $likesize="75";
                               }
                             $$discussionitems[$idx].= '<br /><blockquote>'.                              $$discussionitems[$idx].= '<br /><blockquote>'.
                                     $message.'</blockquote>';                                      "<div style='font-size:$likesize%'>".
                                       $message.
                                       '</div></blockquote>';
                             if ($contrib{$idx.':history'}) {                              if ($contrib{$idx.':history'}) {
                                 my @postversions = ();                                  my @postversions = ();
                                 $$discussionitems[$idx] .= &mt('This post has been edited by the author.');                                  $$discussionitems[$idx] .= &mt('This post has been edited by the author.');
Line 1309  sub build_posting_display { Line 1383  sub build_posting_display {
                                     $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).'  ';                                      $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).'  ';
                                 }                                  }
                             }                              }
   # end of unless ($$notshown ...)
                         }                          }
   # end of if ($message) ...
                     }                      }
   # end of the else-branch of target being export
                 }                  }
   # end of unless hidden or deleted
             }              }
   # end of the loop over all discussion entries
  }   }
   # end of "if there actually are any discussions
     }      }
   # end of subroutine "build_posting_display" 
 }  }
   
 sub filter_regexp {  sub filter_regexp {
Line 3571  sub handler { Line 3652  sub handler {
 # --------------------------- Get query string for limited number of parameters  # --------------------------- Get query string for limited number of parameters
   
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
          ['like','unlike','modal','hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);           ['like','unlike','modal','hide','unhide','deldisc','undeleteall','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);
   my $group = $env{'form.group'};    my $group = $env{'form.group'};
   my %attachmax = (    my %attachmax = (
                     text => &mt('(128 KB max size)'),                      text => &mt('(128 KB max size)'),
Line 3851  ENDREDIR Line 3932  ENDREDIR
       my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'};        my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'};
       my ($symb,$idx)=split(/\:\:\:/,$entry);        my ($symb,$idx)=split(/\:\:\:/,$entry);
       ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);        ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
   #
   # Likes and unlikes are in db-file "disclikes" of the course
   # The prefix is the $symb to identify the resource discussion,
   # and the $idx to identify the entry
   #
       my $prefix=$symb.':'.$idx.':';        my $prefix=$symb.':'.$idx.':';
       my %contrib=&Apache::lonnet::dump('disclikes',        my %contrib=&Apache::lonnet::dump('disclikes',
                                         $env{'course.'.$env{'request.course.id'}.'.domain'},                                          $env{'course.'.$env{'request.course.id'}.'.domain'},
Line 3859  ENDREDIR Line 3945  ENDREDIR
 # Get all who like or unlike this  # Get all who like or unlike this
       my $currentlikers=$contrib{$prefix.'likers'};        my $currentlikers=$contrib{$prefix.'likers'};
       my $currentunlikers=$contrib{$prefix.'unlikers'};        my $currentunlikers=$contrib{$prefix.'unlikers'};
   # Get the current "likes" count
       my $likes=$contrib{$prefix.'likes'};        my $likes=$contrib{$prefix.'likes'};
 # Find out if they already voted  # Find out if they already voted
   # Users cannot like a post twice, or unlike it twice. They can change their mind, though
       my $alreadyflag=0;        my $alreadyflag=0;
       my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};        my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
       if ($env{'form.like'}) {        if ($env{'form.like'}) {
Line 3868  ENDREDIR Line 3956  ENDREDIR
               $alreadyflag=1;                $alreadyflag=1;
           } else {            } else {
               if ($currentunlikers=~/\,\Q$thisuser\E\,/) {                if ($currentunlikers=~/\,\Q$thisuser\E\,/) {
                   $currentunlikers=~s/\,\Q$thisuser\E\,//;                    $currentunlikers=~s/\,\Q$thisuser\E\,//g;
               } else {                } else {
                   $currentlikers.=','.$thisuser.',';                    $currentlikers.=','.$thisuser.',';
               }                }
Line 3879  ENDREDIR Line 3967  ENDREDIR
               $alreadyflag=1;                $alreadyflag=1;
           } else {            } else {
               if ($currentlikers=~/\,\Q$thisuser\E\,/) {                if ($currentlikers=~/\,\Q$thisuser\E\,/) {
                   $currentlikers=~s/\,\Q$thisuser\E\,//;                    $currentlikers=~s/\,\Q$thisuser\E\,//g;
               } else {                } else {
                   $currentunlikers.=','.$thisuser.',';                    $currentunlikers.=','.$thisuser.',';
               }                }
Line 3887  ENDREDIR Line 3975  ENDREDIR
           }             } 
       }        }
       my $result;        my $result;
   # $alreadyflag would be 1 if they tried to double-like or double-unlike
       unless ($alreadyflag) {        unless ($alreadyflag) {
           my %newhash=($prefix.'likes'    => $likes,            my %newhash=($prefix.'likes'    => $likes,
                        $prefix.'likers'   => $currentlikers,                         $prefix.'likers'   => $currentlikers,
                        $prefix.'unlikers' => $currentunlikers);                         $prefix.'unlikers' => $currentunlikers);
   # Store data in db-file "disclikes"
           if (&Apache::lonnet::put('disclikes',            if (&Apache::lonnet::put('disclikes',
                                    \%newhash,                                     \%newhash,
                                    $env{'course.'.$env{'request.course.id'}.'.domain'},                                     $env{'course.'.$env{'request.course.id'}.'.domain'},
                                    $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {                                     $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
   # Also store with the person who posted the liked/unliked entry
               if ($env{'form.like'}) {                if ($env{'form.like'}) {
                   &storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});                    &storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
                   $result=&mt("Registered 'Like'");                    $result=&mt("Registered 'Like'");
Line 3903  ENDREDIR Line 3994  ENDREDIR
                   $result=&mt("Registered 'Unlike'");                    $result=&mt("Registered 'Unlike'");
               }                }
           } else {            } else {
   # Oops, something went wrong
               $result=&mt("Failed to register vote");                $result=&mt("Failed to register vote");
           }            }
       }        }
Line 3993  ENDREDIR Line 4085  ENDREDIR
   &Apache::loncommon::end_page();    &Apache::loncommon::end_page();
       $r->print($start_page.$discussion.$end_page);        $r->print($start_page.$discussion.$end_page);
       return OK;        return OK;
   
     } elsif ($env{'form.undeleteall'}) {
         &Apache::loncommon::content_type($r,'text/html');
         $r->send_http_header;
         my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.undeleteall'});
         $r->print(&Apache::loncommon::start_page('Undelete all deleted discussion entries'));
         if (&Apache::lonnet::allowed('rin',$env{'request.course.id'})) {
              if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'},
                        $env{'course.'.$env{'request.course.id'}.'.domain'},
                        $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                  $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries")));
              } else {
                  $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1));
              }
              $r->print("<br /><a href='$feedurl'>".&mt("Return and reload")."</a>");
         }
         $r->print(&Apache::loncommon::end_page());
         return OK;
   } else {    } else {
 # ------------------------------------------------------------- Normal feedback  # ------------------------------------------------------------- Normal feedback
       my $feedurl=$env{'form.postdata'};        my $feedurl=$env{'form.postdata'};

Removed from v.1.322  
changed lines
  Added in v.1.327


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>