[Affelio-cvs 1168] CVS update: affelio/lib/Affelio/App/Standalone/Admin

Back to archive index

Tadashi Okoshi slash****@users*****
2006年 3月 22日 (水) 18:15:27 JST


Index: affelio/lib/Affelio/App/Standalone/Admin/Messaging.pm
diff -u affelio/lib/Affelio/App/Standalone/Admin/Messaging.pm:1.1 affelio/lib/Affelio/App/Standalone/Admin/Messaging.pm:1.2
--- affelio/lib/Affelio/App/Standalone/Admin/Messaging.pm:1.1	Tue Mar  7 23:39:09 2006
+++ affelio/lib/Affelio/App/Standalone/Admin/Messaging.pm	Wed Mar 22 18:15:27 2006
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
-# $Id: Messaging.pm,v 1.1 2006/03/07 14:39:09 slash5234 Exp $
+# $Id: Messaging.pm,v 1.2 2006/03/22 09:15:27 slash5234 Exp $
 
 package Affelio::App::Standalone::Admin::Messaging;
 {
@@ -38,8 +38,7 @@
 
     use Exporter;
     @Affelio::App::Standalone::Admin::Messaging::ISA = "Exporter";
-    @Affelio::App::Standalone::Admin::Messaging::EXPORT = qw (show_message_list show_message mark_as_read get_new compose send_message handler);
-
+    @Affelio::App::Standalone::Admin::Messaging::EXPORT = qw (show_message_list show_message mark_as_read get_new compose send_message delete_messages handler);
 
     #######################################################################
     #handler
@@ -55,49 +54,81 @@
 
 	if( $sub_mode eq "send_message" ){
 
+	    #send message
 	    try{
-		send_message($af, $cgi);
-		$out_ref->{ret_msg}
-		.= '<AF_M text="You message has been sent successfuly.">';
+		if( $wi->PTN_through($cgi->param("submit_send")) ){
+		    send_message($af, $cgi, "send");
+		    $out_ref->{ret_msg}
+		    .= '<AF_M text="Your message has been sent successfuly.">';
+		}else{
+		    send_message($af, $cgi, "justsave");
+		    $out_ref->{ret_msg}
+		    .= '<AF_M text="Your message has been saved.">';
+		}
 	    }catch Affelio::exception::CommunicationException with{
 		my $e = shift;
 		$out_ref->{err_msg} 
 		.= '<AF_M text="Could not send message."><BR>' . $e;
 	    };
 
-	    $out_ref->{tmpl_file}
-	    = "$af->{site__tmpl_dir}/owner_side/admin_showmessage_list.tmpl";
-
-	    show_message_list($af, $out_ref);
+	    show_message_list($af, "inbox", $out_ref);
 	    
+	}elsif( $sub_mode eq "operate" ){
+
+	    if( $wi->PTN_through($cgi->param("operate_delete")) ){
+		try{
+		    delete_messages($af, $cgi);
+		    $out_ref->{ret_msg}
+		    .= '<AF_M text="Messages were deleted.">';
+		}catch Affelio::exception::DBException with{
+		    my $e = shift;
+		    $out_ref->{err_msg} 
+		    .= '<AF_M text="Error occured."><BR>' . $e;
+		};
+
+		my $folder = $cgi->param("folder");
+		show_message_list($af, $folder, $out_ref);
+	    }
 	}elsif( $sub_mode eq "compose" ){
 	    
-	    $out_ref->{tmpl_file} = "$af->{site__tmpl_dir}/owner_side/admin_composemessage.tmpl";
-
+	    $out_ref->{tmpl_file} 
+	    = "$af->{site__tmpl_dir}/owner_side/admin_composemessage.tmpl";
 	    compose($af, $cgi, $out_ref);
 
 	}elsif( $sub_mode eq "show" ){
-	    $out_ref->{tmpl_file} = "$af->{site__tmpl_dir}/owner_side/admin_showmessage.tmpl";
+	    my $folder = $cgi->url_param("folder");
+	    if(!$folder){ $folder = "inbox";}
+
+	    if($folder eq "draft"){
+		$out_ref->{tmpl_file} = "$af->{site__tmpl_dir}/owner_side/admin_showmessage__draft.tmpl";
+	    }
+	    elsif($folder eq "sent"){
+		$out_ref->{tmpl_file} 
+		= "$af->{site__tmpl_dir}/owner_side/admin_showmessage__sent.tmpl";
+	    }else{
+		$out_ref->{tmpl_file} 
+		= "$af->{site__tmpl_dir}/owner_side/admin_showmessage.tmpl";
+	    }
 
 	    mark_as_read($af, $cgi->url_param("mid"));
 	    show_message($af, $cgi->url_param("mid"), $out_ref);
 
 	}else{
-	    $out_ref->{tmpl_file} = "$af->{site__tmpl_dir}/owner_side/admin_showmessage_list.tmpl";
-	
-	    show_message_list($af, $out_ref);
+	    my $folder = $cgi->url_param("folder");
+	    if(!$folder){ $folder = "inbox";}
+	    
+	    show_message_list($af, $folder, $out_ref);
 	}
 
     }
 
