[pLog-svn] r5645 - in plog/trunk: class/action/admin templates/admin

mark at devel.lifetype.net mark at devel.lifetype.net
Wed Jul 11 12:51:56 EDT 2007


Author: mark
Date: 2007-07-11 12:51:55 -0400 (Wed, 11 Jul 2007)
New Revision: 5645

Added:
   plog/trunk/class/action/admin/adminreplyprivatemessageaction.class.php
   plog/trunk/class/action/admin/adminsendreplyprivatemessageaction.class.php
   plog/trunk/templates/admin/replyprivatemessage.template
Modified:
   plog/trunk/class/action/admin/adminreadinboxprivatemessageaction.class.php
   plog/trunk/class/action/admin/adminreadoutboxprivatemessageaction.class.php
   plog/trunk/templates/admin/readinboxprivatemessage.template
Log:
Now, we can reply message from read message page and messages list page. Almost done.

Modified: plog/trunk/class/action/admin/adminreadinboxprivatemessageaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminreadinboxprivatemessageaction.class.php	2007-07-11 10:34:16 UTC (rev 5644)
+++ plog/trunk/class/action/admin/adminreadinboxprivatemessageaction.class.php	2007-07-11 16:51:55 UTC (rev 5645)
@@ -26,9 +26,6 @@
 
 			// stuff for the data validation
 			$this->registerFieldValidator( "messageId", new IntegerValidator());
-			$this->_form->registerField( "senderName" );
-			$this->_form->registerField( "subject" );
-			$this->_form->registerField( "messageText" );
 			$errorView = new AdminInboxPrivateMessagesListView( $this->_blogInfo );
 			$errorView->setErrorMessage( $this->_locale->tr("error_incorrect_message_id"));
 			$this->setValidationErrorView( $errorView );

Modified: plog/trunk/class/action/admin/adminreadoutboxprivatemessageaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminreadoutboxprivatemessageaction.class.php	2007-07-11 10:34:16 UTC (rev 5644)
+++ plog/trunk/class/action/admin/adminreadoutboxprivatemessageaction.class.php	2007-07-11 16:51:55 UTC (rev 5645)
@@ -26,9 +26,6 @@
 
 			// stuff for the data validation
 			$this->registerFieldValidator( "messageId", new IntegerValidator());
-			$this->_form->registerField( "senderName" );
-			$this->_form->registerField( "subject" );
-			$this->_form->registerField( "messageText" );
 			$errorView = new AdminOutboxPrivateMessagesListView( $this->_blogInfo );
 			$errorView->setErrorMessage( $this->_locale->tr("error_incorrect_message_id"));
 			$this->setValidationErrorView( $errorView );

