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

raeburn raeburn at source.lon-capa.org
Tue Jan 18 11:55:30 EST 2022


raeburn		Tue Jan 18 16:55:30 2022 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm 
  Log:
  - Handle case where URL on which feedback is to be sent is unavailable or
    is /adm/feedback itself.
  - Handle cases where &fail_redirect() and no_redirect_back() are called when
    feedback is composed in modal window (i.e., "Send Feedback" link was used).
  - Delay (s) can be passed as arg to &fail_redirect() and no_redirect_back()
    to allow user time to read message before window closes or page reloads.
  - If there is only one available feedback option automatically check the 
    radio button for that option.
  - If there are no available feedback options display "Sorry, no recipients"
    before pop-up close or page reload.
  
  
-------------- next part --------------
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.387 loncom/interface/lonfeedback.pm:1.388
--- loncom/interface/lonfeedback.pm:1.387	Fri Dec 31 20:34:24 2021
+++ loncom/interface/lonfeedback.pm	Tue Jan 18 16:55:30 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.387 2021/12/31 20:34:24 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.388 2022/01/18 16:55:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2751,29 +2751,49 @@
         $$attachments{'0'}{'filename'} = $attachmenturls;
         $$attachments{'0'}{'0'} = 'n';
     }
-
     return;
 }
 
 sub fail_redirect {
-  my ($r,$feedurl) = @_;
+  my ($r,$feedurl,$delay) = @_;
   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
   my %lt = &Apache::lonlocal::texthash(
                  'sorr' => 'Sorry, no recipients ...',
   );
   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
-  $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,
-					   {'redirect'  => [2,$feedurl],
-					    'only_body' => 1,}));
+  my %parms=('only_body'   => 1);
+  if ($delay !~ /^\d+(|\.\d+)$/) {
+      $delay = 0;
+  }
+  if ($env{'form.modal'}) {
+      my $onload = 'document.forms.reldt.submit()';
+      if ($delay) {
+          my $js_delay = int(1000 * $delay);
+          $onload = "setTimeout(function(){
+                     document.forms.reldt.submit();
+                     },$js_delay);";
+      }
+      $parms{'add_entries'}={'onload' => $onload};
+  } else {
+      $parms{'redirect'}=[$delay,$feedurl];
+  }
+  $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,\%parms));
+  my $windowname = 'loncapaclient';
+  if ($env{'request.lti.login'}) {
+     $windowname .= 'lti';
+  }
   $r->print(<<ENDFAILREDIR);
 <img align="right" src="$logo" />
 <p class="LC_warning">$lt{'sorr'}</p>
+<form name="reldt" action="$feedurl" target="$windowname">
+</form>
 ENDFAILREDIR
   $r->print(&Apache::loncommon::end_page());
 }
 
 sub redirect_back {
-  my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
+  my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,
+      $rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
   my $sorttag = '';
   my $roletag = '';
   my $statustag = '';
@@ -2873,7 +2893,8 @@
   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
   my %parms=('only_body'   => 1);
   if ($env{'form.modal'}) {
-      $parms{'add_entries'}={'onLoad' => 'document.forms.reldt.submit()'};
+      my $onload = 'document.forms.reldt.submit()';
+      $parms{'add_entries'}={'onload' => $onload};
   } else {
       $parms{'redirect'}=[0,$feedurl];
   }
@@ -2907,39 +2928,63 @@
 }
 
 sub no_redirect_back {
-  my ($r,$feedurl) = @_;
+  my ($r,$feedurl,$delay) = @_;
   my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
- 
-  my %onload;
-
-  my %body_options = ('only_body'   => 1,
-		      'bgcolor'     => '#FFFFFF',
-		      'add_entries' => \%onload,);
-
-  if ($feedurl !~ m{^/adm/feedback}) { 
-      $body_options{'redirect'} = [2,$feedurl];
+  my $form_for_modal;
+  my %parms=('only_body'   => 1,
+             'bgcolor'     => '#FFFFFF',);
+  if ($delay !~ /^\d+(|\.\d+)$/) {
+      $delay = 0;
+  }
+  if ($env{'form.modal'}) {
+      if (($feedurl !~ m{^/adm/feedback}) && ($feedurl ne '')) {
+          my $onload = 'document.forms.reldt.submit()';
+          if ($delay) {
+              my $js_delay = int(1000 * $delay);
+              $onload = "setTimeout(function(){
+                         document.forms.reldt.submit();
+                         },$js_delay);";
+          }
+          $parms{'add_entries'}={'onload' => $onload};
+          my $windowname = 'loncapaclient';
+          if ($env{'request.lti.login'}) {
+              $windowname .= 'lti';
+          }
+          $form_for_modal = <<ENDFORM;
+<form name="reldt" action="$feedurl" target="$windowname">
+</form>
+ENDFORM
+      }
+  } else {
+      if (($feedurl !~ m{^/adm/feedback}) && ($feedurl ne '')) {
+          $parms{'redirect'}=[$delay,$feedurl];
+      }
   }