-
-
     #######################################################################
     #send_message
     #######################################################################    
     sub send_message{
 	my $af = shift;
 	my $cgi = shift;
+	my $mode = shift;
 
 	debug_print("StandAlone::Mesg::send: start.");
 
@@ -111,6 +142,26 @@
 	    $msg_to = $1;
 	}
 
+	###################################################################
+	#Save the message to draft folder
+	###################################################################
+	my $msg_to_nickname
+	    = $af->getFM->get_attribute_by_afid($msg_to, "nickname");
+	my $msg_to_url = "<A HREF=\"$msg_to\">$msg_to_nickname</A>";
+
+	my $mid = $af->getMESGM->post_message(from => $msg_to_url,
+					      title => $msg_title,
+					      type => "UserToUser/OneToOne",
+					      body =>  $msg_body,
+					      folder => 'draft',
+					      readflag => 1);	
+	if($mode eq "justsave"){
+	    return();
+	}
+
+	###################################################################
+	#Sending message to the peer (through SNS layer)
+	###################################################################
 	my $passAB = "";
 	try{
 	    $passAB = $af->getFM->get_attribute_by_afid($msg_to, "password");
@@ -135,6 +186,7 @@
 				msg_timestamp => get_timestamp(),
 				msg_title => $msg_title,
 				msg_body => $msg_body);
+
 	}catch Affelio::exception::NetworkException with{
 	    my $E = shift;
 	    throw Affelio::exception::CommunicationException($E);
@@ -143,6 +195,13 @@
 	    my $E = shift;
 	    error($cgi, "<PRE>Exception: " . $E .  "</PRE>");
 	};
+
+	###################################################################
+	#Move the message from "draft" to "sent"
+	###################################################################
+	$af->getMESGM->move_message(mid => $mid, 
+				    folder => "sent");
+
     }
 
 
@@ -250,7 +309,7 @@
 
 	debug_print("StandAlone::marK_as_read: start");
 
-	my $ret= $af->getMESGM->mark_as_read($mid);
+	my $ret= $af->getMESGM->mark_as_read(mid => $mid);
 
 	debug_print("StandAlone::marK_as_read: end");
     }
@@ -273,19 +332,24 @@
     #show_message
     #######################################################################    
     sub show_message{
-	my $wi = new Affelio::misc::WebInput;
+	debug_print("StandAlone::show_message: start.");
 
+	###################################################################
+	#Check input values
+	my $wi = new Affelio::misc::WebInput;
 	my $af = shift;
 	my $mid = shift;
 	$mid = $wi->PTN_num($mid);
 	my $output_ref = shift;
 
-	debug_print("StandAlone::show_message: start.");
-
-	my @message= $af->getMESGM->retrieve_message($mid);
+	###################################################################
+	#Retrieve specified message from DB
+	my @message= $af->getMESGM->retrieve_message(mid => $mid);
 	my ($msg_mid, $msg_timestamp, $msg_title, $msg_type,
-	    $msg_from, $msg_body, $msg_readflag) = @message;
+	    $msg_from, $msg_body, $msg_readflag, $msg_folder) = @message;
 
+	###################################################################
+	#Message processing and data prep...
 	if($msg_type=~ /Encode\-Base64/){
 	    $msg_body = decode_base64($msg_body);
 	}
