Diff for /loncom/interface/lonmsg.pm between versions 1.144 and 1.165

version 1.144, 2005/06/04 21:11:30 version 1.165, 2005/12/21 22:58:07
Line 97  Right now, this document will cover just Line 97  Right now, this document will cover just
 it is likely you will not need to programmatically read messages,  it is likely you will not need to programmatically read messages,
 since lonmsg already implements that functionality.  since lonmsg already implements that functionality.
   
   The routines used to package messages and unpackage messages are not
   only used by lonmsg when creating/extracting messages for LON-CAPA's
   internal messaging system, but also by lonnotify.pm which is available
   for use by Domain Coordinators to broadcast standard e-mail to specified
   users in their domain.  The XML packaging used in the two cases is very
   similar.  The differences are the use of <recuser>$uname</recuser> and 
   <recdomain>$udom</recdomain> in stored internal messages, compared 
   with <recipient username="$uname:$udom">$email</recipient> in stored
   Domain Coordinator e-mail for the storage of information about 
   recipients of the message/e-mail.
   
 =head1 FUNCTIONS  =head1 FUNCTIONS
   
 =over 4  =over 4
Line 114  use HTML::Entities(); Line 125  use HTML::Entities();
 use Mail::Send;  use Mail::Send;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::loncommunicate;  use Apache::loncommunicate;
   use Apache::lonfeedback;
   use Apache::lonrss();
   
 # Querystring component with sorting type  # Querystring component with sorting type
 my $sqs;  my $sqs;
