Diff for /loncom/interface/lonfeedback.pm between versions 1.222 and 1.255.2.2

version 1.222, 2006/11/29 04:25:23 version 1.255.2.2, 2008/12/21 16:18:04
Line 44  use HTML::LCParser(); Line 44  use HTML::LCParser();
 use Apache::lonspeller();  use Apache::lonspeller();
 use Apache::longroup;  use Apache::longroup;
 use Cwd;  use Cwd;
 use lib '/home/httpd/lib/perl/';  
 use LONCAPA;  use LONCAPA;
   
 sub discussion_open {  sub discussion_open {
Line 75  sub discussion_visible { Line 74  sub discussion_visible {
   
 sub list_discussion {  sub list_discussion {
     my ($mode,$status,$ressymb,$imsextras,$group)=@_;      my ($mode,$status,$ressymb,$imsextras,$group)=@_;
       unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
       unless ($ressymb) { return ''; }
       $ressymb=&wrap_symb($ressymb);
     my $outputtarget=$env{'form.grade_target'};      my $outputtarget=$env{'form.grade_target'};
     if (defined($env{'form.export'})) {      if (defined($env{'form.export'})) {
  if($env{'form.export'}) {   if($env{'form.export'}) {
Line 86  sub list_discussion { Line 88  sub list_discussion {
             $outputtarget = 'export';              $outputtarget = 'export';
         }          }
     }      }
     if (not &discussion_visible($status)) { return ''; }      if (not &discussion_visible($status)) {
           if ($mode ne 'board') {
               &Apache::lonenc::check_encrypt(\$ressymb); 
               return '<br />'.&send_message_link($ressymb);
           }
       }
     if ($group ne '' && $mode eq 'board') {      if ($group ne '' && $mode eq 'board') {
         if (&check_group_priv($group,'vgb') ne 'ok') {          if (&check_group_priv($group,'vgb') ne 'ok') {
             return '';              return '';
         }          }
     }      }
   
       my ($blocked,$blocktext) = 
           &Apache::loncommon::blocking_status('boards');
       if ($blocked) {
           &Apache::lonenc::check_encrypt(\$ressymb);
           if ($mode ne 'board') {
               $blocktext.='<br />'.&send_message_link($ressymb);
           }
           return $blocktext; 
       }
   
     my @bgcols = ("#cccccc","#eeeeee");      my @bgcols = ("#cccccc","#eeeeee");
     my $discussiononly=0;      my $discussiononly=0;
     if ($mode eq 'board') { $discussiononly=1; }      if ($mode eq 'board') { $discussiononly=1; }
Line 103  sub list_discussion { Line 120  sub list_discussion {
  $crs.='_'.$env{'request.course.sec'};   $crs.='_'.$env{'request.course.sec'};
     }      }
     $crs=~s/\_/\//g;      $crs=~s/\_/\//g;
     unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }  
     unless ($ressymb) { return ''; }  
     $ressymb=&wrap_symb($ressymb);  
     my $encsymb=&Apache::lonenc::check_encrypt($ressymb);      my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)      my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
   && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/));    && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/));
Line 611  END Line 625  END
                             $filterchoice .= '&nbsp;'.$role_types{$role}.',';                              $filterchoice .= '&nbsp;'.$role_types{$role}.',';
                         }                          }
                         $filterchoice =~ s/,$//;                          $filterchoice =~ s/,$//;
                         $filterchoice .= '<br />&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;';                          $filterchoice .= '<br />'.('&nbsp;' x8);
                     }                      }
                     if ($statusfilter) {                      if ($statusfilter) {
                         $filterchoice .= '<i>'.&mt('status').'</i>-&nbsp;'.$status_types{$statusfilter};                          $filterchoice .= '<i>'.&mt('status').'</i>-&nbsp;'.$status_types{$statusfilter};
Line 623  END Line 637  END
                 }                  }
             }              }
             if ($dischash{$toggkey}) {              if ($dischash{$toggkey}) {
                 my $storebutton = &mt('Store read/unread changes');                  my $storebutton = &mt('Save read/unread changes');
                 $discussion.='<td align="right">'.                  $discussion.='<td align="right">'.
               '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".                '<input type="hidden" name="discsymb" value="'.$ressymb.'">'."\n".
               '<input type="button" name="readoptions" value="'.$storebutton.'"'.                '<input type="button" name="readoptions" value="'.$storebutton.'"'.
Line 718  END Line 732  END
             }              }
  }   }
     } else {      } else {
  $discussion.='<table bgcolor="#BBBBBB"><tr><td>';          $discussion.='<div class="LC_feedback_link">';
         if (&discussion_open($status) &&          if (&discussion_open($status) &&
             &Apache::lonnet::allowed('pch',              &Apache::lonnet::allowed('pch',
            $env{'request.course.id'}.             $env{'request.course.id'}.
         ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {          ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
     if ($outputtarget ne 'tex') {      if ($outputtarget ne 'tex') {
  $discussion.='<a href="/adm/feedback?replydisc='.   $discussion.= &send_feedback_link($ressymb,$target);
     &escape($ressymb).':::" '.$target.'>'.  
     '<img alt="" src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" border="0" />'.  
     &mt('Post Discussion').'</a><br />';  
             }              }
  }   }
  $discussion.='<a href="/adm/feedback?sendmessageonly=1&amp;symb='.          if ($outputtarget ne 'tex') {
     &escape($ressymb).      $discussion.= &send_message_link($ressymb);
     '"><img alt="" src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" border="0" />'.          }
     &mt('Send Message').'</a></td></tr></table>';          $discussion.='</div>';
     }      }
     return $discussion;      return $discussion;
 }  }
   
   sub send_feedback_link {
       my ($ressymb,$target) = @_;
       my $output = '<span class="LC_feedback_link">'.
                    ' <a href="/adm/feedback?replydisc='.
                    &escape($ressymb).':::" '.$target.'>'.
                    '<img alt="" src="'.
                    &Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').
                    '" border="0" />'.&mt('Post Discussion').'</a></span>';
       return $output;
   }
   
   sub send_message_link {
       my ($ressymb) = @_;
       my $output = '<span class="LC_message_link">'.
                    '  <a href="/adm/feedback?sendmessageonly=1&amp;symb='.
                    &escape($ressymb).'"><img alt="" src="'.
                    &Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').
                    '" border="0" />'.&mt('Send Message').'</a></span>';
       return $output;
   }
   
 sub action_links_bar {  sub action_links_bar {
     my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_;      my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_;
     my $discussion = '<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.      my $discussion = '<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
Line 762  sub action_links_bar { Line 794  sub action_links_bar {
             $discussion .= '&previous='.$prevread;              $discussion .= '&previous='.$prevread;
         }          }
         $discussion .= &group_args($group);          $discussion .= &group_args($group);
         $discussion .='">'.&mt('Sorting/Filtering options').'</a>&nbsp;&nbsp';          $discussion .='">'.&mt('Sorting/Filtering options').'</a>'.('&nbsp;' x2);
     } else {      } else {
         $discussion .= '<td align="left">';          $discussion .= '<td align="left">';
     }      }