Added: plog/trunk/class/action/admin/adminreplyprivatemessageaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminreplyprivatemessageaction.class.php	                        (rev 0)
+++ plog/trunk/class/action/admin/adminreplyprivatemessageaction.class.php	2007-07-11 16:51:55 UTC (rev 5645)
@@ -0,0 +1,69 @@
+<?php
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/view/admin/admininboxprivatemessageslistview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/dao/privatemessages.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that shows a form of the private message
+     */
+    class AdminReplyPrivateMessageAction extends AdminAction
+	{
+
+    	var $_messageId;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminReplyPrivateMessageAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+
+			// stuff for the data validation
+			$this->registerFieldValidator( "messageId", new IntegerValidator());
+			$errorView = new AdminInboxPrivateMessagesListView( $this->_blogInfo );
+			$errorView->setErrorMessage( $this->_locale->tr("error_incorrect_message_id"));
+			$this->setValidationErrorView( $errorView );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+        	// fetch the private message
+			$this->_messageId = $this->_request->getValue( "messageId" );
+            $privateMessages = new PrivateMessages();
+            $privateMessage   = $privateMessages->getPrivateMessageByReceiverId( $this->_messageId, $this->_userInfo->getId() );
+            // show an error if we couldn't fetch the private message
+            if( !$privateMessage ) {
+            	$this->_view = new AdminInboxPrivateMessagesListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_private_message") );
+				$this->_view->setError( true );
+                $this->setCommonData();
+                return false;
+            } else {
+            	if( $privateMessage->getReceiverReadStatus() == PRIVATE_MESSAGE_RECEIVER_UNREAD ) {
+            		$privateMessage->setReceiverReadStatus( PRIVATE_MESSAGE_RECEIVER_READ );
+            		$privateMessages->updatePrivateMessage( $privateMessage );
+            	}
+        	}
+
+			$this->notifyEvent( EVENT_PRIVATE_MESSAGE_LOADED, Array( "privatemessage" => &$privateMessage ));
+            // otherwise show the form to edit its fields
+            $senderInfo = $privateMessage->getSenderInfo();
+        	$this->_view = new AdminTemplatedView( $this->_blogInfo, "replyprivatemessage" );
+            $this->_view->setValue( "receiverName", $senderInfo->getUsername() );
+            $this->_view->setValue( "subject", $this->_locale->tr( 'reply_string' ) . $privateMessage->getSubject() );
+            $this->setCommonData();
+
+            // better to return true if everything fine
+           return true;
+        }
+    }
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminsendreplyprivatemessageaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminsendreplyprivatemessageaction.class.php	                        (rev 0)
+++ plog/trunk/class/action/admin/adminsendreplyprivatemessageaction.class.php	2007-07-11 16:51:55 UTC (rev 5645)
@@ -0,0 +1,142 @@
+<?php
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/dao/privatemessages.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminoutboxprivatemessageslistview.class.php" );
+
+    /**
+     * \ingroup Action
+     * @private
+     *
+     * Action that adds a reply private message to the database.
+     */
+    class AdminSendReplyPrivateMessageAction extends AdminAction
+	{
+
+    	var $_receiverName;
+		var $_subject;
+		var $_replyText;
+		var $_receiverId;
+		var $_senderId;
+		var $_backupPrivateMessage;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminSendReplyPrivateMessageAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+
+			// register two validators
+			$this->registerFieldValidator( "receiverName", new StringValidator() );
+			$this->registerFieldValidator( "subject", new StringValidator() );
+			$this->registerFieldValidator( "replyText", new StringValidator() );
+			$this->registerField( "backupPrivateMessage" );
+			// and the view we should show in case there is a validation error
+			$errorView = new AdminTemplatedView( $this->_blogInfo, "replyprivatemessage" );
+			$errorView->setErrorMessage( $this->_locale->tr("error_sending_private_message" ));
+			$this->setValidationErrorView( $errorView );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+			// fetch the data, we already know it's valid and that we can trust it!
+			$this->_receiverName = Textfilter::filterAllHTML( $this->_request->getValue( "receiverName" ) );
+        	$this->_subject = Textfilter::filterAllHTML( $this->_request->getValue( "subject" ) );
+         	$this->_replyText = Textfilter::filterAllHTML( $this->_request->getValue( "replyText" ) );
+         	$this->_backupPrivateMessage = $this->_request->getValue("backupPrivateMessage") ? 1 : 0;
+
+			// check the receiver exist or not
+			lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
+			$users = new Users();
+			$receiver = $users->getUserInfoFromUsername( $this->_receiverName );
+
+        	// see if the user exists
+            if( !$receiver || $receiver->getId() == $this->_userInfo->getId() ) {
+            	$this->_view = new AdminTemplatedView( $this->_blogInfo, "replyprivatemessage" );
+                $this->_view->setErrorMessage( $this->_locale->pr("error_invalid_receiver", $this->_receiverName) );
+				$this->_form->setFieldValidationStatus( "receiverName", false );
+                $this->setCommonData( true );
+
+                return false;
+            }
+
+			// retrive receiverId & senderId
+			$this->_receiverId = $receiver->getId();
+			$this->_senderId = $this->_userInfo->getId();
+
+			// get private message inbox from receiver id
+			lt_include( PLOG_CLASS_PATH."class/dao/privatemessageboxes.class.php" );
+			$privateMessageBoxes = new PrivateMessageBoxes();
+			$receiverInbox = $privateMessageBoxes->getPrivateMessageInboxFromUserId( $this->_receiverId );
+
+			// create the private message object...
+    		lt_include( PLOG_CLASS_PATH."class/dao/privatemessages.class.php" );
+            $privateMessages = new PrivateMessages();
+			$receiverPrivateMessage = new PrivateMessage( $receiverInbox->getId(),
+                                                          $this->_receiverId,
+                                                          $this->_senderId,
+                                                          $this->_subject,
+                                                          $this->_replyText );
+
+			// fire the pre event...
+			$this->notifyEvent( EVENT_PRE_SEND_PRIVATE_MESSAGE, Array( "privatemessage" => &$receiverPrivateMessage ));
+
+            // once we have built the object, we can add it to the database!
+            if( $privateMessages->addPrivateMessage( $receiverPrivateMessage )) {
+                if( $this->_backupPrivateMessage ) {
+                    $senderOutbox = $privateMessageBoxes->getPrivateMessageOutboxFromUserId( $this->_senderId );
+                    $senderPrivateMessage = new PrivateMessage( $senderOutbox->getId(),
+                                                                $this->_receiverId,
+                                                                $this->_senderId,
+                                                                $this->_subject,
+                                                                $this->_replyText );
+                    $privateMessages->addPrivateMessage( $senderPrivateMessage );
+                }
+				$this->_view = new AdminOutboxPrivateMessagesListView( $this->_blogInfo );
+				$this->_view->setSuccess( true );
+				$this->_view->setSuccessMessage( $this->_locale->pr("private_message_sended_ok", $receiverPrivateMessage->getSubject()));
+				$this->notifyEvent( EVENT_POST_SEND_PRIVATE_MESSAGE, Array( "privatemessage" => &$receiverPrivateMessage ));
+
+				$this->sendPrivateMessageEmail( $receiver );
+
+				$this->setCommonData();
+            }
+            else {
+				// if there was an error, we should say so... as well as not changing the view since
+				$this->_view = new AdminTemplatedView( $this->_blogInfo, "replyprivatemessage" );
+				$this->_view->setError( true );
+				$this->_view->setErrorMessage( $this->_locale->tr("error_sending_private_message" ));
+				$this->setCommonData( true );
+            }
+
+            return true;
+        }
+
+        function sendPrivateMessageEmail( $userInfo )
+        {
+            // if everything went fine, we can now send the private message to the receiver
+            // only if the receiver specified a valid email address
+            if( $userInfo->getEmail() != "" ) {
+	            lt_include( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
+
+            	// build an email message
+                $emailMessage = new EmailMessage();
+                $emailMessage->setBody( $this->_replyText );
+                $emailMessage->setSubject( "[Private Message]" . $this->_subject );
+                $emailMessage->addTo( $userInfo->getEmail());
+                $emailMessage->setFrom( $this->_userInfo->getEmail());
+                // and finally send it
+                $emailService = new EmailService();
+                $emailService->sendMessage( $emailMessage );
+            }
+
+            return true;
+        }
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/readinboxprivatemessage.template
===================================================================
--- plog/trunk/templates/admin/readinboxprivatemessage.template	2007-07-11 10:34:16 UTC (rev 5644)
+++ plog/trunk/templates/admin/readinboxprivatemessage.template	2007-07-11 16:51:55 UTC (rev 5645)
@@ -30,9 +30,8 @@
   </fieldset>
   <div class="buttons">
    <input type="hidden" name="op" value="replyPrivateMessage" />
-   <input type="hidden" name="messageId" value="{$messageId}" />
-   <input type="button" name="Delete" value="{$locale->tr("delete")}" />
-   <input type="button" name="Reply" value="{$locale->tr("reply")}" />
+   <input type="button" name="Delete" value="{$locale->tr("delete")}" onClick="window.location='?op=deletePrivateMessage&messageId={$messageId}'" />
+   <input type="button" name="Reply" value="{$locale->tr("reply")}" onClick="window.location='?op=replyPrivateMessage&messageId={$messageId}'" />
   </div>
  </form>
 {include file="$blogtemplate/footernavigation.template"}

Added: plog/trunk/templates/admin/replyprivatemessage.template
===================================================================
--- plog/trunk/templates/admin/replyprivatemessage.template	                        (rev 0)
+++ plog/trunk/templates/admin/replyprivatemessage.template	2007-07-11 16:51:55 UTC (rev 5645)
@@ -0,0 +1,49 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=editInboxPrivateMessages title=$locale->tr("replyPrivateMessage")}
+
+ <form name="replyPrivateMessage" method="post" action="admin.php">
+  <fieldset class="inputField">
+   <legend>{$locale->tr("replyPrivateMessage")}</legend>
+   {include file="$admintemplatepath/formvalidate.template"}
+
+   <div class="field">
+    <label for="receiverName">{$locale->tr("receiver_name")}</label>
+    <span class="required">*</span><br/>
+    <div class="formHelp">{$locale->tr("receiver_name_help")}</div>
+     <input type="text" value="{$receiverName}" id="receiverName" name="receiverName" readonly=readonly />
+    {include file="$admintemplatepath/validate.template" field=receiverName message=$locale->tr("error_receiver_name")}
+   </div>
+
+   <div class="field">
+    <label for="subject">{$locale->tr("subject")}</label>
+    <span class="required">*</span><br/>
+    <div class="formHelp">{$locale->tr("subject_help")}</div>
+     <input type="text" value="{$subject}" id="subject" name="subject" />
+    {include file="$admintemplatepath/validate.template" field=subject message=$locale->tr("error_empty_subject")}
+   </div>
+
+   <div class="field">
+    <label for="replyText">{$locale->tr("reply_text")}</label>
+    <span class="required">*</span>
+    <div class="formHelp">{$locale->tr("reply_text_help")}</div>
+    <textarea name="replyText" cols="60" id="replyText" rows="5">{$messageText}</textarea>
+    {include file="$admintemplatepath/validate.template" field=replyText message=$locale->tr("error_empty_reply_text")}
+   </div>
+
+   <div class="field">
+    <label for="backupPrivateMessage">{$locale->tr("backup_private_message")}</label>
+    <div class="formHelp">
+     <input class="checkbox" type="checkbox" id="backupPrivateMessage" name="backupPrivateMessage" value="1" {if $backupPrivateMessage}checked="checked"{/if} />
+     {$locale->tr("backup_private_message_help")}
+    </div>
+   </div>
+
+  </fieldset>
+  <div class="buttons">
+   <input type="hidden" name="op" value="sendReplyPrivateMessage" />
+   <input type="reset" name="Reset" value="{$locale->tr("reset")}" />
+   <input type="submit" name="Add" value="{$locale->tr("send")}" />
+  </div>
+ </form>
+{include file="$blogtemplate/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file



More information about the pLog-svn mailing list