Line 124  my $interdis; Line 137  my $interdis;
   
 sub packagemsg {  sub packagemsg {
     my ($subject,$message,$citation,$baseurl,$attachmenturl,      my ($subject,$message,$citation,$baseurl,$attachmenturl,
  $recuser,$recdomain)=@_;   $recuser,$recdomain,$msgid,$type)=@_;
     $message =&HTML::Entities::encode($message,'<>&"');      $message =&HTML::Entities::encode($message,'<>&"');
     $citation=&HTML::Entities::encode($citation,'<>&"');      $citation=&HTML::Entities::encode($citation,'<>&"');
     $subject =&HTML::Entities::encode($subject,'<>&"');      $subject =&HTML::Entities::encode($subject,'<>&"');
Line 134  sub packagemsg { Line 147  sub packagemsg {
     #remove machine specification      #remove machine specification
     $attachmenturl =~ s|^http://[^/]+/|/|;      $attachmenturl =~ s|^http://[^/]+/|/|;
     $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');      $attachmenturl =&HTML::Entities::encode($attachmenturl,'<>&"');
       my $course_context;
       if (defined($env{'form.replyid'})) {
           my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid)=
                      split(/\:/,&Apache::lonnet::unescape($env{'form.replyid'}));
           $course_context = $origcid;
       }
       foreach my $key (keys(%env)) {
           if ($key=~/^form\.(rep)?rec\_(.*)$/) {
               my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$origcid) =
                                       split(/\:/,&Apache::lonnet::unescape($2));
               $course_context = $origcid;
               last;
           }
       }
       unless(defined($course_context)) {
           $course_context = $env{'request.course.id'};
       }
     my $now=time;      my $now=time;
     $msgcount++;      $msgcount++;
     my $partsubj=$subject;      unless(defined($msgid)) {
     $partsubj=&Apache::lonnet::escape($partsubj);          $msgid = &buildmsgid($now,$subject,$env{'user.name'},$env{'user.domain'},
     my $msgid=&Apache::lonnet::escape(                              $msgcount,$course_context,$$);
            $now.':'.$partsubj.':'.$env{'user.name'}.':'.      }
            $env{'user.domain'}.':'.$msgcount.':'.  
            $env{'request.course.id'}.':'.$$);  
     my $result='<sendername>'.$env{'user.name'}.'</sendername>'.      my $result='<sendername>'.$env{'user.name'}.'</sendername>'.
            '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.             '<senderdomain>'.$env{'user.domain'}.'</senderdomain>'.
            '<subject>'.$subject.'</subject>'.             '<subject>'.$subject.'</subject>'.
Line 155  sub packagemsg { Line 182  sub packagemsg {
    '<browserversion>'.$env{'browser.version'}.'</browserversion>'.     '<browserversion>'.$env{'browser.version'}.'</browserversion>'.
            '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.             '<browsermathml>'.$env{'browser.mathml'}.'</browsermathml>'.
    '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.     '<browserraw>'.$ENV{'HTTP_USER_AGENT'}.'</browserraw>'.
    '<courseid>'.$env{'request.course.id'}.'</courseid>'.     '<courseid>'.$course_context.'</courseid>'.
    '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.     '<coursesec>'.$env{'request.course.sec'}.'</coursesec>'.
    '<role>'.$env{'request.role'}.'</role>'.     '<role>'.$env{'request.role'}.'</role>'.
    '<resource>'.$env{'request.filename'}.'</resource>'.     '<resource>'.$env{'request.filename'}.'</resource>'.
            '<msgid>'.$msgid.'</msgid>'.             '<msgid>'.$msgid.'</msgid>';
    '<recuser>'.$recuser.'</recuser>'.      if (ref($recuser) eq 'ARRAY') {
    '<recdomain>'.$recdomain.'</recdomain>'.          for (my $i=0; $i<@{$recuser}; $i++) {
    '<message>'.$message.'</message>';              if ($type eq 'dcmail') {
                   my ($username,$email) = split(/:/,$$recuser[$i]);
                   $username = &Apache::lonnet::unescape($username);
                   $email = &Apache::lonnet::unescape($email);
                   $username = &HTML::Entities::encode($username,'<>&"');
                   $email = &HTML::Entities::encode($email,'<>&"');
                   $result .= '<recipient username="'.$username.'">'.
                                               $email.'</recipient>';
               } else {
                   $result .= '<recuser>'.$$recuser[$i].'</recuser>'.
                              '<recdomain>'.$$recdomain[$i].'</recdomain>';
               }
           }
       } else {
           $result .= '<recuser>'.$recuser.'</recuser>'.
                      '<recdomain>'.$recdomain.'</recdomain>';
       }
       $result .= '<message>'.$message.'</message>';
     if (defined($citation)) {      if (defined($citation)) {
  $result.='<citation>'.$citation.'</citation>';   $result.='<citation>'.$citation.'</citation>';
     }      }
Line 186  sub unpackagemsg { Line 230  sub unpackagemsg {
        if ($token->[0] eq 'S') {         if ($token->[0] eq 'S') {
    my $entry=$token->[1];     my $entry=$token->[1];
            my $value=$parser->get_text('/'.$entry);             my $value=$parser->get_text('/'.$entry);
            $content{$entry}=$value;             if (($entry eq 'recuser') || ($entry eq 'recdomain')) {
                  push(@{$content{$entry}},$value);
              } elsif ($entry eq 'recipient') {
                  my $username = $token->[2]{'username'};
                  $username = &HTML::Entities::decode($username,'<>&"');
                  $content{$entry}{$username} = $value;
              } else {
                  $content{$entry}=$value;
              }
        }         }
     }      }
     if ($content{'attachmenturl'}) {      if ($content{'attachmenturl'}) {
Line 206  sub unpackagemsg { Line 258  sub unpackagemsg {
   
 # ======================================================= Get info out of msgid  # ======================================================= Get info out of msgid
   
   sub buildmsgid {
       my ($now,$subject,$uname,$udom,$msgcount,$course_context,$pid) = @_;
       $subject=&Apache::lonnet::escape($subject);
       return(&Apache::lonnet::escape($now.':'.$subject.':'.$uname.':'.
              $udom.':'.$msgcount.':'.$course_context.':'.$pid));
   }
   
 sub unpackmsgid {  sub unpackmsgid {
     my ($msgid,$folder)=@_;      my ($msgid,$folder,$skipstatus)=@_;
     $msgid=&Apache::lonnet::unescape($msgid);      $msgid=&Apache::lonnet::unescape($msgid);
     my $suffix=&foldersuffix($folder);  
     my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid)=split(/\:/,      my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid)=split(/\:/,
                           &Apache::lonnet::unescape($msgid));                            &Apache::lonnet::unescape($msgid));
     my %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);      my %status=();
     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }      unless ($skipstatus) {
     unless ($status{$msgid}) { $status{$msgid}='new'; }          my $suffix=&foldersuffix($folder);
           %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
           if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
           unless ($status{$msgid}) { $status{$msgid}='new'; }
       }
     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);      return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
 }  }
   
Line 337  sub del_url_author_res_msg { Line 399  sub del_url_author_res_msg {
     }      }
     return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);      return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
 }  }
   # =================================== Clear out all author messages in URL path
   
   sub clear_author_res_msg {
       my $url=shift;
       $url=&Apache::lonnet::declutter($url);
       my ($domain,$author)=($url=~/^(\w+)\/(\w+)\//);
       my @delmsgs=();
       foreach (&Apache::lonnet::getkeys('nohist_res_msgs',$domain,$author)) {
    if ($_=~/^\Q$url\E/) {
       push (@delmsgs,$_);
    }
       }
       return &Apache::lonnet::del('nohist_res_msgs',\@delmsgs,$domain,$author);
   }
 # ================= Return hash with URLs for which there is a resource message  # ================= Return hash with URLs for which there is a resource message
   
 sub all_url_author_res_msg {  sub all_url_author_res_msg {
Line 353  sub all_url_author_res_msg { Line 428  sub all_url_author_res_msg {
 # ================================================== Critical message to a user  # ================================================== Critical message to a user
   
 sub user_crit_msg_raw {  sub user_crit_msg_raw {
     my ($user,$domain,$subject,$message,$sendback,$toperm)=@_;      my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
 # Check if allowed missing  # Check if allowed missing
     my $status='';      my $status='';
     my $msgid='undefined';      my $msgid='undefined';
Line 367  sub user_crit_msg_raw { Line 442  sub user_crit_msg_raw {
            'put:'.$domain.':'.$user.':critical:'.             'put:'.$domain.':'.$user.':critical:'.
            &Apache::lonnet::escape($msgid).'='.             &Apache::lonnet::escape($msgid).'='.
            &Apache::lonnet::escape($message),$homeserver);             &Apache::lonnet::escape($message),$homeserver);
        if ($env{'request.course.id'}) {          if (defined($sentmessage)) {
           &user_normal_msg_raw(              $$sentmessage = $message;
             $env{'course.'.$env{'request.course.id'}.'.num'},          }
             $env{'course.'.$env{'request.course.id'}.'.domain'},  
             'Critical ['.$user.':'.$domain.']',  
     $message);  
        }  
     } else {      } else {
        $status='no_host';         $status='no_host';
     }      }
Line 411  sub user_crit_msg_raw { Line 482  sub user_crit_msg_raw {
 =cut  =cut
   
 sub user_crit_msg {  sub user_crit_msg {
     my ($user,$domain,$subject,$message,$sendback,$toperm)=@_;      my ($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage)=@_;
     my $status='';      my $status='';
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],      my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);                                         $domain,$user);
Line 421  sub user_crit_msg { Line 492  sub user_crit_msg {
  my ($forwuser,$forwdomain)=split(/\:/,$_);   my ($forwuser,$forwdomain)=split(/\:/,$_);
          $status.=           $status.=
    &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,     &user_crit_msg_raw($forwuser,$forwdomain,$subject,$message,
                 $sendback,$toperm).' ';                  $sendback,$toperm,$sentmessage).' ';
        }         }
     } else {       } else { 
  $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm);   $status=&user_crit_msg_raw($user,$domain,$subject,$message,$sendback,$toperm,$sentmessage);
     }      }
     return $status;      return $status;
 }  }