Line 827  ENDDISCUSS Line 859  ENDDISCUSS
     if ($group ne '') {      if ($group ne '') {
         $postingform .='<input type="hidden" name="group" value="'.$group.'" />';          $postingform .='<input type="hidden" name="group" value="'.$group.'" />';
     }      }
       my $blockblog = &Apache::loncommon::blocking_status('blogs');
       if (!$blockblog) {
           $postingform .= &add_blog_checkbox();
       }
     $postingform .= "</form>\n";      $postingform .= "</form>\n";
     if ($outputtarget ne 'tex') {      if ($outputtarget ne 'tex') {
         $postingform .= &generate_attachments_button('',$attachnum,$ressymb,          $postingform .= &generate_attachments_button('',$attachnum,$ressymb,
                                                      $now,$currnewattach,                                                       $now,$currnewattach,
                                                      $currdelold,'',$mode);                                                       $currdelold,'',$mode,
                                                        $blockblog);
         if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {          if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
             $newattachmsg = '<br /><b>'.$lt{'newa'}.'</b><br />';              $newattachmsg = '<br /><b>'.$lt{'newa'}.'</b><br />';
             if (@{$currnewattach} > 1) {              if (@{$currnewattach} > 1) {
Line 863  sub build_posting_display { Line 900  sub build_posting_display {
   $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'});
   
       my $see_anonymous = 
    &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;
     }      }
Line 963  sub build_posting_display { Line 1003  sub build_posting_display {
                                @{$$subjectsort{$subject}} = ("$idx");                                 @{$$subjectsort{$subject}} = ("$idx");
                             }                              }
                         }                          }
         if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {          if (!$contrib{$idx.':anonymous'} || $see_anonymous) {
     $sender=&Apache::loncommon::aboutmewrapper(      $sender=&Apache::loncommon::aboutmewrapper(
  $plainname,   $plainname,
  $contrib{$idx.':sendername'},   $contrib{$idx.':sendername'},
  $contrib{$idx.':senderdomain'}).' ('.   $contrib{$idx.':senderdomain'}).' ('.
  $contrib{$idx.':sendername'}.' at '.   $contrib{$idx.':sendername'}.':'.
  $contrib{$idx.':senderdomain'}.')';   $contrib{$idx.':senderdomain'}.')';
     if ($contrib{$idx.':anonymous'}) {      if ($contrib{$idx.':anonymous'}) {
         $sender.=' <font color="red"><b>['.$$anonhash{$key}.']</b></font> '.          $sender.=' <font color="red"><b>['.$$anonhash{$key}.']</b></font> '.
     $screenname;      $screenname;
     }      }
       if ($see_anonymous) {
    $sender.=&Apache::loncommon::student_image_tag($contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
       }
 # Set up for sorting by domain, then username  # Set up for sorting by domain, then username
                             unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {                              unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
                                 %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();                                  %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
Line 1198  sub build_posting_display { Line 1240  sub build_posting_display {
                                 $$newitem{$idx} = 1;                                  $$newitem{$idx} = 1;
                                 $$discussionitems[$idx] .= '                                  $$discussionitems[$idx] .= '
                                  <p><table border="0" width="100%">                                   <p><table border="0" width="100%">
                                   <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';                                    <tr><td align="left"><font color="#FF0000"><b>'.&mt('NEW').'</b></font></td>';
                             } else {                              } else {
                                 $$newitem{$idx} = 0;                                  $$newitem{$idx} = 0;
                                 $$discussionitems[$idx] .= '                                  $$discussionitems[$idx] .= '
Line 1430  sub replicate_attachments { Line 1472  sub replicate_attachments {
 }  }
   
 sub mail_screen {  sub mail_screen {
   my ($r,$feedurl,$options) = @_;    my ($r,$feedurl,$options,$caller_symb,$attachmaxtext) = @_;
   if (exists($env{'form.origpage'})) {    if (exists($env{'form.origpage'})) {
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog','group','ref']);        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog','group','ref']);
   }    }
Line 1440  sub mail_screen { Line 1482  sub mail_screen {
             'myqu' => 'My question/comment/feedback:',              'myqu' => 'My question/comment/feedback:',
             'title' => 'Title',              'title' => 'Title',
             'reta' => 'Retained attachments',              'reta' => 'Retained attachments',
             'atta' => 'Attachment (128 KB max size)',              'atta' => 'Attachment',
            );              );
   my $title=&Apache::lonnet::gettitle($feedurl);    my $restitle = &get_resource_title($caller_symb,$feedurl);
   if (!$title) { $title = $feedurl; }  
   my $quote='';    my $quote='';
   my $subject = '';    my $subject = '';
   my $comment = '';    my $comment = '';
Line 1532  END Line 1573  END
               if ($idx > 0) {                if ($idx > 0) {
                   my %subversions = ();                    my %subversions = ();
                   &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);                    &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
                   $subject = &mt('Re: ')..$subversions{$numoldver};                    $subject = &mt('Re: ').$subversions{$numoldver};
               }                }
               $subject = &HTML::Entities::encode($subject,'<>&"');                $subject = &HTML::Entities::encode($subject,'<>&"');
           } else {            } else {
Line 1631  END Line 1672  END
   
   $r->print(<<END);    $r->print(<<END);
 $start_page  $start_page
 <h2><tt>$title</tt></h2>  <h2><tt>$restitle</tt></h2>
 <form action="/adm/feedback" method="post" name="mailform"  <form action="/adm/feedback" method="post" name="mailform"
 enctype="multipart/form-data">  enctype="multipart/form-data">
 $prevtag  $prevtag
Line 1680  END Line 1721  END
         }          }
     } else {      } else {
         $r->print(<<END);          $r->print(<<END);
 $lt{'atta'}: <input type="file" name="attachment" />  $lt{'atta'} $attachmaxtext: <input type="file" name="attachment" />
 </p>  </p>
 END  END
     }      }
Line 1700  END Line 1741  END
     if ($env{'form.editdisc'} || $env{'form.replydisc'}) {      if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
         my $now = time;          my $now = time;
         my $ressymb = $symb;          my $ressymb = $symb;
           &Apache::lonenc::check_encrypt(\$ressymb);
         my $postidx = '';          my $postidx = '';
         if ($env{'form.editdisc'}) {          if ($env{'form.editdisc'}) {
             $postidx = $idx;              $postidx = $idx;
Line 1707  END Line 1749  END
         if (@currnewattach > 0) {          if (@currnewattach > 0) {
             $attachnum += @currnewattach;              $attachnum += @currnewattach;
         }          }
         $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver));          my $blockblog = &Apache::loncommon::blocking_status('blogs');
           $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
         if ($attachnum > 0) {          if ($attachnum > 0) {
             if (@currnewattach > 0) {              if (@currnewattach > 0) {
                 $newattachmsg .= '<br /><b>'.&mt('New attachments').'</b><br />';                  $newattachmsg .= '<br /><b>'.&mt('New attachments').'</b><br />';
Line 1759  sub print_display_options { Line 1802  sub print_display_options {
         'unread' => 'New posts only',          'unread' => 'New posts only',
         'unmark' => 'Posts not marked read',          'unmark' => 'Posts not marked read',
         'ondisp' => 'Once displayed',          'ondisp' => 'Once displayed',
         'onmark' => 'Once marked not NEW ',          'onmark' => 'Once marked not NEW',
         'toggon' => 'Shown',          'toggon' => 'Shown',
         'toggoff' => 'Not shown',          'toggoff' => 'Not shown',
         'disa' => 'Posts displayed?',          'disa' => 'Posts displayed?',
Line 1917  END Line 1960  END
        <td>$lt{$disctogg}</td>         <td>$lt{$disctogg}</td>
        <td><label><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>         <td><label><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
 END  END
       my $save = &mt('Save Changes');
     $r->print(&Apache::loncommon::end_data_table_row());      $r->print(&Apache::loncommon::end_data_table_row());
     $r->print(&Apache::loncommon::end_data_table());      $r->print(&Apache::loncommon::end_data_table());
     $r->print(<<END);      $r->print(<<END);
Line 1928  END Line 1972  END
 <input type="hidden" name="$dispchgB" value=""/>  <input type="hidden" name="$dispchgB" value=""/>
 <input type="hidden" name="$markchg" value=""/>  <input type="hidden" name="$markchg" value=""/>
 <input type="hidden" name="$toggchg" value="" />  <input type="hidden" name="$toggchg" value="" />
 <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />  <input type="button" name="sub" value="$save" onClick="javascript:setDisp()" />
 END  END
     if (exists($env{'form.group'})) {      if (exists($env{'form.group'})) {
         $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');          $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
Line 2016  sub print_sortfilter_options { Line 2060  sub print_sortfilter_options {
         'spgr' => 'Specific groups',          'spgr' => 'Specific groups',
         'psub' => 'Pick specific users (by name)',          'psub' => 'Pick specific users (by name)',
         'shal' => 'Show a list of current posters',          'shal' => 'Show a list of current posters',
         'stor' => 'Store changes',          'stor' => 'Save changes',
     );      );
   
     my %sort_types = ();      my %sort_types = ();
Line 2347  ENDFAILREDIR Line 2391  ENDFAILREDIR
 }  }
   
 sub redirect_back {  sub redirect_back {
   my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group) = @_;    my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
   my $sorttag = '';    my $sorttag = '';
   my $roletag = '';    my $roletag = '';
   my $statustag = '';    my $statustag = '';
Line 2442  sub redirect_back { Line 2486  sub redirect_back {
           $feedurl .= '?group='.$group.$refarg;            $feedurl .= '?group='.$group.$refarg;
       }        }
   }     } 
   $feedurl=&Apache::lonenc::check_encrypt($feedurl);    &Apache::lonenc::check_encrypt(\$feedurl);
   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');    my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
   my %onload;    my %onload;
   if ($env{'environment.remote'} ne 'off') {    if ($env{'environment.remote'} ne 'off') {
Line 2461  $start_page Line 2505  $start_page
 $typestyle  $typestyle
 <b>Sent $sendsomething message(s), and $sendposts post(s).</b>  <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
 $blog  $blog
   $toolarge
 <font color="red">$status</font>  <font color="red">$status</font>
 <form name="reldt" action="$feedurl" target="loncapaclient">  <form name="reldt" action="$feedurl" target="loncapaclient">
 $prevtag  $prevtag
Line 2499  sub no_redirect_back { Line 2544  sub no_redirect_back {
               
   my $end_page = &Apache::loncommon::end_page();    my $end_page = &Apache::loncommon::end_page();
   
   $feedurl=&Apache::lonenc::check_encrypt($feedurl);    &Apache::lonenc::check_encrypt(\$feedurl);
   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');    my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
   $r->print (<<ENDNOREDIRTWO);    $r->print (<<ENDNOREDIRTWO);
 $start_page  $start_page
Line 2520  sub screen_header { Line 2565  sub screen_header {
  '<p><label><input type="radio" name="discuss" value="author" /> '.   '<p><label><input type="radio" name="discuss" value="author" /> '.
  &mt('Feedback to resource author').'</label></p>';   &mt('Feedback to resource author').'</label></p>';
  }   }
           my %optionhash=();
           foreach my $type ('question','comment','policy') {
       $optionhash{$type}=$env{'course.'.$env{'request.course.id'}.'.'.$type.'.email.text'};
    }
  if (&feedback_available(1)) {   if (&feedback_available(1)) {
     $msgoptions.=      $msgoptions.=
  '<p><label><input type="radio" name="discuss" value="question" /> '.   '<p><label><input type="radio" name="discuss" value="question" /> '.
  &mt('Question about resource content').'</label></p>';   ($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'</label></p>';
  }   }
  if (&feedback_available(0,1)) {   if (&feedback_available(0,1)) {
     $msgoptions.=      $msgoptions.=
  '<p><label><input type="radio" name="discuss" value="course" /> '.   '<p><label><input type="radio" name="discuss" value="course" /> '.
  &mt('Question/Comment/Feedback about course content').   ($optionhash{'comment'}?$optionhash{'comment'}:&mt('Question/Comment/Feedback about course content')).
  '</label></p>';   '</label></p>';
  }   }
  if (&feedback_available(0,0,1)) {   if (&feedback_available(0,0,1)) {
     $msgoptions.=      $msgoptions.=
  '<p><label><input type="radio" name="discuss" value="policy" /> '.   '<p><label><input type="radio" name="discuss" value="policy" /> '.
  &mt('Question/Comment/Feedback about course policy').   ($optionhash{'policy'}?$optionhash{'policy'}:&mt('Question/Comment/Feedback about course policy')).
  '</label></p>';   '</label></p>';
  }   }
     }      }
     if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {      if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
  if (&discussion_open(undef,$symb) &&          my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
           if (!$blocked && &discussion_open(undef,$symb) && 
     &Apache::lonnet::allowed('pch',      &Apache::lonnet::allowed('pch',
      $env{'request.course.id'}.       $env{'request.course.id'}.
      ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {       ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
     $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.      $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.
  &mt('Contribution to course discussion of resource');   &mt('Contribution to course discussion of resource');
     $discussoptions.='</label><br /><label><input type="radio" name="discuss" value="anon" /> '.          $discussoptions.='</label><br /><label><input type="radio" name="discuss" value="anon" /> '.
  &mt('Anonymous contribution to course discussion of resource').   &mt('Anonymous contribution to course discussion of resource').
  ' <i>('.&mt('name only visible to course faculty').')</i></label> '.   ' <i>('.&mt('name only visible to course faculty').')</i></label> '.
  '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';   '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
               my $blockblog = &Apache::loncommon::blocking_status('blogs');
               if (!$blockblog) {
                   $discussoptions.= &add_blog_checkbox();
               }
         }          }
         $discussoptions.='<br /><label><input type="checkbox" name="blog" /> '.  
     &mt('Add to my public course blog').'</label>';  
     }      }
     if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }      if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
     if ($discussoptions) {       if ($discussoptions) { 
Line 2599  sub clear_out_html { Line 2651  sub clear_out_html {
 }  }
   
 sub assemble_email {  sub assemble_email {
   my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;    my ($message,$prevattempts,$usersaw,$useranswer)=@_;
   my %lt = &Apache::lonlocal::texthash(    my %lt = &Apache::lonlocal::texthash(
              'prev' => 'Previous attempts of student (if applicable)',               'prev' => 'Previous attempts of student (if applicable)',
              'orig' => 'Original screen output (if applicable)',               'orig' => 'Original screen output (if applicable)',
Line 2620  ENDCITE Line 2672  ENDCITE
   return ($email,$citations);    return ($email,$citations);
 }  }
   
 sub secapply {  
     my $rec=shift;  
     my $defaultflag=shift;  
     $rec=~s/\s+//g;  
     $rec=~s/\@/\:/g;  
     my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);  
     if ($sections) {  
  foreach my $sec (split(/\;/,$sections)) {  
             if (($sec eq $env{'request.course.sec'}) ||  
                 ($defaultflag && ($sec eq '*'))) {  
                 return $adr;   
             }  
         }  
     } else {  
        return $rec;  
     }  
     return '';  
 }  
   
 =pod   
   
 =over 4  
   
 =item *  
   
 decide_receiver($feedurl,$author,$question,$course,$policy,$defaultflag);  
   
 Arguments  
   $feedurl - /res/ url of resource (only need if $author is true)  
   $author,$question,$course,$policy - all true/false parameters  
     if true will attempt to find the addresses of user that should receive  
     this type of feedback (author - feedback to author of resource $feedurl,  
     $question 'Resource Content Questions', $course 'Course Content Question',  
     $policy 'Course Policy')  
     (Additionally it also checks $env for whether the corresponding form.<name>  
     element exists, for ease of use in a html response context)  
      
   $defaultflag - (internal should be left blank) if true gather addresses   
                  that aren't for a section even if I have a section  
                  (used for reccursion internally, first we look for  
                  addresses for our specific section then we recurse  
                  and look for non section addresses)  
   
 Returns  
   $typestyle - string of html text, describing what addresses were found  
   %to - a hash, which keys are addresses of users to send messages to  
         the keys will look like   name:domain  
   
 =cut  
   
 sub decide_receiver {  
   my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;  
   my $typestyle='';  
   my %to=();  
   if ($env{'form.discuss'} eq 'author' ||$author) {  
     $typestyle.='Submitting as Author Feedback<br />';  
     $feedurl=~/^\/res\/(\w+)\/(\w+)\//;  
     $to{$2.':'.$1}=1;  
   }  
   if ($env{'form.discuss'} eq 'question' ||$question) {  
     $typestyle.=&mt('Submitting as Question').'<br />';  
     foreach my $item (split(/\,/,  
    $env{'course.'.$env{'request.course.id'}.'.question.email'})  
      ) {  
  my $rec=&secapply($item,$defaultflag);  
         if ($rec) { $to{$rec}=1; }  
     }   
   }  
   if ($env{'form.discuss'} eq 'course' ||$course) {  
     $typestyle.=&mt('Submitting as Comment').'<br />';  
     foreach my $item (split(/\,/,  
    $env{'course.'.$env{'request.course.id'}.'.comment.email'})  
      ) {  
  my $rec=&secapply($item,$defaultflag);  
         if ($rec) { $to{$rec}=1; }  
     }   
   }  
   if ($env{'form.discuss'} eq 'policy' ||$policy) {  
     $typestyle.=&mt('Submitting as Policy Feedback').'<br />';  
     foreach my $item (split(/\,/,  
    $env{'course.'.$env{'request.course.id'}.'.policy.email'})  
      ) {  
  my $rec=&secapply($item,$defaultflag);  
         if ($rec) { $to{$rec}=1; }  
     }   
   }  
   if ((scalar(%to) eq '0') && (!$defaultflag)) {  
      ($typestyle,%to)=  
  &decide_receiver($feedurl,$author,$question,$course,$policy,1);  
   }  
   return ($typestyle,%to);  
 }  
   
 sub feedback_available {  sub feedback_available {
     my ($question,$course,$policy)=@_;      my ($question,$course,$policy)=@_;
     my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);      my ($typestyle,%to)=&Apache::lonmsg::decide_receiver('',0,$question,
    $course,$policy);
     return scalar(%to);      return scalar(%to);
 }  }
   
 sub send_msg {  sub send_msg {
   my ($title,$feedurl,$email,$citations,$attachmenturl,%to)=@_;      my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_;
   my $status='';      my $status='';
   my $sendsomething=0;      my $sendsomething=0;
   if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }      my $restitle = &get_resource_title($symb,$feedurl);
   unless ($title=~/\w/) { $title=&mt('Feedback'); }      if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
   foreach my $key (keys(%to)) {      unless ($title=~/\w/) { $title=&mt('Feedback'); }
     if ($key) {      foreach my $key (keys(%to)) {
       my $declutter=&Apache::lonnet::declutter($feedurl);   if ($key) {
       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$key),      my ($user,$domain) = split(/\:/,$key,2);
                $title.' ['.$declutter.']',$email,$citations,$feedurl,      if (!defined($user)) {
                 $attachmenturl)=~/ok/) {   $status.='<br />'.&mt('Error sending message to [_1], no user specified.',$key);
  $status.='<br />'.&mt('Error sending message to').' '.$key.'<br />';      } elsif (!defined($domain)) {
       } else {   $status.='<br />'.&mt('Error sending message to [_1], no domain specified.',$key);
  $sendsomething++;      } else {
       }   unless (&Apache::lonmsg::user_normal_msg($user,$domain,
    $title.' ['.$restitle.']',$email,$citations,$feedurl,
    $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) {
       $status.='<br />'.&mt('Error sending message to').' '.$key.'<br />';
    } else {
       $sendsomething++;
    }
       }
    }
     }      }
   }  
   
     my %record=&Apache::lonnet::restore('_feedback');      my %record=&Apache::lonnet::restore('_feedback');
     my ($temp)=keys(%record);      my ($temp)=keys(%record);
     unless ($temp=~/^error\:/) {      unless ($temp=~/^error\:/) {
        my %newrecord=();   my %newrecord=();
        $newrecord{'resource'}=$feedurl;   $newrecord{'resource'}=$feedurl;
        $newrecord{'subnumber'}=$record{'subnumber'}+1;   $newrecord{'subnumber'}=$record{'subnumber'}+1;
        unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {   unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
    $status.='<br />'.&mt('Not registered').'<br />';      $status.='<br />'.&mt('Not registered').'<br />';
        }   }
     }      }
              
   return ($status,$sendsomething);      return ($status,$sendsomething);
 }  }
   
 sub adddiscuss {  sub adddiscuss {
Line 2782  sub adddiscuss { Line 2751  sub adddiscuss {
  $contrib{'anonymous'}='true';   $contrib{'anonymous'}='true';
     }      }
     if (($symb) && ($email)) {      if (($symb) && ($email)) {
           my $now = time;
         if ($env{'form.editdisc'}) {          if ($env{'form.editdisc'}) {
             $contrib{'ip'}=$ENV{'REMOTE_ADDR'};              $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
             $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};              $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
             $contrib{'timestamp'} = time;              $contrib{'timestamp'} = $now;
             $contrib{'history'} = '';              $contrib{'history'} = '';
             my $numoldver = 0;              my $numoldver = 0;
             my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});              my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
Line 2836  sub adddiscuss { Line 2806  sub adddiscuss {
                      $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'});
         }          }
         my %storenewentry=($symb => time);          my %storenewentry=($symb => $now);
         $status.='<br />'.&mt('Updating discussion time').': '.          $status.='<br />'.&mt('Updating discussion time').': '.
         &Apache::lonnet::put('discussiontimes',\%storenewentry,          &Apache::lonnet::put('discussiontimes',\%storenewentry,
                      $env{'course.'.$env{'request.course.id'}.'.domain'},                       $env{'course.'.$env{'request.course.id'}.'.domain'},
Line 2857  sub adddiscuss { Line 2827  sub adddiscuss {
     return $status.'<br />';         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  # ----------------------------------------------------------- Preview function
   
 sub show_preview {  sub show_preview {
Line 2921  ENDPREVIEW Line 2933  ENDPREVIEW
 }  }
   
 sub modify_attachments {  sub modify_attachments {
     my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls)=@_;      my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls,
           $attachmaxtext,$toolarge)=@_;
   
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                'subj' => 'Subject',                 'subj' => 'Subject',
Line 2929  sub modify_attachments { Line 2942  sub modify_attachments {
                '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' => 'Store Changes',                 'stch' => 'Save Changes',
              );               );
     my $js = <<END;      my $js = <<END;
 <script type="text/javascript">  <script type="text/javascript">
Line 2963  END Line 2976  END
                 
     $r->print(<<END);      $r->print(<<END);
 $start_page  $start_page
   $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">
  <table border="2">   <br />
    <table class="LC_data_table">
   <tr>    <tr>
    <td>     <td colspan="2">
     <b>Subject:</b> $subject</b><br /><br />      <b>Subject:</b> $subject</b><br /><br />
 END  END
     if ($idx) {      if ($idx) {
Line 2992  END Line 3007  END
         $r->print("<br />");           $r->print("<br />"); 
     }      }
     $r->print(<<END);      $r->print(<<END);
    $lt{'adda'}&nbsp;<input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onClick="this.form.submit()" />         </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>     </td>
   </tr>    </tr>
     <tr>
      <td colspan="2">$attachmaxtext</td>
     </tr>
  </table>   </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'}" />
Line 3048  sub process_attachments { Line 3069  sub process_attachments {
 }  }
   
 sub generate_attachments_button {  sub generate_attachments_button {
     my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,$numoldver,$mode) = @_;      my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,
           $numoldver,$mode,$blockblog) = @_;
     my $origpage = $ENV{'REQUEST_URI'};      my $origpage = $ENV{'REQUEST_URI'};
     my $att=$attachnum.' '.&mt("attachments");      my $att=$attachnum.' '.&mt("attachments");
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
Line 3060  sub generate_attachments_button { Line 3082  sub generate_attachments_button {
 $lt{'clic'}:&nbsp;<input type="button" value="$att"  $lt{'clic'}:&nbsp;<input type="button" value="$att"
 onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value);  onClick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value);
 END  END
       if (!$blockblog) {
           $response .= 'setblogvalue();';
       }
     unless ($mode eq 'board') {      unless ($mode eq 'board') {
         $response .= 'javascript:anonchk();';          $response .= 'javascript:anonchk();';
     }      }
Line 3199  sub construct_attachmenturl { Line 3224  sub construct_attachmenturl {
     return $newattachmenturl;       return $newattachmenturl; 
 }  }
   
   sub add_blog_checkbox {
       my ($checkstatus);
       if ($env{'form.blog'}) {
           $checkstatus = 'checked="checked"';
       }
       my $output = '
   <script type="text/javascript">
   function setblogvalue() {
       if (document.mailform.blog.checked) {
           document.attachment.blog.value = 1;
       } else {
           document.attachment.blog.value = 0;
       }
   }
   </script><br />
   <label><input type="checkbox" name="blog" '.$checkstatus.' /> '.
   &mt('Add to my public course blog').'</label><br />'."\n";
       return $output;
   }
   
 sub has_discussion {  sub has_discussion {
     my $resourcesref = shift;      my $resourcesref = shift;
     my $navmap = Apache::lonnavmaps::navmap->new();      my $navmap = Apache::lonnavmaps::navmap->new();
     my @allres=$navmap->retrieveResources();      if (defined($navmap)) {
     foreach my $resource (@allres) {          my @allres=$navmap->retrieveResources();
         if ($resource->hasDiscussion()) {          foreach my $resource (@allres) {
             my $ressymb = $resource->wrap_symb();              if ($resource->hasDiscussion()) {
             push(@{$resourcesref}, $ressymb);                  my $ressymb = $resource->wrap_symb();
                   if (ref($resourcesref) eq 'ARRAY') {
                       push(@{$resourcesref}, $ressymb);
                   }
               }
         }          }
       } else {
           &Apache::lonnet::logthis('Has discussion check failed - could not create navmap object.');
     }      }
     return;      return;
 }  }
Line 3253  sub handler { Line 3304  sub handler {
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
          ['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']);           ['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']);
   my $group = $env{'form.group'};    my $group = $env{'form.group'};
     my %attachmax = (
                       text => '(128 KB max size)',
                       num  => 131072,
                     );
   if ($env{'form.editdisc'}) {    if ($env{'form.editdisc'}) {
       if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {        if (!(&editing_allowed($env{'form.editdisc'},$env{'form.group'}))) {
           my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];            my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
Line 3501  ENDREDIR Line 3556  ENDREDIR
       if ( ($env{'form.hide'}) && (!$seeid) ) {        if ( ($env{'form.hide'}) && (!$seeid) ) {
   $newhash{'studenthidden'} = $currentstudenthidden;    $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'},        &Apache::lonnet::store(\%newhash,$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'});
Line 3514  ENDREDIR Line 3578  ENDREDIR
       my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});        my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
       if ($env{'form.cmd'} eq 'threadedon') {        if ($env{'form.cmd'} eq 'threadedon') {
   &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});    &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
   &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');    &Apache::lonnet::appenv({'environment.threadeddiscussion' => 'on'});
       } else {        } else {
    &Apache::lonnet::del('environment',['threadeddiscussion']);     &Apache::lonnet::del('environment',['threadeddiscussion']);
   &Apache::lonnet::delenv('environment\.threadeddiscussion');    &Apache::lonnet::delenv('environment\.threadeddiscussion');
Line 3530  ENDREDIR Line 3594  ENDREDIR
       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'});
         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.");        my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
       &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},        &Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
    $env{'course.'.$env{'request.course.id'}.'.domain'},     $env{'course.'.$env{'request.course.id'}.'.domain'},
Line 3547  ENDREDIR Line 3616  ENDREDIR
       &Apache::loncommon::content_type($r,'text/html');        &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;        $r->send_http_header;
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']);        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']);
       my (@currnewattach,@currdelold,@keepold);        my (@currnewattach,@currdelold,@keepold,$toolarge);
       &process_attachments(\@currnewattach,\@currdelold,\@keepold);        &process_attachments(\@currnewattach,\@currdelold,\@keepold);
       if (exists($env{'form.addnewattach.filename'})) {        if (exists($env{'form.addnewattach.filename'})) {
           unless (length($env{'form.addnewattach'})>131072) {            if (length($env{'form.addnewattach'})<=$attachmax{'num'}) {
               my $subdir = 'feedback/'.$env{'form.timestamp'};                my $subdir = 'feedback/'.$env{'form.timestamp'};
               my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);                my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
       push(@currnewattach, $newattachment);        push(@currnewattach, $newattachment);
             } else {
                 $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
           }            }
       }        }
       my $attachmenturls;        my $attachmenturls;
Line 3566  ENDREDIR Line 3637  ENDREDIR
           $attachmenturls = $contrib{$idx.':attachmenturl'};            $attachmenturls = $contrib{$idx.':attachmenturl'};
       }        }
       &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,        &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
   $attachmenturls);    $attachmenturls,$attachmax{'text'},$toolarge);
       return OK;        return OK;
   } elsif ($env{'form.export'}) {    } elsif ($env{'form.export'}) {
       &Apache::loncommon::content_type($r,'text/html');        &Apache::loncommon::content_type($r,'text/html');
Line 3589  ENDREDIR Line 3660  ENDREDIR
   } else {    } else {
 # ------------------------------------------------------------- Normal feedback  # ------------------------------------------------------------- Normal feedback
       my $feedurl=$env{'form.postdata'};        my $feedurl=$env{'form.postdata'};
       $feedurl=~s/^http\:\/\///;        $feedurl=~s/^https?\:\/\///;
       $feedurl=~s/^$ENV{'SERVER_NAME'}//;        $feedurl=~s/^$ENV{'SERVER_NAME'}//;
       $feedurl=~s/^$ENV{'HTTP_HOST'}//;        $feedurl=~s/^$ENV{'HTTP_HOST'}//;
       $feedurl=~s/\?.+$//;        $feedurl=~s/\?.+$//;
Line 3597  ENDREDIR Line 3668  ENDREDIR
       my $symb;        my $symb;
       if ($env{'form.replydisc'}) {        if ($env{'form.replydisc'}) {
   $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];    $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];
   my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);  
   $feedurl=&Apache::lonnet::clutter($url);  
       } elsif ($env{'form.editdisc'}) {        } elsif ($env{'form.editdisc'}) {
   $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];    $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
   my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);  
   $feedurl=&Apache::lonnet::clutter($url);  
       } elsif ($env{'form.origpage'}) {        } elsif ($env{'form.origpage'}) {
   $symb="";     $symb=""; 
       } else {        } else {
Line 3610  ENDREDIR Line 3677  ENDREDIR
       }        }
       unless ($symb) {        unless ($symb) {
   $symb=$env{'form.symb'};    $symb=$env{'form.symb'};
   if ($symb) {  
       my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);  
       $feedurl=&Apache::lonnet::clutter($url);  
   }  
       }        }
       &Apache::lonenc::check_decrypt(\$symb);        if (defined($symb)) {
             ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
         } else {
             # backward compatibility (bulletin boards used to be 'wrapped')
             &Apache::lonenc::check_decrypt(\$feedurl);
             &dewrapper(\$feedurl);
         }
       my $goahead=1;        my $goahead=1;
       if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {        if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
   unless ($symb) { $goahead=0; }    unless ($symb) { $goahead=0; }
       }        }
       # backward compatibility (bulletin boards used to be 'wrapped')  
       &dewrapper(\$feedurl);  
       if (!$goahead) {        if (!$goahead) {
           # Ambiguous Problem Resource            # Ambiguous Problem Resource
   $r->internal_redirect('/adm/ambiguous');    $r->internal_redirect('/adm/ambiguous');
Line 3640  ENDREDIR Line 3707  ENDREDIR
   &Apache::loncommon::content_type($r,'text/html');    &Apache::loncommon::content_type($r,'text/html');
   $r->send_http_header;    $r->send_http_header;
 # Unable to give feedback  # Unable to give feedback
             &Apache::lonenc::check_encrypt(\$feedurl);
   &no_redirect_back($r,$feedurl);    &no_redirect_back($r,$feedurl);
   return OK;    return OK;
       }        }
 # --------------------------------------------------- Print login screen header  # --------------------------------------------------- Print login screen header
       unless ($env{'form.sendit'}) {        unless ($env{'form.sendit'}) {
             &Apache::lonenc::check_encrypt(\$feedurl);
   &Apache::loncommon::content_type($r,'text/html');    &Apache::loncommon::content_type($r,'text/html');
   $r->send_http_header;    $r->send_http_header;
             if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
                 my ($blocked,$blocktext) = 
                        &Apache::loncommon::blocking_status('boards');
                 if ($blocked) {
                     $r->print(&blocked_reply_or_edit($blocktext));
                     return OK;
                 }
             }
   my $options=&screen_header($feedurl,$symb);    my $options=&screen_header($feedurl,$symb);
   if ($options) {    if ($options) {
       &mail_screen($r,$feedurl,$options);        &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
   } else {    } else {
       &fail_redirect($r,$feedurl);        &fail_redirect($r,$feedurl);
   }    }
Line 3662  ENDREDIR Line 3739  ENDREDIR
    $env{'request.course.id'});     $env{'request.course.id'});
   
 # Get output from resource  # Get output from resource
         &Apache::lonenc::check_encrypt(\$feedurl);
       my $usersaw=&resource_output($feedurl);        my $usersaw=&resource_output($feedurl);
   
 # Get resource answer (need to allow student to view grades for this to work)  # Get resource answer (need to allow student to view grades for this to work)
       &Apache::lonnet::appenv(('allowed.vgr'=>'F'));        &Apache::lonnet::appenv({'allowed.vgr'=>'F'});
       my $useranswer=&Apache::loncommon::get_student_answers(        my $usersymb = &Apache::lonenc::check_encrypt($symb);
                                    $symb,$env{'user.name'},$env{'user.domain'},        my $useranswer=
                    $env{'request.course.id'});            &Apache::loncommon::get_student_answers(
                 $usersymb,$env{'user.name'},$env{'user.domain'},
                 $env{'request.course.id'});
       &Apache::lonnet::delenv('allowed.vgr');        &Apache::lonnet::delenv('allowed.vgr');
 # Get attachments, if any, and not too large  # Get attachments, if any, and not too large
       my $attachmenturl='';        my $attachmenturl='';
         my $toolarge='';
       if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||        if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
   ($env{'form.replydisc'})) {    ($env{'form.replydisc'})) {
   my ($symb,$idx);    my ($symb,$idx);
Line 3690  ENDREDIR Line 3771  ENDREDIR
   $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;    $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
   $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);    $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
       } elsif ($env{'form.attachment.filename'}) {        } elsif ($env{'form.attachment.filename'}) {
   unless (length($env{'form.attachment'})>131072) {    if (length($env{'form.attachment'})<=$attachmax{'num'}) {
       $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');                my $now = time;
   }                my $subdir = 'feedback/'.$now;
         $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,$subdir);
     } else {
                 $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
             }
       }        }
 # Filter HTML out of message (could be nasty)  # Filter HTML out of message (could be nasty)
       my $message=&clear_out_html($env{'form.comment'});        my $message=&clear_out_html($env{'form.comment'});
   
 # Assemble email  # Assemble email
       my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,        my ($email,$citations)=&assemble_email($message,$prevattempts,
      $usersaw,$useranswer);       $usersaw,$useranswer);
     
 # Who gets this?  # Who gets this?
       my ($typestyle,%to) = &decide_receiver($feedurl);        my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl);
   
 # Actually send mail  # Actually send mail
       my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'},        my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'},
       undef,1),        undef,1),
       $feedurl,$email,$citations,        $feedurl,$email,$citations,
       $attachmenturl,%to);        $attachmenturl,$usersymb,%to);
   
 # Discussion? Store that.  # Discussion? Store that.
       my $numpost=0;        my $numpost=0;
