Diff for /loncom/interface/lonmsg.pm between versions 1.6 and 1.12

version 1.6, 2001/02/06 16:51:24 version 1.12, 2001/08/03 14:00:07
Line 12 Line 12
 #  #
 # 10/19,10/20,10/30,  # 10/19,10/20,10/30,
 # 02/06/01 Gerd Kortemeyer  # 02/06/01 Gerd Kortemeyer
   # 07/27 Guy Albertelli
   # 07/27,07/28,07/30,08/03 Gerd Kortemeyer
   
 package Apache::lonmsg;  package Apache::lonmsg;
   
Line 24  use Apache::Constants qw(:common); Line 26  use Apache::Constants qw(:common);
 # ===================================================================== Package  # ===================================================================== Package
   
 sub packagemsg {  sub packagemsg {
     my ($subject,$message)=@_;      my ($subject,$message,$citation)=@_;
     $message=~s/\</\&lt\;/g;      $message=~s/\</\&lt\;/g;
     $message=~s/\>/\&gt\;/g;      $message=~s/\>/\&gt\;/g;
       $citation=~s/\</\&lt\;/g;
       $citation=~s/\>/\&gt\;/g;
     $subject=~s/\</\&lt\;/g;      $subject=~s/\</\&lt\;/g;
     $subject=~s/\>/\&gt\;/g;      $subject=~s/\>/\&gt\;/g;
     my $now=time;      my $now=time;
Line 54  sub packagemsg { Line 58  sub packagemsg {
    '<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>'.
    '<message>'.$message.'</message>';     '<message>'.$message.'</message>'.
      '<citation>'.$citation.'</citation>';
 }  }
   
 # ================================================== Unpack message into a hash  # ================================================== Unpack message into a hash
Line 77  sub unpackagemsg { Line 82  sub unpackagemsg {
 # ======================================================= Get info out of msgid  # ======================================================= Get info out of msgid
   
 sub unpackmsgid {  sub unpackmsgid {
     my $msgid=shift;      my $msgid=&Apache::lonnet::unescape(shift);
     my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,      my ($sendtime,$shortsubj,$fromname,$fromdomain)=split(/\:/,
                      &Apache::lonnet::unescape(                            &Apache::lonnet::unescape($msgid));
                           &Apache::lonnet::unescape($_)));      my %status=&Apache::lonnet::get('email_status',[$msgid]);
     my %status=&Apache::lonnet::get('email_status',$msgid);  
     if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }      if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
     unless ($status{$msgid}) { $status{$msgid}='new'; }      unless ($status{$msgid}) { $status{$msgid}='new'; }
     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});      return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
Line 139  sub user_crit_msg { Line 143  sub user_crit_msg {
 # =================================================== Critical message received  # =================================================== Critical message received
   
 sub user_crit_received {  sub user_crit_received {
     my $message=shift;      my $msgid=shift;
     my %contents=&unpackagemsg($message);      my %message=&Apache::lonnet::get('critical',[$msgid]);
       my %contents=&unpackagemsg($message{$msgid});
     my $status='rec: '.      my $status='rec: '.
      &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},       &user_normal_msg($contents{'sendername'},$contents{'senderdomain'},
                      'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},                       'Receipt: '.$ENV{'user.name'}.' at '.$ENV{'user.domain'},
Line 149  sub user_crit_received { Line 154  sub user_crit_received {
                      $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"                       $contents{'subject'}.'" dated '.$contents{'time'}.".\n\n"
                      .'Message ID: '.$contents{'msgid'});                       .'Message ID: '.$contents{'msgid'});
     $status.=' trans: '.      $status.=' trans: '.
      &Apache::lonnet::put('nohist_email',$contents{'msgid'} => $message);       &Apache::lonnet::put(
        'nohist_email',{$contents{'msgid'} => $message{$msgid}});
     $status.=' del: '.      $status.=' del: '.
      &Apache::lonnet::del('critical',$contents{'msgid'});       &Apache::lonnet::del('critical',[$contents{'msgid'}]);
     &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},      &Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
                          $ENV{'user.home'},'Received critical message '.                           $ENV{'user.home'},'Received critical message '.
                          $contents{'msgid'}.                           $contents{'msgid'}.
                          ', '.$status);                           ', '.$status);
       return $status;
 }  }
   
 # ======================================================== Normal communication  # ======================================================== Normal communication
   
 sub user_normal_msg {  sub user_normal_msg {
     my ($user,$domain,$subject,$message)=@_;      my ($user,$domain,$subject,$message,$citation)=@_;
 # Check if allowed missing  # Check if allowed missing
     my $status='';      my $status='';
     my $msgid='undefined';      my $msgid='undefined';
Line 169  sub user_normal_msg { Line 176  sub user_normal_msg {
     my $homeserver=&Apache::lonnet::homeserver($user,$domain);      my $homeserver=&Apache::lonnet::homeserver($user,$domain);
     if ($homeserver ne 'no_host') {      if ($homeserver ne 'no_host') {
        my $msgid;         my $msgid;
        ($msgid,$message)=&packagemsg($subject,$message);         ($msgid,$message)=&packagemsg($subject,$message,$citation);
        $status=&Apache::lonnet::critical(         $status=&Apache::lonnet::critical(
            'put:'.$domain.':'.$user.':nohist_email:'.             'put:'.$domain.':'.$user.':nohist_email:'.
            &Apache::lonnet::escape($msgid).'='.             &Apache::lonnet::escape($msgid).'='.
Line 183  sub user_normal_msg { Line 190  sub user_normal_msg {
     return $status;      return $status;
 }  }
   
   # =============================================================== Status Change
   
   sub statuschange {
       my ($msgid,$newstatus)=@_;
       my %status=&Apache::lonnet::get('email_status',[$msgid]);
       if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
       unless ($status{$msgid}) { $status{$msgid}='new'; }
       unless (($status{$msgid} eq 'replied') || 
               ($status{$msgid} eq 'forwarded')) {
    &Apache::lonnet::put('email_status',{$msgid => $newstatus});
       }
   }
 # ===================================================================== Handler  # ===================================================================== Handler
   
   sub discrit {
       my $r=shift;
         $r->print('<h1><font color=red>Critical Messages</font></h1>'.
            '<form action=/adm/email method=post>'.
            '<input type=hidden name=confirm value=true>');
         my %what=&Apache::lonnet::dump('critical');
         map {
             my %content=&unpackagemsg($what{$_});
             $content{'message'}=~s/\n/\<br\>/g;
     $r->print('<hr>From: <b>'.$content{'sendername'}.'@'.
                       $content{'senderdomain'}.'</b> ('.$content{'time'}.
                       ')<br><blockquote>'.$content{'message'}.'</blockquote>'.
     '<input type=submit name="rec_'.$_.'" value="Confirm Receipt">');
         } sort keys %what;
         $r->print('</form>');
   }
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
   
Line 202  sub handler { Line 238  sub handler {
        $value =~ tr/+/ /;         $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
        if (($name eq 'display') || ($name eq 'replyto') ||          if (($name eq 'display') || ($name eq 'replyto') || 
            ($name eq 'forward') || ($name eq 'mark')) {             ($name eq 'forward') || ($name eq 'mark') ||
              ($name eq 'sendreply') || ($name eq 'compose') ||
              ($name eq 'sendmail') || ($name eq 'critical')) {
            unless ($ENV{'form.'.$name}) {             unless ($ENV{'form.'.$name}) {
               $ENV{'form.'.$name}=$value;                $ENV{'form.'.$name}=$value;
    }     }
Line 212  sub handler { Line 250  sub handler {
 # --------------------------------------------------------------- Render Output  # --------------------------------------------------------------- Render Output
       
   $r->print('<html><head><title>EMail and Messaging</title></head>');    $r->print('<html><head><title>EMail and Messaging</title></head>');
   $r->print('<body bgcolor="#FFFFFF">');    $r->print(
      '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
   $r->print('<h1>EMail</h1>');    $r->print('<h1>EMail</h1>');
   if ($ENV{'form.display'}) {    if ($ENV{'form.display'}) {
         my $msgid=$ENV{'form.display'};
         &statuschange($msgid,'read');
         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
         my %content=&unpackagemsg($message{$msgid});
         $r->print('<b>Subject:</b> '.$content{'subject'}.
                '<br><b>From:</b> '.$content{'sendername'}.' at '.
                                    $content{'senderdomain'}.
                '<br><b>Time:</b> '.$content{'time'}.'<hr>Functions: '.
                '<a href="/adm/email?replyto='.&Apache::lonnet::escape($msgid).
                '"><b>Reply</b></a><hr><pre>'.
                $content{'message'}.'</pre><hr>'.$content{'citation'});
   } elsif ($ENV{'form.replyto'}) {    } elsif ($ENV{'form.replyto'}) {
         my $msgid=$ENV{'form.replyto'};
         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
         my %content=&unpackagemsg($message{$msgid});
         my $quotemsg='> '.$content{'message'};
         $quotemsg=~s/\r/\n/g;
         $quotemsg=~s/\f/\n/g;
         $quotemsg=~s/\n+/\n\> /g;
         my $subject='Re: '.$content{'subject'};
         my $dispcrit='';
         if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
            $dispcrit=
        '<input type=checkbox name=critmsg> Send as critical message<p>';
         }
         $r->print(<<"ENDREPLY");
   <form action="/adm/email" method=post>
   <input type=hidden name=sendreply value="$msgid">
   Subject: <input type=text size=50 name=subject value="$subject"><p>
   <textarea name=message cols=60 rows=10>
   $quotemsg
   </textarea><p>
   $dispcrit
   <input type=submit value="Send Reply">
   </form>
   ENDREPLY
     } elsif ($ENV{'form.sendreply'}) {
         my $msgid=$ENV{'form.sendreply'};
         my %message=&Apache::lonnet::get('nohist_email',[$msgid]);
         my %content=&unpackagemsg($message{$msgid});
         &statuschange($msgid,'replied');
         if (($ENV{'form.critmsg'}) && 
             (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
            $r->print('Sending critical: '.
                   &user_crit_msg($content{'sendername'},
                                    $content{'senderdomain'},
                                    $ENV{'form.subject'},
                                    $ENV{'form.message'}));
         } else {
            $r->print('Sending: '.&user_normal_msg($content{'sendername'},
                                    $content{'senderdomain'},
                                    $ENV{'form.subject'},
                                    $ENV{'form.message'}));
         }
     } elsif ($ENV{'form.confirm'}) {
         map {
             if ($_=~/^form\.rec\_(.*)$/) {
         $r->print('<b>Confirming Receipt:</b> '.
                           &user_crit_received($1).'<br>');
             }
         } keys %ENV;
         &discrit($r);
     } elsif ($ENV{'form.critical'}) {
         &discrit($r);
   } elsif ($ENV{'form.forward'}) {    } elsif ($ENV{'form.forward'}) {
   } elsif ($ENV{'form.mark'}) {    } elsif ($ENV{'form.mark'}) {
     } elsif ($ENV{'form.compose'}) {
         my $dispcrit='';
         if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
            $dispcrit=
        '<input type=checkbox name=critmsg> Send as critical message<p>';
         }
         $r->print(<<"ENDCOMP");
   <form action="/adm/email" method=post>
   <input type=hidden name=sendmail value=on>
   Subject: <input type=text size=50 name=subject value=""><p>
   <textarea name=message cols=60 rows=10>
   </textarea><p>
   $dispcrit
   <input type=submit value="Send Mail">
   </form>
   ENDCOMP
     } elsif ($ENV{'form.sendmail'}) {
   } else {    } else {
     $r->print('<table border=2><tr><th>&nbsp</th><th>Date</th>'.      $r->print('<table border=2><tr><th>&nbsp</th><th>Date</th>'.
      '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');       '<th>Username</th><th>Domain</th><th>Subject</th><th>Status</th></tr>');
Line 229  sub handler { Line 348  sub handler {
         } elsif ($status eq 'read') {          } elsif ($status eq 'read') {
     $r->print('<tr bgcolor="#BBBB77">');      $r->print('<tr bgcolor="#BBBB77">');
         } elsif ($status eq 'replied') {          } elsif ($status eq 'replied') {
     $r->print('<tr bgcolor="#BBBB99">');      $r->print('<tr bgcolor="#AAAA88">');
  } else {   } else {
     $r->print('<tr bgcolor="#99BBBB">');      $r->print('<tr bgcolor="#99BBBB">');
         }          }

Removed from v.1.6  
changed lines
  Added in v.1.12


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