+ 
   my $start_page=
       &Apache::loncommon::start_page('Feedback not sent',undef,
-				     \%body_options);
-				      
+				     \%parms);
+
   my $end_page = &Apache::loncommon::end_page();
 
-  &Apache::lonenc::check_encrypt(\$feedurl);
   my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
   $r->print (<<ENDNOREDIRTWO);
 $start_page
 <img align="right" src="$logo" />
 <b>$nofeed</b>
 <br />
+$form_for_modal
 $end_page
 ENDNOREDIRTWO
 }
 
 sub screen_header {
     my ($feedurl,$symb,$group) = @_;
-    my $crscontent = &mt('Question/Comment/Feedback about course content');
-    my $crspolicy = &mt('Question/Comment/Feedback about course policy');
+    my %default = &Apache::lonlocal::texthash (
+                    question => 'Question about resource content',
+                    comment => 'Question/Comment/Feedback about course content',
+                    policy => 'Question/Comment/Feedback about course policy',
+                  );  
     my $contribdisc = &mt('Contribution to course discussion of resource');
     my $anoncontrib = &mt('Anonymous contribution to course discussion of resource');
     my $namevis = &mt('name only visible to course faculty');
@@ -2947,8 +2992,8 @@
     if ($env{'request.course.id'}) {
         $crstype = &Apache::loncommon::course_type();
         if ($crstype eq 'Community') {
-            $crscontent = &mt('Question/Comment/Feedback about community content');
-            $crspolicy = &mt('Question/Comment/Feedback about community policy');
+            $default{'comment'} = &mt('Question/Comment/Feedback about community content');
+            $default{'policy'} = &mt('Question/Comment/Feedback about community policy'); 
             $contribdisc = &mt('Contribution to community discussion of resource');
             $anoncontrib = &mt('Anonymous contribution to community discussion of resource');
             $namevis = &mt('name only visible to community facilitators');
@@ -2956,58 +3001,79 @@
     }
     my $msgoptions='';
     my $discussoptions='';
+    my $checkradio = '';
+    my $blockblog;
+    my (%fdbkoptions,%discoptions);
     unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
-	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
-	    $msgoptions= 
-		'<label><input type="radio" name="discuss" value="author" /> '.
-		&mt('Feedback to resource author').'</label><br />';
-	}
-        my %optionhash=();
-        foreach my $type ('question','comment','policy') {
-	    $optionhash{$type}=$env{'course.'.$env{'request.course.id'}.'.'.$type.'.email.text'};
-	}
-	if (&feedback_available(1)) {
-	    $msgoptions.=
-		'<label><input type="radio" name="discuss" value="question" /> '.
-		($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'</label><br />';
-	}
-	if (&feedback_available(0,1)) {
-	    $msgoptions.=
-		'<label><input type="radio" name="discuss" value="course" /> '.
-		($optionhash{'comment'}?$optionhash{'comment'}:$crscontent).
-		'</label><br />';
-	}
-	if (&feedback_available(0,0,1)) {
-	    $msgoptions.=
-		'<label><input type="radio" name="discuss" value="policy" /> '.
-		($optionhash{'policy'}?$optionhash{'policy'}:$crspolicy).
-		'</label><br />';
-	}
+        if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
+            $fdbkoptions{'author'} = 1;
+        }
+        if (&feedback_available(1)) {
+            $fdbkoptions{'question'} = 1;
+        }
+        if (&feedback_available(0,1)) {
+            $fdbkoptions{'course'} = 1;
+        }
+        if (&feedback_available(0,0,1)) {
+            $fdbkoptions{'policy'} = 1;
+        }
     }
     if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
         my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
         my $realsymb = &get_realsymb($symb);