Line 3735  ENDREDIR Line 3820  ENDREDIR
       }        }
       
 # Receipt screen and redirect back to where came from  # Receipt screen and redirect back to where came from
       &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group);        &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group,$toolarge);
   }    }
   return OK;    return OK;
   }
   
   sub blocked_reply_or_edit {
       my ($blocktext) = @_;
       return 
         &Apache::loncommon::start_page('Resource Feedback and Discussion').
         $blocktext.'<br /><br /><a href="javascript:history.go(-1)">'.
         &mt('Back to previous page').
         &Apache::loncommon::end_page();
 }   } 
   
 sub wrap_symb {  sub wrap_symb {
Line 3842  sub group_args { Line 3936  sub group_args {
     return $extra_args;      return $extra_args;
 }  }
   
   sub get_resource_title {
       my ($symb,$feedurl) = @_;
       my ($restitle,$plainurl);
       if (defined($symb)) {
           my $plain_symb = &Apache::lonenc::check_decrypt($symb);
           $restitle = &Apache::lonnet::gettitle($plain_symb);
       }
       if (defined($feedurl)) {
           $plainurl = &Apache::lonenc::check_decrypt($feedurl);
       }
       if (!defined($restitle)) {
           if (defined($feedurl)) {
               $restitle = &Apache::lonnet::gettitle($plainurl);
           }
       }
       if ($plainurl ne $feedurl) {
           my ($plain_filename) = ($plainurl =~ m-/([^/]+)$-);
           if ($plain_filename eq $restitle) {
               $restitle = &mt('Untitled resource');
           }
       }
       if ($restitle eq '') {
           $restitle = &mt('Untitled resource');
       }
       return $restitle;
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.222  
changed lines
  Added in v.1.255.2.2


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