Diff for /loncom/interface/lonfeedback.pm between versions 1.339 and 1.345

version 1.339, 2012/03/13 05:37:49 version 1.345, 2012/03/16 01:43:48
Line 1333  sub build_posting_display { Line 1333  sub build_posting_display {
                 } else {                  } else {
                     if ($message) {                      if ($message) {
                         my $spansize = 2;                          my $spansize = 2;
                           my ($uname,$udom);
                         if ($showonlyunread && $prevread > $posttime) {                          if ($showonlyunread && $prevread > $posttime) {
                             $$notshown{$idx} = 1;                              $$notshown{$idx} = 1;
                         } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {                          } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
                             $$notshown{$idx} = 1;                              $$notshown{$idx} = 1;
                         } else {                          } else {
 # apply filters  # apply filters
                             my $uname = $contrib{$idx.':sendername'};                              $uname = $contrib{$idx.':sendername'};
                             my $udom = $contrib{$idx.':senderdomain'};                              $udom = $contrib{$idx.':senderdomain'};
                             my $poster = $uname.':'.$udom;                              my $poster = $uname.':'.$udom;
                             if ($env{'form.totposters'} ne '') {                              if ($env{'form.totposters'} ne '') {
                                 if ($totposters == 0) {                                  if ($totposters == 0) {
Line 1424  sub build_posting_display { Line 1425  sub build_posting_display {
                                     '</div></blockquote>';                                      '</div></blockquote>';
                             if ($canvote) {                              if ($canvote) {
 # Put in the like and unlike buttons  # Put in the like and unlike buttons
                                 if ($userlikes{$idx}) {                                  if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) {
                                     $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';                                      my $novote = &mt('No voting for your own posts');
                                       $$discussionitems[$idx].=
                                           '<a href="javascript:alert('."'$novote'".');" style="text-decoration: none;">'.
                                           '<img border="0" src="/res/adm/pages/thumbsup_novote.png" alt="'.$novote.'" />&nbsp;'.
                                           '<img border="0" src="/res/adm/pages/thumbsdown_novote.png" alt="'.$novote.'" /></a>'; 
                                 } else {                                  } else {
                                     $$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"));                                      if ($userlikes{$idx}) {
                                 }                                          $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';
                                 if ($userunlikes{$idx}) {                                      } else {
                                     $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';                                          $$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].='&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"));                                      if ($userunlikes{$idx}) {
                                           $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';
                                       } else {
                                           $$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"));
                                       }
                                 }                                  }
                             }                              }
                             if ($seeid || $canvote) {                              if ($seeid || $canvote) {
Line 1680  sub mail_screen { Line 1689  sub mail_screen {
   }    }
   
   my %lt = &Apache::lonlocal::texthash(    my %lt = &Apache::lonlocal::texthash(
             'myqu' => 'My question/comment/feedback:',              'myqu' => 'Question/comment/feedback:',
             'title' => 'Title',              'title' => 'Title',
             'reta' => 'Retained attachments',              'reta' => 'Retained attachments',
             'atta' => 'Attachment',              'atta' => 'Attachment',
            );             );
     if($env{'form.editdisc'} || $env{'form.replydisc'}){
       %lt = &Apache::lonlocal::texthash(
               'myqu' => 'Post Discussion',
       );
     }
   my $restitle = &get_resource_title($caller_symb,$feedurl);    my $restitle = &get_resource_title($caller_symb,$feedurl);
   my $quote='';    my $quote='';
   my $subject = '';    my $subject = '';
Line 1895  END Line 1909  END
   }    }
   $r->print(<<END);    $r->print(<<END);
 $start_page  $start_page
   <h1>$lt{'myqu'}</h1>
 $header  $header
 <form action="/adm/feedback" method="post" name="mailform"  <form action="/adm/feedback" method="post" name="mailform"
 enctype="multipart/form-data">  enctype="multipart/form-data">
Line 1915  END Line 1930  END
   $r->print(<<END);    $r->print(<<END);
 $options  $options
 $quote  $quote
 <p>$lt{'myqu'}  <p>
 $textareaheader  $textareaheader
 </p>  </p>
   <br>
 <p>  <p>
 $latexHelp  $latexHelp
 </p>  </p>
 <p>  <p>
 $lt{'title'}: <input type="text" name="subject" size="30" value="$subject" /></p>  
 <p>  
 <textarea name="comment" id="comment" cols="60" rows="10" $textareaclass>$comment  
 </textarea></p>  
 END  END
   
       $r->print(&Apache::lonhtmlcommon::start_pick_box());
       $r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject')));
       $r->print('<input type="text" name="subject" size="30" value="'.
                 $subject.'" /></p>');
       $r->print(&Apache::lonhtmlcommon::row_closure());
       $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message')));
       $r->print('<textarea name="comment" id="comment" cols="60" rows="10" '.
                 $textareaclass.'>'.$comment.
                 '</textarea>');
       $r->print(&Apache::lonhtmlcommon::row_closure(1));
       $r->print(&Apache::lonhtmlcommon::end_pick_box());
   
     if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {      if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
         if ($env{'form.origpage'}) {          if ($env{'form.origpage'}) {
             foreach my $attach (@currnewattach) {              foreach my $attach (@currnewattach) {
Line 3396  sub modify_attachments { Line 3421  sub modify_attachments {
   
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                'subj' => 'Subject',                 'subj' => 'Subject',
                'thfo' => 'The following attachments were part of the most recent saved version of this posting.',  
                'chth' => 'Check the checkboxes for any you wish to remove.',                 'chth' => 'Check the checkboxes for any you wish to remove.',
                'thef' => 'The following attachments have been uploaded for inclusion with this posting.',                 'thef' => 'The following attachments have been uploaded for inclusion with this posting.',
                'adda' => 'Add a new attachment to this post.',                 'adda' => 'Add a new attachment to this post',
                'stch' => 'Save Changes',                 'stch' => 'Save Changes',
                  'clic' => 'Add/remove attachments',
              );               );
     my $js = <<END;      my $js = <<END;
 <script type="text/javascript">  <script type="text/javascript">
Line 3414  END Line 3439  END
     # Breadcrumbs      # Breadcrumbs
     my $brcrum = [{'href' => '',      my $brcrum = [{'href' => '',
                    'text' => 'Discussion Post Attachments'}];                     'text' => 'Discussion Post Attachments'}];
     my %parms=();      my %parms=('only_body' => 1);
     if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }      if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }
   
     my $start_page =       my $start_page = 
Line 3443  $start_page Line 3468  $start_page
 $toolarge  $toolarge
 <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">  <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
  <br />   <br />
  <table class="LC_data_table">   <h1>$lt{'clic'}</h1>
   <tr>  
    <td colspan="2">  
     <b>Subject:</b> <b>$subject</b><br /><br />  
 END  END
     if ($idx) {      $r->print(&Apache::lonhtmlcommon::start_pick_box());
         if ($attachmenturls) {      $r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject')));
             my @currold = keys(%currattach);      $r->print('<b>'.$subject.'</b>');
             if (@currold > 0) {      $r->print(&Apache::lonhtmlcommon::row_closure());
                 $r->print($lt{'thfo'}.'<br />'.$lt{'chth'}.'<br />'."\n");        $r->print(&Apache::lonhtmlcommon::row_title($lt{'adda'}));
                 foreach my $id (@currold) {      $r->print('<input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onclick="this.form.submit()" />  '.$attachmaxtext);
                     my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});       if(($idx)||(ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)){
                     $attachurl =~ m#/([^/]+)$#;          $r->print(&Apache::lonhtmlcommon::row_closure());
                     $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'</label><br />'."\n");          $r->print(&Apache::lonhtmlcommon::row_title(&mt('Attachments')));
           if ($idx) {
               if ($attachmenturls) {
                   my @currold = keys(%currattach);
                   if (@currold > 0) {
                       $r->print($lt{'thfo'}.'<br />'.$lt{'chth'}.'<br />'."\n");
                       foreach my $id (@currold) {
                           my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
                           $attachurl =~ m#/([^/]+)$#;
                           $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'</label><br />'."\n");
                       }
                       $r->print("<br />");
                 }                  }
                 $r->print("<br />");  
             }              }
         }          }
     }          if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
     if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {              $r->print($lt{'chth'}.'<br />'."\n");
         $r->print($lt{'thef'}.'<br />'.$lt{'chth'}.'<br />'."\n");              foreach my $attach (@{$currnewattach}) {
         foreach my $attach (@{$currnewattach}) {                  $attach =~ m#/([^/]+)$#;
             $attach =~ m#/([^/]+)$#;                  $r->print('<label><input type="checkbox" name="delnewattach" value="'.$attach.'" />&nbsp;'.$1.'</label><br />'."\n");
             $r->print('<label><input type="checkbox" name="delnewattach" value="'.$attach.'" />&nbsp;'.$1.'</label><br />'."\n");              }
         }          }
         $r->print("<br />");   
     }      }
       $r->print(&Apache::lonhtmlcommon::row_closure(1));
       $r->print(&Apache::lonhtmlcommon::end_pick_box());
     $r->print(<<END);      $r->print(<<END);
    </td></tr>  
    <tr>  
     <td>  
    $lt{'adda'}</td><td><input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onclick="this.form.submit()" />      
    </td>  
   </tr>  
   <tr>  
    <td colspan="2">$attachmaxtext</td>  
   </tr>  
  </table>  
 <input type="hidden" name="subject" value="$env{'form.subject'}" />  <input type="hidden" name="subject" value="$env{'form.subject'}" />
 <input type="hidden" name="comment" value="$env{'form.comment'}" />  <input type="hidden" name="comment" value="$env{'form.comment'}" />
 <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />  <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />
Line 3536  sub generate_attachments_button { Line 3559  sub generate_attachments_button {
     my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,      my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,
         $numoldver,$mode,$blockblog) = @_;          $numoldver,$mode,$blockblog) = @_;
     my $origpage = $ENV{'REQUEST_URI'};      my $origpage = $ENV{'REQUEST_URI'};
       my $att=$attachnum.' '.&mt("attachments");
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                 'clic' => 'Add/remove attachments',                  'clic' => 'Add/remove attachments',
     );       ); 
Line 4058  ENDREDIR Line 4082  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);
       my $status='OPEN';  
       if ($Apache::lonhomework::parsing_a_problem ||  
           $Apache::lonhomework::parsing_a_task) {  
           $status=$Apache::inputtags::status[-1];  
       }  
       my $result;        my $result;
       my $realsymb = &get_realsymb($symb);        if ($idx > 0) {
       if (&discussion_vote_available($status,$realsymb)) {            my $realsymb = &get_realsymb($symb);
             my $status='OPEN';
             if ($Apache::lonhomework::parsing_a_problem ||
                 $Apache::lonhomework::parsing_a_task) {
                 $status=$Apache::inputtags::status[-1];
             }
             if (&discussion_vote_available($status,$realsymb)) {
                 my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                                  $env{'course.'.$env{'request.course.id'}.'.domain'},
                                  $env{'course.'.$env{'request.course.id'}.'.num'});
                 if (($contrib{$idx.':sendername'} eq $env{'user.name'}) && 
                     ($contrib{$idx.':senderdomain'} eq $env{'user.domain'})) {
                     $result = &mt("Vote not registered. No voting for your own posts.");
                 } else {
   
 #  #
 # Likes and unlikes are in db-file "disclikes" of the course  # Likes and unlikes are in db-file "disclikes" of the course
 # The prefix is the $symb to identify the resource discussion,  # The prefix is the $symb to identify the resource discussion,
 # and the $idx to identify the entry  # and the $idx to identify the entry
 #  #
           my $prefix=$symb.':'.$idx.':';                    my $prefix=$symb.':'.$idx.':';
           my %contrib=&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'},
                                         '^'.$prefix);                                    '^'.$prefix);
   
 # Get current like or unlike status for the $idx for this user.  # Get current like or unlike status for the $idx for this user.
           my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};                    my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
           my ($userlikes,$userunlikes);                    my ($userlikes,$userunlikes);
           if (ref($contrib{$prefix.'likers'}) eq 'HASH') {                    if (ref($likes{$prefix.'likers'}) eq 'HASH') {
               if (exists($contrib{$prefix.'likers'}{$thisuser})) {                        if (exists($likes{$prefix.'likers'}{$thisuser})) {
                   $userlikes = 1;                            $userlikes = 1;
               }                        }
           }                    }
           if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') {                    if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
               if (exists($contrib{$prefix.'unlikers'}{$thisuser})) {                        if (exists($likes{$prefix.'unlikers'}{$thisuser})) {
                   $userunlikes = 1;                            $userunlikes = 1;
               }                        }
           }                    }
 # Get the current "likes" count  # Get the current "likes" count
           my $likes=$contrib{$prefix.'likes'};                    my $likescount=$likes{$prefix.'likes'};
 # Find out if they already voted  # Find out if they already voted
 # Users cannot like a post twice, or unlike it twice.  # Users cannot like a post twice, or unlike it twice.
 # They can change their mind, though.  # They can change their mind, though.
           my $alreadyflag=0;                    my $alreadyflag=0;
           my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};                    if ($env{'form.like'}) {
           if ($env{'form.like'}) {                        if ($userlikes) {
               if ($userlikes) {                            $alreadyflag=1;
                   $alreadyflag=1;                        } elsif ($userunlikes) {
               } elsif ($userunlikes) {                            delete($likes{$prefix.'unlikers'}{$thisuser});
                   delete($contrib{$prefix.'unlikers'}{$thisuser});                            $likescount++;
                   $likes++;                        } else {
               } else {                            if (ref($likes{$prefix.'likers'}) eq 'HASH') {
                   if (ref($contrib{$prefix.'likers'}) eq 'HASH') {                                $likes{$prefix.'likers'}{$thisuser} = 1;
                       $contrib{$prefix.'likers'}{$thisuser} = 1;                            } else {
                   } else {                                $likes{$prefix.'likers'} = {$thisuser => 1};
                       $contrib{$prefix.'likers'} = {$thisuser => 1};                            }
                   }                            $likescount++;
                   $likes++;                        }
               }  
           } else {  
               if ($userunlikes) {  
                   $alreadyflag=1;  
               } elsif ($userlikes) {  
                   delete($contrib{$prefix.'likers'}{$thisuser});  
                   $likes--;  
               } else {  
                   if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') {  
                       $contrib{$prefix.'unlikers'}{$thisuser} = 1;  
                   } else {                    } else {
                       $contrib{$prefix.'unlikers'} = {$thisuser => 1};                        if ($userunlikes) {
                             $alreadyflag=1;
                         } elsif ($userlikes) {
                             delete($likes{$prefix.'likers'}{$thisuser});
                             $likescount--;
                         } else {
                             if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
                                 $likes{$prefix.'unlikers'}{$thisuser} = 1;
                             } else {
                                 $likes{$prefix.'unlikers'} = {$thisuser => 1};
                             }
                             $likescount--;
                         }
                   }                    }
                   $likes--;  
               }  
           }  
 # $alreadyflag would be 1 if they tried to double-like or double-unlike  # $alreadyflag would be 1 if they tried to double-like or double-unlike
           unless ($alreadyflag) {                    if ($alreadyflag) {
               my %newhash=($prefix.'likes'    => $likes,                        if ($env{'form.like'}) {
                            $prefix.'likers'   => $contrib{$prefix.'likers'},                            $result= &mt("'Like' already registered");
                            $prefix.'unlikers' => $contrib{$prefix.'unlikers'});                        } else {
                             $result= &mt("'Unlike' already registered");
                         }
                     } else {
                         my %newhash=($prefix.'likes'    => $likescount,
                                      $prefix.'likers'   => $likes{$prefix.'likers'},
                                      $prefix.'unlikers' => $likes{$prefix.'unlikers'});
 # Store data in db-file "disclikes"  # 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  # 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'");
                   } else {                            } else {
                       &storediscussionlikes(-1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});                               &storediscussionlikes(-1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
                       $result=&mt("Registered 'Unlike'");                               $result=&mt("Registered 'Unlike'");
                   }                            }
               } else {                        } else {
 # Oops, something went wrong  # Oops, something went wrong
                   $result=&mt("Failed to register vote");                            $result=&mt("Failed to register vote");
                         }
                     }
               }                }
             } else {
                 $result=&mt('Voting unavailable for this discussion');
           }            }
       } else {        } else {
           $result=&mt('Voting unavailable for this discussion');            $result=&mt('Invalid post number'); 
       }        }
       &redirect_back($r,$feedurl,$result.'<br />',        &redirect_back($r,$feedurl,$result.'<br />',
                      '0','0','','',$env{'form.previous'},undef,undef,undef,                       '0','0','','',$env{'form.previous'},undef,undef,undef,

Removed from v.1.339  
changed lines
  Added in v.1.345


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