-        if (!$blocked && &discussion_open(undef,$realsymb) && 
-	    (&Apache::lonnet::allowed('pch',
-				      $env{'request.course.id'}.
-				      ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) || 
+        if (!$blocked && &discussion_open(undef,$realsymb) &&
+            (&Apache::lonnet::allowed('pch',
+                                      $env{'request.course.id'}.
+                                      ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) ||
             (($group ne '') && ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$}) && (&check_group_priv($group,'pgd') eq 'ok')))) {
-            $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.
-                            $contribdisc.
-                            '</label>'; 
+            $discoptions{'nonanon'} = 1;
             if (&Apache::lonnet::allowed('pac',$env{'request.course.id'}.
                ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
-	        $discussoptions .= '<br /><label><input type="radio" name="discuss" value="anon" /> '.
-		                   $anoncontrib.
-		                   ' <i>('.$namevis.')</i></label> '.
-		                   '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
-            }
-            my $blockblog = &Apache::loncommon::blocking_status('blogs');
-            if (!$blockblog) {
-                $discussoptions.= &add_blog_checkbox($crstype);
+                $discoptions{'anon'} = 1;
             }
+            $blockblog = &Apache::loncommon::blocking_status('blogs');
+        }
+    }
+    my $total = scalar(keys(%fdbkoptions)) + scalar(keys(%discoptions));
+    return if (!$total);
+    if ($total == 1) {
+        $checkradio = ' checked="checked"';
+    }
+    if (keys(%fdbkoptions)) {
+        if ($fdbkoptions{'author'}) {
+	    $msgoptions =
+		'<label><input type="radio" name="discuss" value="author"'.$checkradio.' /> '.
+		&mt('Feedback to resource author').'</label><br />';
+	}
+        foreach my $item ('question','comment','policy') {
+            my $type = $item;
+            if ($item eq 'comment') {
+                $type = 'course';
+            }
+            my $optionhash=$env{'course.'.$env{'request.course.id'}.'.'.$item.'.email.text'};
+            if ($fdbkoptions{$type}) {
+                $msgoptions .=
+                    '<label><input type="radio" name="discuss" value="'.$type.'"'.$checkradio.' />'.
+                    ($optionhash?$optionhash:$default{$item}).'</label><br />'; 
+	    }
+        }
+    }
+    if (keys(%discoptions)) {
+        if ($discoptions{'nonanon'}) {
+            $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.
+                            $contribdisc.
+                            '</label>';
+        }
+        if ($discoptions{'anon'}) {
+            $discussoptions .= '<br /><label><input type="radio" name="discuss" value="anon"'.$checkradio.' /> '.
+                               $anoncontrib.
+                               ' <i>('.$namevis.')</i></label> '.
+                               '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
+        }
+        if (!$blockblog) {
+            $discussoptions.= &add_blog_checkbox($crstype);
         }
     }
     if ($msgoptions) {
@@ -3947,8 +4013,9 @@
           my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
           my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
           my $feedurl=&Apache::lonnet::clutter($url);
-          &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />',                     '0','0','','',$env{'form.previous'},undef,undef,undef,
-                    undef,undef,undef,$group);
+          &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />',
+                         '0','0','','',$env{'form.previous'},undef,undef,undef,
+                         undef,undef,undef,$group);
           return OK;
       }
   } 
@@ -4159,7 +4226,7 @@
       unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) {
           &redirect_back($r,$feedurl,&mt('Hiding not permitted').'<br />',
                          '0','0','','',$env{'form.previous'},'','','','',
-                         undef,undef,$group,);
+                         undef,undef,$group);
           return OK;
       }
 
@@ -4591,6 +4658,12 @@
 	  $r->internal_redirect('/adm/ambiguous');
 	  return OK;
       }
+      if ($feedurl eq '') {
+          &Apache::loncommon::content_type($r,'text/html');
+          $r->send_http_header;
+          &no_redirect_back($r);
+          return OK;
+      }
 # Go ahead with feedback, no ambiguous reference
       unless (
 	  (
@@ -4607,7 +4680,7 @@
 	  $r->send_http_header;
 # Unable to give feedback
           &Apache::lonenc::check_encrypt(\$feedurl);
-	  &no_redirect_back($r,$feedurl);
+	  &no_redirect_back($r,$feedurl,2);
 	  return OK;
       }
 # --------------------------------------------------- Print login screen header
@@ -4627,7 +4700,7 @@
 	  if ($options) {
 	      &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
 	  } else {
-	      &fail_redirect($r,$feedurl);
+	      &fail_redirect($r,$feedurl,1);
 	  }
 	  return OK;
       }
@@ -4730,7 +4803,8 @@
       }
 	  
 # 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,$toolarge);
+      &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},
+                     undef,undef,undef,undef,undef,undef,$group,$toolarge);
   }
   return OK;
 }


More information about the LON-CAPA-cvs mailing list