Line 459  sub user_crit_received { Line 530  sub user_crit_received {
   
 sub user_normal_msg_raw {  sub user_normal_msg_raw {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,      my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  $toperm)=@_;   $toperm,$currid,$newid,$sentmessage)=@_;
 # Check if allowed missing  # Check if allowed missing
     my $status='';      my $status='';
     my $msgid='undefined';      my $msgid='undefined';
Line 468  sub user_normal_msg_raw { Line 539  sub user_normal_msg_raw {
     my $homeserver=&Apache::lonnet::homeserver($user,$domain);      my $homeserver=&Apache::lonnet::homeserver($user,$domain);
     if ($homeserver ne 'no_host') {      if ($homeserver ne 'no_host') {
        ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,         ($msgid,$message)=&packagemsg($subject,$message,$citation,$baseurl,
                                      $attachmenturl,$user,$domain);                                       $attachmenturl,$user,$domain,$currid);
 # Store in user folder  # Store in user folder
        $status=&Apache::lonnet::critical(         $status=&Apache::lonnet::critical(
            'put:'.$domain.':'.$user.':nohist_email:'.             'put:'.$domain.':'.$user.':nohist_email:'.
Line 477  sub user_normal_msg_raw { Line 548  sub user_normal_msg_raw {
 # Save new message received time  # Save new message received time
        &Apache::lonnet::put         &Apache::lonnet::put
                          ('email_status',{'recnewemail'=>time},$domain,$user);                           ('email_status',{'recnewemail'=>time},$domain,$user);
 # Into sent-mail folder  # Into sent-mail folder unless a broadcast message or critical message
        $status.=' '.&Apache::lonnet::critical(         unless (($env{'request.course.id'}) && 
            'put:'.$env{'user.domain'}.':'.$env{'user.name'}.                 (($env{'form.sendmode'} eq 'group')  || 
       ':nohist_email_sent:'.                 (($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
            &Apache::lonnet::escape($msgid).'='.                 (&Apache::lonnet::allowed('srm',$env{'request.course.id'})))) {
            &Apache::lonnet::escape($message),$env{'user.home'});             $status .= &store_sent_mail($msgid,$message);
          }
     } else {      } else {
        $status='no_host';         $status='no_host';
     }      }
       if (defined($newid)) {
           $$newid = $msgid;
       }
       if (defined($sentmessage)) {
           $$sentmessage = $message;
       }
   
 # Notifications  # Notifications
     my %userenv = &Apache::lonnet::get('environment',['notification',      my %userenv = &Apache::lonnet::get('environment',['notification',
                                                       'permanentemail'],                                                        'permanentemail'],
Line 516  sub user_normal_msg_raw { Line 595  sub user_normal_msg_raw {
   
 sub user_normal_msg {  sub user_normal_msg {
     my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,      my ($user,$domain,$subject,$message,$citation,$baseurl,$attachmenturl,
  $toperm)=@_;   $toperm,$sentmessage)=@_;
     my $status='';      my $status='';
     my %userenv = &Apache::lonnet::get('environment',['msgforward'],      my %userenv = &Apache::lonnet::get('environment',['msgforward'],
                                        $domain,$user);                                         $domain,$user);
Line 526  sub user_normal_msg { Line 605  sub user_normal_msg {
  my ($forwuser,$forwdomain)=split(/\:/,$_);   my ($forwuser,$forwdomain)=split(/\:/,$_);
          $status.=           $status.=
   &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,    &user_normal_msg_raw($forwuser,$forwdomain,$subject,$message,
        $citation,$baseurl,$attachmenturl,$toperm).' ';   $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage).' ';
        }         }
     } else {       } else { 
  $status=&user_normal_msg_raw($user,$domain,$subject,$message,   $status=&user_normal_msg_raw($user,$domain,$subject,$message,
      $citation,$baseurl,$attachmenturl,$toperm);      $citation,$baseurl,$attachmenturl,$toperm,undef,undef,$sentmessage);
     }      }
     return $status;      return $status;
 }  }
   
   sub store_sent_mail {
       my ($msgid,$message) = @_;
           my $status =' '.&Apache::lonnet::critical(
                      'put:'.$env{'user.domain'}.':'.$env{'user.name'}.
                                                 ':nohist_email_sent:'.
                      &Apache::lonnet::escape($msgid).'='.
                      &Apache::lonnet::escape($message),$env{'user.home'});
       return $status;
   }
   
 # ============================================================ List all folders  # ============================================================ List all folders
   
Line 564  sub scrollbuttons { Line 652  sub scrollbuttons {
     my ($start,$maxdis,$first,$finish,$total)=@_;      my ($start,$maxdis,$first,$finish,$total)=@_;
     unless ($total>0) { return ''; }      unless ($total>0) { return ''; }
     $start++; $maxdis++;$first++;$finish++;      $start++; $maxdis++;$first++;$finish++;
     return       return
      &mt('Page').': '. 
    '<input type="submit" name="firstview" value="'.&mt('First').'" />'.     '<input type="submit" name="firstview" value="'.&mt('First').'" />'.
    '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.     '<input type="submit" name="prevview" value="'.&mt('Previous').'" />'.
    '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.     '<input type="text" size="5" name="startdis" value="'.$start.'" onChange="this.form.submit()" /> of '.$maxdis.
    '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.     '<input type="submit" name="nextview" value="'.&mt('Next').'" />'.
    '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.     '<input type="submit" name="lastview" value="'.&mt('Last').'" /><br />'.
    &mt('Messages [_1] through [_2] of [_3]',$first,$finish,$total).'</form>';     &mt('Showing messages [_1] through [_2] of [_3]',$first,$finish,$total).'</form>';
 }  }
   
 # =============================================================== Folder suffix  # =============================================================== Folder suffix
Line 596  sub statuschange { Line 685  sub statuschange {
     if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {      if (($newstatus eq 'deleted') || ($newstatus eq 'new')) {
  &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});   &Apache::lonnet::put('email_status'.$suffix,{$msgid => $newstatus});
     }      }
       if ($newstatus eq 'deleted') {
          &movemsg(&Apache::lonnet::unescape($msgid),$folder,'trash');
      }
 }  }
   
 # ============================================================= Make new folder  # ============================================================= Make new folder
Line 768  sub sortedmessages { Line 860  sub sortedmessages {
  my $msgid=&Apache::lonnet::escape($_);   my $msgid=&Apache::lonnet::escape($_);
  my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=   my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
     &Apache::lonmsg::unpackmsgid($msgid,$folder);      &Apache::lonmsg::unpackmsgid($msgid,$folder);
           my $description = &get_course_desc($fromcid);
  my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,   my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
      $msgid);       $msgid,$description);
         # Check whether message was sent during blocking period.          # Check whether message was sent during blocking period.
         if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {          if ($sendtime >= $startblock && ($sendtime <= $endblock && $endblock > 0) ) {
             my $escid = &Apache::lonnet::unescape($msgid);              my $escid = &Apache::lonnet::unescape($msgid);
Line 805  sub sortedmessages { Line 898  sub sortedmessages {
     if ($env{'form.sortedby'} eq "revsubject"){      if ($env{'form.sortedby'} eq "revsubject"){
         @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;          @temp = sort  {lc($b->[1]) cmp lc($a->[1])} @temp;
     }      }
       if ($env{'form.sortedby'} eq "course"){
           @temp = sort  {lc($a->[6]) cmp lc($b->[6])} @temp;
       }
       if ($env{'form.sortedby'} eq "revcourse"){
           @temp = sort  {lc($b->[6]) cmp lc($a->[6])} @temp;
       }
     if ($env{'form.sortedby'} eq "status"){      if ($env{'form.sortedby'} eq "status"){
         @temp = sort  {$a->[4] cmp $b->[4]} @temp;          @temp = sort  {$a->[4] cmp $b->[4]} @temp;
     }      }
Line 814  sub sortedmessages { Line 913  sub sortedmessages {
     return @temp;      return @temp;
 }  }
   
   sub get_course_desc {
       my ($fromcid) = @_;
       my $description; 
       if (defined($env{'course.'.$fromcid.'.description'})) {
          $description = $env{'course.'.$fromcid.'.description'};
       } else {
          my %courseinfo=&Apache::lonnet::coursedescription($fromcid);
           $description = $courseinfo{'description'};
       }
       return $description;
   }
   
 # ======================================================== Display new messages  # ======================================================== Display new messages
   
   
Line 822  sub disnew { Line 933  sub disnew {
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
        'nm' => 'New Messages',         'nm' => 'New Messages',
        'su' => 'Subject',         'su' => 'Subject',
                                          'co' => 'Course',
        'da' => 'Date',         'da' => 'Date',
        'us' => 'Username',         'us' => 'Username',
        'op' => 'Open',         'op' => 'Open',
Line 843  sub disnew { Line 955  sub disnew {
         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=          my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
     &Apache::lonmsg::unpackmsgid($_);      &Apache::lonmsg::unpackmsgid($_);
         if (defined($sendtime) && $sendtime!~/error/) {          if (defined($sendtime) && $sendtime!~/error/) {
               my $description = &get_course_desc($fromcid);
             my $numsendtime = $sendtime;              my $numsendtime = $sendtime;
             $sendtime = &Apache::lonlocal::locallocaltime($sendtime);              $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
             if ($status eq 'new') {              if ($status eq 'new') {
Line 855  sub disnew { Line 968  sub disnew {
                         sendtime => $sendtime,                          sendtime => $sendtime,
                         shortsub => &Apache::lonnet::unescape($shortsubj),                          shortsub => &Apache::lonnet::unescape($shortsubj),
                         from     => $fromname,                          from     => $fromname,
                         fromdom  => $fromdom                           fromdom  => $fromdom,
                           course   => $description 
                         }                          }
                 }                  }
             }              }
Line 865  sub disnew { Line 979  sub disnew {
         $r->print(<<TABLEHEAD);          $r->print(<<TABLEHEAD);
 <h2>$lt{'nm'}</h2>  <h2>$lt{'nm'}</h2>
 <table border=2><tr><th>&nbsp</th>  <table border=2><tr><th>&nbsp</th>
 <th>$lt{'da'}</th><th>$lt{'us'}</th><th>$lt{'do'}</th><th>$lt{'su'}</th></tr>  <th>$lt{'da'}</th><th>$lt{'us'}</th><th>$lt{'do'}</th><th>$lt{'su'}</th><th>$lt{'co'}</th></tr>
 TABLEHEAD  TABLEHEAD
         foreach my $msg (@newmsgs) {          foreach my $msg (@newmsgs) {
             $r->print(<<"ENDLINK");              $r->print(<<"ENDLINK");
 <tr bgcolor="#FFBB77">  <tr class="new" bgcolor="#FFBB77" onMouseOver="javascript:style.backgroundColor='#DD9955'" 
   onMouseOut="javascript:style.backgroundColor='#FFBB77'">
 <td><a href="/adm/email?dismode=new&display=$msg->{'msgid'}">$lt{'op'}</a></td>  <td><a href="/adm/email?dismode=new&display=$msg->{'msgid'}">$lt{'op'}</a></td>
 ENDLINK  ENDLINK
             foreach ('sendtime','from','fromdom','shortsub') {              foreach ('sendtime','from','fromdom','shortsub','course') {
                 $r->print("<td>$msg->{$_}</td>");                  $r->print("<td>$msg->{$_}</td>");
             }              }
             $r->print("</td></tr>");              $r->print("</td></tr>");
Line 986  ENDDISHEADER Line 1101  ENDDISHEADER
     $r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');      $r->print('<a href = "?sortedby=revsubject'.$fsqs.'">'.&mt('Subject').'</a>');
     }      }
     $r->print('</th><th>');      $r->print('</th><th>');
       if ($env{'form.sortedby'} eq "revcourse") {
           $r->print('<a href = "?sortedby=course'.$fsqs.'">'.&mt('Course').'</a>');
       } else {
           $r->print('<a href = "?sortedby=revcourse'.$fsqs.'">'.&mt('Course').'</a>');
       }
       $r->print('</th><th>');
     if ($env{'form.sortedby'} eq "revstatus") {      if ($env{'form.sortedby'} eq "revstatus") {
  $r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');   $r->print('<a href = "?sortedby=status'.$fsqs.'">'.&mt('Status').'</a></th>');
     } else {      } else {
Line 993  ENDDISHEADER Line 1114  ENDDISHEADER
     }      }
     $r->print("</tr>\n");      $r->print("</tr>\n");
     for (my $n=$firstdis;$n<=$lastdis;$n++) {      for (my $n=$firstdis;$n<=$lastdis;$n++) {
  my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID)= @{$temp[$n]};   my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$origID,$description)= @{$temp[$n]};
  if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {   if (($status ne 'deleted') && defined($sendtime) && $sendtime!~/error/) {
     if ($status eq 'new') {      if ($status eq 'new') {
  $r->print('<tr bgcolor="#FFBB77">');   $r->print('<tr bgcolor="#FFBB77" onMouseOver="javascript:style.backgroundColor=\'#DD9955\'"  onMouseOut="javascript:style.backgroundColor=\'#FFBB77\'">');
     } elsif ($status eq 'read') {      } elsif ($status eq 'read') {
  $r->print('<tr bgcolor="#BBBB77">');   $r->print('<tr bgcolor="#BBBB77" onMouseOver="javascript:style.backgroundColor=\'#999944\'"  onMouseOut="javascript:style.backgroundColor=\'#BBBB77\'">');
     } elsif ($status eq 'replied') {      } elsif ($status eq 'replied') {
  $r->print('<tr bgcolor="#AAAA88">');    $r->print('<tr bgcolor="#AAAA88" onMouseOver="javascript:style.backgroundColor=\'#888855\'"  onMouseOut="javascript:style.backgroundColor=\'#AAAA88\'">'); 
     } else {      } else {
  $r->print('<tr bgcolor="#99BBBB">');   $r->print('<tr bgcolor="#99BBBB" onMouseOver="javascript:style.backgroundColor=\'#669999\'"  onMouseOut="javascript:style.backgroundColor=\'#99BBBB\'">');
     }      }
     $r->print('<td><input type="checkbox" name="delmark_'.$origID.'" /></td><td><a href="/adm/email?display='.$origID.$sqs.       $r->print('<td><input type="checkbox" name="delmark_'.$origID.'" /></td><td><a href="/adm/email?display='.$origID.$sqs. 
       '">'.&mt('Open').'</a></td><td>'.        '">'.&mt('Open').'</a></td><td>'.
Line 1011  ENDDISHEADER Line 1132  ENDDISHEADER
       '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.        '<td>'.&Apache::lonlocal::locallocaltime($sendtime).'</td><td>'.
       $fromname.'</td><td>'.$fromdomain.'</td><td>'.        $fromname.'</td><td>'.$fromdomain.'</td><td>'.
       &Apache::lonnet::unescape($shortsubj).'</td><td>'.        &Apache::lonnet::unescape($shortsubj).'</td><td>'.
                       $status."</td></tr>\n");                        $description.'</td><td>'.$status.'</td></tr>'."\n");
  } elsif ($status eq 'deleted') {   } elsif ($status eq 'deleted') {
 # purge  # purge
     &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');      &movemsg(&Apache::lonnet::unescape($origID),$folder,'trash');
Line 1095  sub compout { Line 1216  sub compout {
  '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').'  ' .   '<label><input type="checkbox" name="sendbck" /> '.&mt('Send as critical message').'  ' .
  &mt('and return receipt') . '</label>' . $crithelp .    &mt('and return receipt') . '</label>' . $crithelp . 
  '</p><p><label><input type="checkbox" name="permanent" /> '.   '</p><p><label><input type="checkbox" name="permanent" /> '.
 &mt('Send copy to permanent email address (if known)').'</label></p>';  &mt('Send copy to permanent email address (if known)').'</label></p>'.
      }  '<!-- <p><label><input type="checkbox" name="rsspost" /> '.
     &mt('Include in course RSS newsfeed').'</label></p>-->';      }
     my %message;      my %message;
     my %content;      my %content;
     my $defdom=$env{'user.domain'};      my $defdom=$env{'user.domain'};
Line 1215  ENDUPLOAD Line 1337  ENDUPLOAD
        &discourse;         &discourse;
     }      }
     $r->print('</form>'.      $r->print('</form>'.
         &Apache::lonfeedback::generate_preview_button('compemail','message').
       &Apache::lonhtmlcommon::htmlareaselectactive('message'));        &Apache::lonhtmlcommon::htmlareaselectactive('message'));
 }  }
   
Line 1236  sub retrieve_instructor_comments { Line 1359  sub retrieve_instructor_comments {
         my %content=&unpackagemsg($records{$_});          my %content=&unpackagemsg($records{$_});
         next if ($content{'senderdomain'} eq '');          next if ($content{'senderdomain'} eq '');
         next if ($content{'subject'} !~ /^Record/);          next if ($content{'subject'} !~ /^Record/);
         # $content{'message'}=~s/\n/\<br\>/g;   # &Apache::lonfeedback::newline_to_br(\$content{'message'});
         $result.='Recorded by '.   $result.='Recorded by '.
             $content{'sendername'}.'@'.$content{'senderdomain'}."\n";              $content{'sendername'}.'@'.$content{'senderdomain'}."\n";
         $result.=          $result.=
             &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";              &Apache::lontexconvert::msgtexconverted($content{'message'})."\n";
Line 1260  sub disfacetoface { Line 1383  sub disfacetoface {
     foreach (sort keys %records) {      foreach (sort keys %records) {
         my %content=&unpackagemsg($records{$_});          my %content=&unpackagemsg($records{$_});
         next if ($content{'senderdomain'} eq '');          next if ($content{'senderdomain'} eq '');
         $content{'message'}=~s/\n/\<br\>/g;   &Apache::lonfeedback::newline_to_br(\$content{'message'});
         if ($content{'subject'}=~/^Record/) {          if ($content{'subject'}=~/^Record/) {
     $result.='<h3>'.&mt('Record').'</h3>';      $result.='<h3>'.&mt('Record').'</h3>';
         } elsif ($content{'subject'}=~/^Broadcast/) {          } elsif ($content{'subject'}=~/^Broadcast/) {
             $result .='<h3>'.&mt('Broadcast Message').'</h3>';              $result .='<h3>'.&mt('Broadcast Message').'</h3>';
               if ($content{'subject'}=~/^Broadcast\./) {
                   %content=&unpackagemsg($content{'message'});
                   $content{'message'}=
                       '<b>'.&mt('Subject').': '.$content{'subject'}.'</b><br />'.
                       $content{'message'};
               }    
         } else {          } else {
             $result.='<h3>'.&mt('Critical Message').'</h3>';              $result.='<h3>'.&mt('Critical Message').'</h3>';
             %content=&unpackagemsg($content{'message'});              %content=&unpackagemsg($content{'message'});
Line 1340  ENDTREC Line 1469  ENDTREC
         ($env{'form.recdomain'}) && ($env{'form.recuname'})) {          ($env{'form.recdomain'}) && ($env{'form.recuname'})) {
         chomp($env{'form.newrecord'});          chomp($env{'form.newrecord'});
         if ($env{'form.newrecord'}) {          if ($env{'form.newrecord'}) {
              my $recordtxt = $env{'form.newrecord'};
            &user_normal_msg_raw(             &user_normal_msg_raw(
             $env{'course.'.$env{'request.course.id'}.'.num'},              $env{'course.'.$env{'request.course.id'}.'.num'},
             $env{'course.'.$env{'request.course.id'}.'.domain'},              $env{'course.'.$env{'request.course.id'}.'.domain'},
             &mt('Record').              &mt('Record').
      ' ['.$env{'form.recuname'}.':'.$env{'form.recdomain'}.']',       ' ['.$env{'form.recuname'}.':'.$env{'form.recdomain'}.']',
     $env{'form.newrecord'});      $recordtxt);
         }          }
         $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},          $r->print('<h3>'.&Apache::loncommon::plainname($env{'form.recuname'},
      $env{'form.recdomain'}).'</h3>');       $env{'form.recdomain'}).'</h3>');
Line 1777  sub displaymessage { Line 1907  sub displaymessage {
       '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.        '<td><a href="/adm/email?markunread='.&Apache::lonnet::escape($msgid).$sqs.
       '"><b>'.&mt('Mark Unread').'</b></a></td>'.        '"><b>'.&mt('Mark Unread').'</b></a></td>'.
       '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.        '<td><a href="/adm/email?markdel='.&Apache::lonnet::escape($msgid).$sqs.
       '"><b>Delete</b></a></td>'.        '"><b>'.&mt('Delete').'</b></a></td>'.
       '<td><a href="/adm/email?'.$sqs.        '<td><a href="/adm/email?'.$sqs.
       ($env{'form.dismode'} eq 'new'?'&folder=new':'').        ($env{'form.dismode'} eq 'new'?'&folder=new':'').
       '"><b>'.&mt('Back to Folder Display').'</b></a></td>');        '"><b>'.&mt('Back to Folder Display').'</b></a></td>');
Line 1790  sub displaymessage { Line 1920  sub displaymessage {
   '"><b>'.&mt('Next').'</b></a></td>');    '"><b>'.&mt('Next').'</b></a></td>');
     }      }
     $r->print('</tr></table>');      $r->print('</tr></table>');
       if ($env{'user.adv'}) {
    $r->print('<table border="2" width="100%"><tr bgcolor="#FFAAAA"><td>'.&mt('Currently available actions (will open extra window)').':</td>');
    my $symb=&Apache::lonnet::symbread($content{'baseurl'});      
    if (&Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
    $r->print('<td><b>'.&Apache::loncommon::track_student_link(&mt('View recent activity'),$content{'sendername'},$content{'senderdomain'},'check').'</b></td>');
       }
    if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) && $symb) {
       $r->print('<td><b>'.&Apache::loncommon::pprmlink(&mt('Set/Change parameters'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
    }
    if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}) && $symb) {
       $r->print('<td><b>'.&Apache::loncommon::pgrdlink(&mt('Set/Change grades'),$content{'sendername'},$content{'senderdomain'},$symb,'check').'</b></td>');
    }
    $r->print('</tr></table>');
       }
       my $tolist;
       my @recipients = ();
       for (my $i=0; $i<@{$content{'recuser'}}; $i++) {
           $recipients[$i] =  &Apache::loncommon::aboutmewrapper(
              &Apache::loncommon::plainname($content{'recuser'}[$i],
                                         $content{'recdomain'}[$i]),
                 $content{'recuser'}[$i],$content{'recdomain'}[$i]).
          ' ('.$content{'recuser'}[$i].' at '.$content{'recdomain'}[$i].') ';
       }
       $tolist = join(', ',@recipients);
     $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.      $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
       ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.        ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
       &Apache::loncommon::aboutmewrapper(        &Apache::loncommon::aboutmewrapper(
Line 1797  sub displaymessage { Line 1951  sub displaymessage {
  $content{'sendername'},$content{'senderdomain'}).' ('.   $content{'sendername'},$content{'senderdomain'}).' ('.
       $content{'sendername'}.' at '.        $content{'sendername'}.' at '.
       $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.        $content{'senderdomain'}.') ':'<br /><b>'.&mt('To').':</b> '.
       &Apache::loncommon::aboutmewrapper(                $tolist).
  &Apache::loncommon::plainname($content{'recuser'},$content{'recdomain'}),  
  $content{'recuser'},$content{'recdomain'}).' ('.  
       $content{'recuser'}.' at '.  
       $content{'recdomain'}.') ').  
       ($content{'courseid'}?'<br /><b>'.&mt('Course').':</b> '.$courseinfo{'description'}.        ($content{'courseid'}?'<br /><b>'.&mt('Course').':</b> '.$courseinfo{'description'}.
        ($content{'coursesec'}?' ('.&mt('Group/Section').': '.$content{'coursesec'}.')':''):'').         ($content{'coursesec'}?' ('.&mt('Group/Section').': '.$content{'coursesec'}.')':''):'').
       '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.        '<br /><b>'.&mt('Time').':</b> '.$content{'time'}.
Line 1916  sub sendoffmail { Line 2066  sub sendoffmail {
     my ($r,$folder)=@_;      my ($r,$folder)=@_;
     my $suffix=&foldersuffix($folder);      my $suffix=&foldersuffix($folder);
     my $sendstatus='';      my $sendstatus='';
       my %specialmsg_status;
       my $numspecial = 0;
     if ($env{'form.send'}) {      if ($env{'form.send'}) {
  &printheader($r,'','Messages being sent.');   &printheader($r,'','Messages being sent.');
  $r->rflush();   $r->rflush();
Line 1960  sub sendoffmail { Line 2112  sub sendoffmail {
  $toaddr{$auname.':'.$audom}='';   $toaddr{$auname.':'.$audom}='';
     }      }
  }   }
   
           my $savemsg;
           my $msgtype;
           my %sentmessage;
           if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&
               (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
               $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);
               $msgtype = 'critical';
           } else {
               $savemsg=&Apache::lonfeedback::clear_out_html($env{'form.message'});
           }
   
  foreach (keys %toaddr) {   foreach (keys %toaddr) {
     my ($recuname,$recdomain)=split(/\:/,$_);      my ($recuname,$recdomain)=split(/\:/,$_);
             my $msgtxt;              my $msgtxt = $savemsg;
             if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&  
                 (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {  
                 $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'},1);  
             } else {    
         $msgtxt=&Apache::lonfeedback::clear_out_html($env{'form.message'});  
             }  
     if ($toaddr{$_}) { $msgtxt.='<hr />'.$toaddr{$_}; }      if ($toaddr{$_}) { $msgtxt.='<hr />'.$toaddr{$_}; }
     my $thismsg;          my $thismsg;
     if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) &&       if ((($env{'form.critmsg'}) || ($env{'form.sendbck'})) && 
  (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {   (&Apache::lonnet::allowed('srm',$env{'request.course.id'}))) {
  $r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': ');   $r->print(&mt('Sending critical message').' '.$recuname.'@'.$recdomain.': ');
  $thismsg=&user_crit_msg($recuname,$recdomain,   $thismsg=&user_crit_msg($recuname,$recdomain,
  &Apache::lonfeedback::clear_out_html($env{'form.subject'}),   &Apache::lonfeedback::clear_out_html($env{'form.subject'}),
  $msgtxt,   $msgtxt,
  $env{'form.sendbck'},$env{'form.permanent'});   $env{'form.sendbck'},$env{'form.permanent'},\$sentmessage{$_});
     } else {      } else {
  $r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': ');   $r->print(&mt('Sending').' '.$recuname.'@'.$recdomain.': ');
  $thismsg=&user_normal_msg($recuname,$recdomain,   $thismsg=&user_normal_msg($recuname,$recdomain,
   &Apache::lonfeedback::clear_out_html($env{'form.subject'}),    &Apache::lonfeedback::clear_out_html($env{'form.subject'}),
   $msgtxt,    $msgtxt,
   $content{'citation'},undef,undef,$env{'form.permanent'});    $content{'citation'},undef,undef,$env{'form.permanent'},\$sentmessage{$_});
  if (($env{'request.course.id'}) && ($env{'form.sendmode'} eq 'group')) {              }
     &user_normal_msg_raw(      if (($env{'request.course.id'}) && (($msgtype eq 'critical') || 
  $env{'course.'.$env{'request.course.id'}.'.num'},                                           ($env{'form.sendmode'} eq 'group'))) {
  $env{'course.'.$env{'request.course.id'}.'.domain'},          $specialmsg_status{$recuname.':'.$recdomain}  = $thismsg;
  'Broadcast ['.$recuname.':'.$recdomain.']',                  if ($thismsg eq 'ok') {
  $msgtxt);                      $numspecial ++;
  }                  }
     }      }
     $r->print($thismsg.'<br />');      $r->print($thismsg.'<br />');
     $sendstatus.=' '.$thismsg;      $sendstatus.=' '.$thismsg;
  }   }
           if (($env{'request.course.id'}) && (($env{'form.sendmode'} eq 'group')
                                                 || ($msgtype eq 'critical'))) {
               my $subj_prefix;
               if ($msgtype eq 'critical') {
                   $subj_prefix = 'Critical.';
               } else {
                   $subj_prefix = 'Broadcast.';
               }
               my ($specialmsgid,$specialresult);
               my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
               my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
               my $course_str = &Apache::lonnet::escape('['.$cnum.':'.$cdom.']');
   
               if ($numspecial) {
                   $specialresult = &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
                       ' '.$course_str,$savemsg,undef,undef,undef,
                       undef,undef,\$specialmsgid);
                   $specialmsgid = &Apache::lonnet::unescape($specialmsgid);
               }
               if ($specialresult eq 'ok') {
                   my $record_sent;
                   my @recusers = ();
                   my @recudoms = ();
                   my ($stamp,$msgsubj,$msgname,$msgdom,$msgcount,$context,$pid) = 
                               split(/\:/,&Apache::lonnet::unescape($specialmsgid));
                   foreach my $recipient (sort(keys(%toaddr))) {
                       if ($specialmsg_status{$recipient} eq 'ok') {
                           my $usersubj = $subj_prefix.'['.$recipient.']';
                           my $usermsgid = &buildmsgid($stamp,$usersubj,$msgname,
                                                 $msgdom,$msgcount,$context,$pid);
                           &user_normal_msg_raw($cnum,$cdom,$subj_prefix.
                           ' ['.$recipient.']',$sentmessage{$recipient},
                           undef,undef,undef,undef,$usermsgid);
                           my ($uname,$udom) = split/:/,$recipient;
                           push(@recusers,$uname);
                           push(@recudoms,$udom);
                       }
                   }
                   if (@recusers) {
                       my $specialmessage;
                       my $sentsubj = $subj_prefix.' ('.$numspecial.' sent) '.
                       &Apache::lonfeedback::clear_out_html($env{'form.subject'});
                       $sentsubj = &HTML::Entities::encode($sentsubj,'<>&"');
                       my $sentmsgid = &buildmsgid($stamp,$sentsubj,$msgname,
                                                 $msgdom,$msgcount,$context,$pid);
                       ($specialmsgid,$specialmessage) =
                            &packagemsg(&Apache::lonfeedback::clear_out_html(
                                $env{'form.subject'}),$savemsg,undef,undef,undef,
                                               \@recusers,\@recudoms,$sentmsgid);
                       $record_sent = &store_sent_mail($specialmsgid,$specialmessage);
                   }
               } else {
                   &Apache::lonnet::logthis('Failed to create record of critical message or broadcast in '.$env{'course.'.$env{'request.course.id'}.'.num'}.' at '.$env{'course.'.$env{'request.course.id'}.'.domain'}.' - no msgid generated');
               }
           }
     } else {      } else {
  &printheader($r,'','No messages sent.');    &printheader($r,'','No messages sent.'); 
     }      }
Line 2161  sub handler { Line 2373  sub handler {
  if ($env{'form.storebasecomment'}) {   if ($env{'form.storebasecomment'}) {
     &storecomment($r);      &storecomment($r);
  }   }
    if (($env{'form.rsspost'}) && ($env{'request.course.id'})) {
       &Apache::lonrss::addentry($env{'course.'.$env{'request.course.id'}.'.num'},
         $env{'course.'.$env{'request.course.id'}.'.domain'},
         'Course_Announcements',
         $env{'form.subject'},
         $env{'form.message'},'/adm/communicate','public');
    }
  &disall($r,($folder?$folder:$dismode));   &disall($r,($folder?$folder:$dismode));
     } elsif ($env{'form.newfolder'}) {      } elsif ($env{'form.newfolder'}) {
  &printheader($r,'','New Folder');   &printheader($r,'','New Folder');

Removed from v.1.144  
changed lines
  Added in v.1.165


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