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

version 1.327, 2012/01/07 03:01:11 version 1.334, 2012/01/10 20:06:07
Line 759  END Line 759  END
   
   
 sub discussion_link {  sub discussion_link {
    my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds)=@_;     my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title)=@_;
    my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item;     my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item;
    if ($flag) { $link .= '&previous='.$prev; }     if ($flag) { $link .= '&previous='.$prev; }
    if ($adds) { $link .= $adds; }     if ($adds) { $link .= $adds; }
Line 769  sub discussion_link { Line 769  sub discussion_link {
        $width=300;         $width=300;
        $height=200;         $height=200;
    }     }
    return &Apache::loncommon::modal_link($link,$linktext,$width,$height);     return &Apache::loncommon::modal_link($link,$linktext,$width,$height,undef,undef,$title);
 }  }
   
   
Line 787  sub send_feedback_link { Line 787  sub send_feedback_link {
 sub send_message_link {  sub send_message_link {
     my ($ressymb) = @_;      my ($ressymb) = @_;
     my $output = '<span class="LC_message_link">'.      my $output = '<span class="LC_message_link">'.
                  '  <a href="/adm/feedback?sendmessageonly=1&amp;symb='.                   &discussion_link($ressymb,
                  &escape($ressymb).'"><img alt="" class="LC_noBorder" src="'.                      '<img alt="" class="LC_noBorder" src="'.
                  &Apache::loncommon::lonhttpdurl('/res/adm/pages/feedback.png').                      &Apache::loncommon::lonhttpdurl('/res/adm/pages/feedback.png').
                  '" border="0" /><span class="LC_menubuttons_inline_text">'.&mt('Send Feedback').'</span></a></span>';                      '" border="0" /><span class="LC_menubuttons_inline_text">'.&mt('Send Feedback').'</span>',
                       'sendmessageonly').
                    '</span>';
     return $output;      return $output;
 }  }
   
Line 886  sub postingform_display { Line 888  sub postingform_display {
 <input type="submit" name="anondiscuss" value="$lt{'poan'}" /> <input type="hidden" name="symb" value="$ressymb" />  <input type="submit" name="anondiscuss" value="$lt{'poan'}" /> <input type="hidden" name="symb" value="$ressymb" />
 <input type="hidden" name="sendit" value="true" />  <input type="hidden" name="sendit" value="true" />
 <input type="hidden" name="timestamp" value="$now" />  <input type="hidden" name="timestamp" value="$now" />
 <br /><a name="newpost"></a>  <a name="newpost"></a>
 <font size="1">$lt{'note'}</font><br />  <font size="1">$lt{'note'}</font><br />
 <b>$lt{'title'}:</b>&nbsp;<input type="text" name="subject" value="$subject" size="30" /><br /><br />  <b>$lt{'title'}:</b>&nbsp;<input type="text" name="subject" value="$subject" size="30" /><br />
 <textarea name="comment" cols="80" rows="14" id="comment" $textareaclass>$comment</textarea>  <textarea name="comment" cols="80" rows="14" id="comment" $textareaclass>$comment</textarea>
 ENDDISCUSS  ENDDISCUSS
     if ($env{'form.origpage'}) {      if ($env{'form.origpage'}) {
Line 1017  sub build_posting_display { Line 1019  sub build_posting_display {
         my $twoplus=$ave+2.*$stddev;          my $twoplus=$ave+2.*$stddev;
         my $oneminus=$ave-$stddev;          my $oneminus=$ave-$stddev;
         my $twominus=$ave-2.*$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  # This is now the real loop. Go through all entries, pick up what we need
 #   # 
Line 1154  sub build_posting_display { Line 1155  sub build_posting_display {
                                 @{$$namesort{$lastname}{$firstname}} = ("$idx");                                  @{$$namesort{$lastname}{$firstname}} = ("$idx");
                             }                              }
                             if ($outputtarget ne 'tex') {                              if ($outputtarget ne 'tex') {
                                 unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) {  # Add karma stars
                                     $sender.='&nbsp;'.&discussion_link($symb,&mt('Like'),'like',$idx,$$newpostsflag,$prevread,&group_args($group));                                  my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
                                 }                                  for (my $i=1;$i<=$karma;$i++) {
                                 unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {                                      $sender.='<img border="0" src="/res/adm/pages/star.gif" alt="'.&mt('Contributor Kudos').'" />';
                                     $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)).')';  
                                 }                                  }
   # Can people edit this?
                                 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 1361  sub build_posting_display { Line 1356  sub build_posting_display {
                             } elsif ($thislikes<$oneminus) {                              } elsif ($thislikes<$oneminus) {
                                 $likesize="75";                                  $likesize="75";
                             }                              }
   # Actually glue in the message itself
                             $$discussionitems[$idx].= '<br /><blockquote>'.                              $$discussionitems[$idx].= '<br /><blockquote>'.
                                     "<div style='font-size:$likesize%'>".                                      "<div style='font-size:$likesize%'>".
                                     $message.                                      $message.
                                     '</div></blockquote>';                                      '</div></blockquote>';
   # Put in the like and unlike buttons
                               unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) {
                                   $$discussionitems[$idx].='&nbsp;'.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
                               } else {
                                   $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';
                               }
                               unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {
                                   $$discussionitems[$idx].='&nbsp;'.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />',,'unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
                               } else {
                                   $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';
                               }
                               my $thislikes=$likes{$symb.':'.$idx.':likes'};
                               if ($thislikes>0) {
                                   $$discussionitems[$idx].='&nbsp;('.&mt("[_1] likes",$thislikes).')';
                               } elsif ($thislikes<0) {
                                   $$discussionitems[$idx].='&nbsp;('.&mt("[_1] unlikes",abs($thislikes)).')';
                               }
   # If there is any history to this post, inform the reader
                             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] .= '&nbsp;&nbsp;'.&mt('This post has been edited by the author.');
                                 if ($seeid) {                                  if ($seeid) {
                                     $$discussionitems[$idx] .= '&nbsp;&nbsp;'.                                      $$discussionitems[$idx] .= '&nbsp;&nbsp;'.
                                          &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group));                                           &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group));
Line 2681  sub no_redirect_back { Line 2695  sub no_redirect_back {
       'add_entries' => \%onload,);        'add_entries' => \%onload,);
   
   if ($feedurl !~ m{^/adm/feedback}) {     if ($feedurl !~ m{^/adm/feedback}) { 
       $body_options{'rediect'} = [2,$feedurl];        $body_options{'redirect'} = [2,$feedurl];
   }    }
   my $start_page=    my $start_page=
       &Apache::loncommon::start_page('Feedback not sent',undef,        &Apache::loncommon::start_page('Feedback not sent',undef,
Line 2723  sub screen_header { Line 2737  sub screen_header {
     unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {      unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
  if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {   if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
     $msgoptions=       $msgoptions= 
  '<p><label><input type="radio" name="discuss" value="author" /> '.   '<label><input type="radio" name="discuss" value="author" /> '.
  &mt('Feedback to resource author').'</label></p>';   &mt('Feedback to resource author').'</label><br />';
  }   }
         my %optionhash=();          my %optionhash=();
         foreach my $type ('question','comment','policy') {          foreach my $type ('question','comment','policy') {
Line 2732  sub screen_header { Line 2746  sub screen_header {
  }   }
  if (&feedback_available(1)) {   if (&feedback_available(1)) {
     $msgoptions.=      $msgoptions.=
  '<p><label><input type="radio" name="discuss" value="question" /> '.   '<label><input type="radio" name="discuss" value="question" /> '.
  ($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'</label></p>';   ($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'</label><br />';
  }   }
  if (&feedback_available(0,1)) {   if (&feedback_available(0,1)) {
     $msgoptions.=      $msgoptions.=
  '<p><label><input type="radio" name="discuss" value="course" /> '.   '<label><input type="radio" name="discuss" value="course" /> '.
  ($optionhash{'comment'}?$optionhash{'comment'}:$crscontent).   ($optionhash{'comment'}?$optionhash{'comment'}:$crscontent).
  '</label></p>';   '</label><br />';
  }   }
  if (&feedback_available(0,0,1)) {   if (&feedback_available(0,0,1)) {
     $msgoptions.=      $msgoptions.=
  '<p><label><input type="radio" name="discuss" value="policy" /> '.   '<label><input type="radio" name="discuss" value="policy" /> '.
  ($optionhash{'policy'}?$optionhash{'policy'}:$crspolicy).   ($optionhash{'policy'}?$optionhash{'policy'}:$crspolicy).
  '</label></p>';   '</label><br />';
  }   }
     }      }
     if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {      if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
Line 2933  sub storefeedbackpoints { Line 2947  sub storefeedbackpoints {
     my %record=('grader_user'   => $env{'user.name'},      my %record=('grader_user'   => $env{'user.name'},
                 'grader_domain' => $env{'user.domain'},                  'grader_domain' => $env{'user.domain'},
                 'points' => $points);                  'points' => $points);
     return &Apache::lonnet::cstore(\%record,'_feedback');      return &Apache::lonnet::cstore(\%record,'_feedback',$course,$udom,$uname);
 }  }
   
 # Store feedback "likes"  # Store feedback "likes"
Line 2953  sub storefeedbacklikes { Line 2967  sub storefeedbacklikes {
                    'likes_domain' => $env{'user.domain'},                     'likes_domain' => $env{'user.domain'},
                    'likes' => $likes,                     'likes' => $likes,
                    'totallikes' => $totallikes);                     'totallikes' => $totallikes);
     return &Apache::lonnet::cstore(\%newrecord,'_feedback');      return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname);
 }  }
   
   
Line 3063  sub adddiscuss { Line 3077  sub adddiscuss {
        $newrecord{'subnumber'}=$record{'subnumber'}+1;         $newrecord{'subnumber'}=$record{'subnumber'}+1;
        $status.='<br />'.&mt('Registering').': '.         $status.='<br />'.&mt('Registering').': '.
                &Apache::lonnet::cstore(\%newrecord,'_discussion');                 &Apache::lonnet::cstore(\%newrecord,'_discussion');
          &updatekarma();
     }      }
     } else {      } else {
  $status.='Failed.';   $status.='Failed.';
Line 3086  sub getdiscussionrecords { Line 3101  sub getdiscussionrecords {
   
 sub getdiscussionstats {  sub getdiscussionstats {
     my %record=&getdiscussionrecords(@_);      my %record=&getdiscussionrecords(@_);
     return ($record{'subnumber'},$record{'points'},$record{'totallikes'});      return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$record{'totalvotes'});
   }
   
   # Calculate discussion karma
   
   sub calcdiscussionkarma {    
       my ($subs,$pts,$likes,$votes)=&getdiscussionstats(@_);
       my $karma=0;
       if ($votes>0) {
           $karma=int(.1+5.*(1.-exp(-$subs/10.))*$likes/$votes);
           if ($karma<0) { $karma=0; }
           if ($karma>5) { $karma=5; }
       }
       return $karma;
 }  }
   
   # Update karma
   
   sub updatekarma {
       my ($uname,$udom,$course)=@_;
       unless ($uname) { $uname=$env{'user.name'}; }
       unless ($udom)  { $udom=$env{'user.domain'}; }
       unless ($course) { $course=$env{'request.course.id'}; }
       my $karma=&calcdiscussionkarma($uname,$udom,$course);
       &Apache::lonnet::cstore({ 'karma' => $karma },'_discussion',$course,$udom,$uname);
       &Apache::lonnet::do_cache_new('karma',$uname.':'.$udom.':'.$course,$karma,3600);
       return $karma;
   }
   
   # Retrieve karma
   
   sub userkarma {
       my ($uname,$udom,$course)=@_;
       unless ($uname) { $uname=$env{'user.name'}; }
       unless ($udom)  { $udom=$env{'user.domain'}; }
       unless ($course) { $course=$env{'request.course.id'}; }
       my $hashkey=$uname.':'.$udom.':'.$course;
       my ($karma,$cached)=&Apache::lonnet::is_cached_new('karma',$hashkey);
       if ($cached) {
           return $karma;
       }
       my %userdisc=&getdiscussionrecords($uname,$udom,$course);
       $karma=$userdisc{'karma'};
       &Apache::lonnet::do_cache_new('karma',$hashkey,$karma,3600);
       return $karma;
   }
   
 # Store discussion credit  # Store discussion credit
   
Line 3101  sub storediscussionpoints { Line 3159  sub storediscussionpoints {
     my %record=('grader_user'   => $env{'user.name'},      my %record=('grader_user'   => $env{'user.name'},
                 'grader_domain' => $env{'user.domain'},                  'grader_domain' => $env{'user.domain'},
                 'points' => $points);                  'points' => $points);
     return &Apache::lonnet::cstore(\%record,'_discussion');      return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname);
 }  }
   
 # Store discussion "likes"  # Store discussion "likes"
Line 3116  sub storediscussionlikes { Line 3174  sub storediscussionlikes {
     unless ($course) { $course=$env{'request.course.id'}; }      unless ($course) { $course=$env{'request.course.id'}; }
     my %record=&getdiscussionrecords($uname,$udom,$course);      my %record=&getdiscussionrecords($uname,$udom,$course);
     my $totallikes=$record{'totallikes'};      my $totallikes=$record{'totallikes'};
       my $totalvotes=$record{'totalvotes'};
     $totallikes+=$likes;      $totallikes+=$likes;
       $totalvotes++;
     my %newrecord=('likes_user'   => $env{'user.name'},      my %newrecord=('likes_user'   => $env{'user.name'},
                    'likes_domain' => $env{'user.domain'},                     'likes_domain' => $env{'user.domain'},
                    'likes' => $likes,                     'likes' => $likes,
                    'totallikes' => $totallikes);                     'totallikes' => $totallikes,
     return &Apache::lonnet::cstore(\%newrecord,'_discussion');                     'totalvotes' => $totalvotes);
       my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname);
       if ($status eq 'ok') {
           &updatekarma($uname,$udom,$course);
       }
       return $status;
 }  }
   
 sub get_discussion_info {  sub get_discussion_info {
Line 4118  ENDREDIR Line 4183  ENDREDIR
   $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];    $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
       } elsif ($env{'form.origpage'}) {        } elsif ($env{'form.origpage'}) {
   $symb="";     $symb=""; 
         } elsif ($env{'form.sendmessageonly'}) {
             $symb=(split(/\:\:\:/,$env{'form.sendmessageonly'}))[0];
       } else {        } else {
   $symb=&Apache::lonnet::symbread($feedurl);    $symb=&Apache::lonnet::symbread($feedurl);
       }        }

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


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