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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 20 Mar 2007 00:08:11 -0000


albertel		Mon Mar 19 20:08:11 2007 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm lonfeedback.pm 
  Log:
  - error checking course email addresses
     - both at the setting stage for proper form and that the user exists
     - at the sending stage for proper form
  
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.363 loncom/interface/lonparmset.pm:1.364
--- loncom/interface/lonparmset.pm:1.363	Sat Mar 17 00:35:03 2007
+++ loncom/interface/lonparmset.pm	Mon Mar 19 20:08:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.363 2007/03/17 04:35:03 albertel Exp $
+# $Id: lonparmset.pm,v 1.364 2007/03/20 00:08:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2044,6 +2044,22 @@
         if ($name =~ /^default_enrollment_(start|end)_date$/) {
             $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
         }
+	#
+        # Deal with the emails
+        if ($name =~ /\.email$/) {
+	    my ($user,$domain) = split(/:/,$value);
+	    if (!defined($user) || !defined($domain)) {
+		$setoutput.= '<br /> <span class="LC_error">'.
+		    &mt("Invalid email address specified, address must be of the form username:domain").
+		    '</span>';
+		undef($value);
+	    } elsif (&Apache::lonnet::homeserver($user,$domain) eq 'no_host') {
+		$setoutput.= '<br /> <span class="LC_error">'.
+		    &mt("Invalid email address specified, user [_1] is unknown.",$value).
+		    '</span>';
+		undef($value);
+	    }
+        }
         # Get existing cloners
         my @oldcloner = ();
         if ($name eq 'cloners') {
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.245 loncom/interface/lonfeedback.pm:1.246
--- loncom/interface/lonfeedback.pm:1.245	Wed Feb 28 16:45:42 2007
+++ loncom/interface/lonfeedback.pm	Mon Mar 19 20:08:09 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.245 2007/02/28 21:45:42 albertel Exp $
+# $Id: lonfeedback.pm,v 1.246 2007/03/20 00:08:09 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2675,36 +2675,44 @@
 }
 
 sub send_msg {
-  my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_;
-  my $status='';
-  my $sendsomething=0;
-  my $restitle = &get_resource_title($symb,$feedurl);
-  if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
-  unless ($title=~/\w/) { $title=&mt('Feedback'); }
-  foreach my $key (keys(%to)) {
-    if ($key) {
-      unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$key),
-               $title.' ['.$restitle.']',$email,$citations,$feedurl,
-                $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) {
-	$status.='<br />'.&mt('Error sending message to').' '.$key.'<br />';
-      } else {
-	$sendsomething++;
-      }
+    my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_;
+    my $status='';
+    my $sendsomething=0;
+    my $restitle = &get_resource_title($symb,$feedurl);
+    if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
+    unless ($title=~/\w/) { $title=&mt('Feedback'); }
+    foreach my $key (keys(%to)) {
+	if ($key) {
+	    my ($user,$domain) = split(/\:/,$key,2);
+	    if (!defined($user)) {
+		$status.='<br />'.&mt('Error sending message to [_1], no user specified.',$key);
+	    } elsif (!defined($domain)) {
+		$status.='<br />'.&mt('Error sending message to [_1], no domain specified.',$key);
+	    } 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 ($temp)=keys(%record);
     unless ($temp=~/^error\:/) {
-       my %newrecord=();
-       $newrecord{'resource'}=$feedurl;
-       $newrecord{'subnumber'}=$record{'subnumber'}+1;
-       unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
-	   $status.='<br />'.&mt('Not registered').'<br />';
-       }
+	my %newrecord=();
+	$newrecord{'resource'}=$feedurl;
+	$newrecord{'subnumber'}=$record{'subnumber'}+1;
+	unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
+	    $status.='<br />'.&mt('Not registered').'<br />';
+	}
     }
-       
-  return ($status,$sendsomething);
+    
+    return ($status,$sendsomething);
 }
 
 sub adddiscuss {