@@ -294,19 +358,38 @@
 	$msg_timestamp = timestamp2string($msg_timestamp);
 
 	if($msg_type=~ /UserToUser/){
-	    my $reply_title = "Re: $msg_title";
-	    my $reply_body = $msg_body;
-	    $reply_body =~ s/\r\n/\n/g;
-	    $reply_body =~ s/\r/\n/g;
-	    $reply_body =~ s/\n/\n>>/g;
-	    $reply_body = "\r\n>>" . $reply_body;
-
+	    my $reply_title = "";
+	    my $reply_body = "";
 	    my $reply_to="";
-	    if($msg_from =~ /HREF="(.+)">/){
-		$reply_to = $1;
-	    }
+	    my $reply_HTML =""; 
+
+	    if($msg_from =~ /HREF="(.+)">/){ $reply_to = $1; }
 
-	    my $reply_HTML = <<EOT;
+	    if($msg_folder eq "draft" || $msg_folder eq "sent"){
+		#mesg in draft box
+		$reply_title = $msg_title;
+		$reply_body = $msg_body;
+		$reply_body =~ s/\r\n/\n/g;
+		$reply_body =~ s/\r/\n/g;
+
+		$reply_HTML = <<EOT;
+<FORM METHOD="POST" ACTION="admin.cgi?mode=messages&action=compose">
+<INPUT TYPE="hidden" NAME="reply_to" VALUE="$reply_to">
+<INPUT TYPE="hidden" NAME="reply_title" VALUE="$reply_title">
+<INPUT TYPE="hidden" NAME="reply_body" VALUE="$reply_body">
+<INPUT TYPE="submit" VALUE="<AF_M text="Edit again">">
+</FORM>
+EOT
+	    }else{
+		#mesg in inbox
+		$reply_title = "Re: $msg_title";
+		$reply_body = $msg_body;
+		$reply_body =~ s/\r\n/\n/g;
+		$reply_body =~ s/\r/\n/g;
+		$reply_body =~ s/\n/\n>>/g;
+		$reply_body = "\r\n>>" . $reply_body;
+
+		$reply_HTML = <<EOT;
 <FORM METHOD="POST" ACTION="admin.cgi?mode=messages&action=compose">
 <INPUT TYPE="hidden" NAME="reply_to" VALUE="$reply_to">
 <INPUT TYPE="hidden" NAME="reply_title" VALUE="$reply_title">
@@ -314,9 +397,10 @@
 <INPUT TYPE="submit" VALUE="<AF_M text="Reply">">
 </FORM>
 EOT
+            }		
             $$output_ref{"reply_HTML"} = $reply_HTML;
-
-       }
+	}
+	#if
 
 	if($msg_type!~ /HTML/){
 	    #URL ---> <A HREF="URL">URL</A>
@@ -337,37 +421,65 @@
 	# by using ad-hoc regexes....
 	if($msg_type =~ /UserToUser/){
 	    $msg_from =~ /<A HREF="(.*)">(.+)<\/A>/;
-	    debug_print("StandAlone::show_message_list: \t[$1]");
-	    debug_print("StandAlone::show_message_list: \t[$2]");
+	    debug_print("StandAlone::show_message: \t[$1]");
+	    debug_print("StandAlone::show_message: \t[$2]");
 	    
 	    $msg_from = '<A HREF="' . $af->{site__user_afid} . '/outgoing.cgi?dest_url=' . $1 . '" target="_blank">' . $2 . '</A>';
 	}
-	###########
 
+	###################################################################
+	#Set template file
 
+	###################################################################
+	#Set output data
 	$$output_ref{"msg_timestamp"} = $msg_timestamp;
 	$$output_ref{"msg_title"} = $msg_title;
 	$$output_ref{"msg_from"} = $msg_from;
 	$$output_ref{"msg_body"} = $msg_body;
-
-	$$output_ref{"url2list"} = "$af->{site__user_afid}/admin.cgi?mode=messages";
+	$$output_ref{"url2list"} 
+	= "$af->{site__user_afid}/admin.cgi?mode=messages&folder=$msg_folder";
 
 	debug_print("StandAlone::show_message: end.");
     }
 
     #######################################################################
+    #delete_messages
+    #######################################################################    
+    sub delete_messages{
+	debug_print("StandAlone::delete_messages: start.");
+	my $af = shift;
+	my $cgi = shift;
+
+	foreach my  $value ( $cgi->param("operate_msg") ){
+	    debug_print("StandAlone::delete_messages: [$value]");
+	    $af->getMESGM->delete_message(mid => $value);
+	}
+
+	debug_print("StandAlone::delete_messages: end.");
+    }
+
+
+    #######################################################################
     #show_message_list
     #######################################################################    
     sub show_message_list{
 	my $af = shift;
+	my $folder = shift;
 	my $output_ref = shift;
 
-	debug_print("StandAlone::show_message_list: start.");
+	debug_print("StandAlone::show_message_list: start. [$folder]");
 
 	my @ret_messages=();
 	$output_ref->{'messages'} = \@ret_messages;
+	$output_ref->{'folder'} = $folder;
 
-	my $messages= $af->getMESGM->retrieve_all_messages();
+	my $folder_postfix = "";
+	unless($folder eq "inbox"){
+	    $folder_postfix = "__" . $folder;
+	}
+	$output_ref->{tmpl_file}  = "$af->{site__tmpl_dir}/owner_side/admin_showmessage_list$folder_postfix.tmpl";
+
+	my $messages= $af->getMESGM->retrieve_all_messages(folder => $folder);
 
 	my @message=();
 	while(@message = $messages->fetchrow_array) {
@@ -398,10 +510,10 @@
 	    }
 	    ###########
 
-
-	    my $linkurl = "$af->{site__user_afid}/admin.cgi?mode=messages&action=show&mid=$msg_mid";
+	    my $linkurl = "$af->{site__user_afid}/admin.cgi?mode=messages&action=show&mid=$msg_mid&folder=$folder";
 	    push(@ret_messages, 
 		 {
+		     'msg_mid' => $msg_mid,
 		     'msg_title' => $msg_title,
 		     'msg_from' => $msg_from,
 		     'msg_timestamp' => $msg_timestamp,


Affelio-cvs メーリングリストの案内
Back to archive index