[pLog-svn] r2050 - in plugins/trunk: . mailcentre mailcentre/class mailcentre/class/action mailcentre/class/dao mailcentre/class/view mailcentre/locale mailcentre/templates

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sun May 22 23:21:08 GMT 2005


Author: oscar
Date: 2005-05-22 23:21:07 +0000 (Sun, 22 May 2005)
New Revision: 2050

Added:
   plugins/trunk/mailcentre/
   plugins/trunk/mailcentre/class/
   plugins/trunk/mailcentre/class/action/
   plugins/trunk/mailcentre/class/action/mailcentredeletesentmailaction.class.php
   plugins/trunk/mailcentre/class/action/mailcentresendmail.class.php
   plugins/trunk/mailcentre/class/action/mailcentresendmessage.class.php
   plugins/trunk/mailcentre/class/action/mailcentresentmail.class.php
   plugins/trunk/mailcentre/class/action/mailcentreuserselectoraction.class.php
   plugins/trunk/mailcentre/class/action/mailcentreviewsentmail.class.php
   plugins/trunk/mailcentre/class/dao/
   plugins/trunk/mailcentre/class/dao/mailmessage.class.php
   plugins/trunk/mailcentre/class/dao/mailmessages.class.php
   plugins/trunk/mailcentre/class/view/
   plugins/trunk/mailcentre/class/view/mailcentremessagelistview.class.php
   plugins/trunk/mailcentre/class/view/mailcentresendmessageview.class.php
   plugins/trunk/mailcentre/class/view/mailcentreuserselectorview.class.php
   plugins/trunk/mailcentre/locale/
   plugins/trunk/mailcentre/locale/locale_en_UK.php
   plugins/trunk/mailcentre/pluginmailcentre.class.php
   plugins/trunk/mailcentre/templates/
   plugins/trunk/mailcentre/templates/messagelist.template
   plugins/trunk/mailcentre/templates/sendmail.template
   plugins/trunk/mailcentre/templates/userselector.template
Log:
by popular request, this is the 'mailcentre' plugin that allows to send emails to users
registered in our site (and to other people too) It's only accessible to site admins and the 
plugin is very simple, but it allows to easy and quick communication to all blog users via email.

The plugin is not 100% ready yet so if any of you updates the _all_plugins.zip package in sf.net,
please do not forget not to include this one...

Now after this one, I hope people will stop requesting boring plugins... :P


Added: plugins/trunk/mailcentre/class/action/mailcentredeletesentmailaction.class.php
===================================================================
--- plugins/trunk/mailcentre/class/action/mailcentredeletesentmailaction.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/action/mailcentredeletesentmailaction.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,92 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentremessagelistview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/dao/mailmessages.class.php" );		
+
+    class MailCentreDeleteSentMailAction extends SiteAdminAction 
+	{
+
+        var $_messageIds;
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function MailCentreDeleteSentMailAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+			
+			$this->_mode = $actionInfo->getActionParamValue();
+			if( $this->_mode == "mailcentreDeleteMessage" ) {
+				$this->registerFieldValidator( "messageId", new IntegerValidator());
+            }
+			else
+				$this->registerFieldValidator( "messageIds", new ArrayValidator());
+				
+			$view = new MailCentreMessageListView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr("mailcentre_error_deleting_messages"));
+			$this->setValidationErrorView( $view );
+        }
+		
+		/**
+		 * sets up the parameters and calls the method below
+		 */
+		function perform()
+		{		
+			if( $this->_mode == "mailcentreDeleteMessage" ) {
+				$messageId = $this->_request->getValue( "messageId" );
+				$this->messageIds = Array();
+				$this->_messageIds[] = $messageId;
+			}
+			else
+				$this->_messageIds = $this->_request->getValue( "messageIds" );				
+				
+			$this->_deleteMessages();
+		}
+
+        /**
+         * deletes comments
+		 * @private
+         */
+        function _deleteMessages()
+        {
+            $messages = new MailMessages();
+            $errorMessage = "";
+			$successMessage = "";
+			$totalOk = 0;
+						
+			// loop through the messages and remove them
+            foreach( $this->_messageIds as $messageId ) {
+                $message = $messages->getMessage( $messageId );
+                if( !$message ) {
+                    $errorMessage .= $this->_locale->pr("mailcentre_error_deleting_message2", $messageId );
+                }
+                else {
+                    if( !$messages->deleteMessage( $messageId ))
+                        $errorMessage .= $this->_locale->pr("mailcentre_error_deleting_message", $message->getSubject())."<br/>";
+                    else {
+                        $totalOk++;
+                        if( $totalOk < 2 )
+                            $successMessage .= $this->_locale->pr("mailcentre_message_deleted_ok", $message->getSubject())."<br/>";
+                        else
+                            $successMessage = $this->_locale->pr("mailcentre_messages_deleted_ok", $totalOk );
+                    }
+				}
+            }
+
+			// if everything fine, then display the same view again with the feedback
+            $this->_view = new MailCentreMessageListView( $this->_blogInfo );
+			if( $successMessage != "" ) {
+				$this->_view->setSuccessMessage( $successMessage );
+			}
+			if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+            $this->setCommonData();
+
+            // better to return true if everything fine
+            return true;
+        }
+    }
+?>

Added: plugins/trunk/mailcentre/class/action/mailcentresendmail.class.php
===================================================================
--- plugins/trunk/mailcentre/class/action/mailcentresendmail.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/action/mailcentresendmail.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,16 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentresendmessageview.class.php" );
+	
+	class MailCentreSendMail extends SiteAdminAction
+	{
+		function perform()
+		{
+			$this->_view = new MailCentreSendMessageView( $this->_blogInfo );
+			$this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/action/mailcentresendmessage.class.php
===================================================================
--- plugins/trunk/mailcentre/class/action/mailcentresendmessage.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/action/mailcentresendmessage.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,132 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
+	include_once( PLOG_CLASS_PATH."class/mail/emailmessage.class.php" );	
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentresendmessageview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentremessagelistview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/dao/mailmessages.class.php" );
+	
+	class MailCentreSendMessage extends SiteAdminAction
+	{
+		
+		function MailCentreSendMessage( $actionInfo, $request )
+		{
+			$this->SiteAdminAction( $actionInfo, $request );
+			
+			$this->registerFieldValidator( "messageSubject", new StringValidator());
+			$this->registerFieldValidator( "messageText", new StringValidator());
+			$this->registerField( "messageRecipient" );
+			$this->registerField( "messageCc" );
+			$this->registerField( "messageBcc" );						
+			$view = new MailCentreSendMessageView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr("mailcentre_error_sending_message" ));
+			$this->setValidationErrorView( $view );		
+		}
+		
+		function perform()
+		{
+		    // extract the data
+		    $recipients = $this->_request->getValue( "messageRecipient" );
+		    $recipientsCc = $this->_request->getValue( "messageCc" );
+		    $recipientsBcc = $this->_request->getValue( "messageBcc" );
+		    $text = $this->_request->getValue( "messageText" );
+		    $subject = $this->_request->getValue( "messageSubject" );
+		    
+		    // check that we've got either a 'to','cc' or 'bcc'
+		    if( $recipients == "" && $recipientsCc == "" && $recipientsBcc == "" ) {
+		        // force an error
+    			$this->_view = new MailCentreSendMessageView( $this->_blogInfo );
+	   		    $this->_view->setErrorMessage( $this->_locale->tr("mailcentre_error_sending_message" ));
+	   		    $this->_form->setFieldValidationStatus( "messageRecipient", false );
+	   		    $this->setCommonData( true );
+		    }
+		    
+		    // pre-process some of the data
+		    $recipients = str_replace ( " ", "", $recipients );
+		    $recipientsCc = str_replace ( " ", "", $recipientsCc );
+		    $recipientsBcc = str_replace ( " ", "", $recipientsBcc );		    
+		    
+		    // and get the list of recipients
+		    $list = explode( ",", $recipients );
+		    $listCc = explode( ",", $recipientsCc );
+		    $listBcc = explode( ",", $recipientsBcc );
+		    
+		    // create a mail message that includes all the recipients
+		    $message = new EmailMessage();
+		    $val = new EmailValidator();
+		    $totalTo = 0;
+		    $totalCc = 0;
+		    $totalBcc = 0;
+		    foreach( $list as $to ) {
+		      // add each one of the recipients
+		      if( $val->validate( $to )) {
+    		      $message->addTo( $to );
+    		      $totalTo++;
+    		  }
+		    }
+		    foreach( $listCc as $cc ) {
+		      // add each one of the recipients
+      	      if( $val->validate( $cc )) {
+    		      $message->addCc( $cc );
+    		      $totalCc++;
+    		  }
+		    }
+		    foreach( $listBcc as $bcc ) {
+		      // add each one of the recipients
+      	      if( $val->validate( $bcc )) {
+    		      $message->addBcc( $bcc );
+    		      $totalBcc++;
+    		  }
+		    }
+		    
+		    // check that we are really sending the message to somebody
+		    if( $totalTo == 0 && $totalCc == 0 && $totalBcc == 0 ) {
+		        // force an error
+    			$this->_view = new MailCentreSendMessageView( $this->_blogInfo );
+	   		    $this->_view->setErrorMessage( $this->_locale->tr("mailcentre_error_sending_message" ));
+	   		    $this->_form->setFieldValidationStatus( "messageRecipient", false );
+	   		    $this->setCommonData( true );		    
+		    }
+		    
+		    // and now set the subject and body...
+		    $message->setSubject( $subject );
+		    $message->setBody( $text );
+		    // set the encoding based on the current blog settings
+		    $locale =& $this->_blogInfo->getLocale();
+		    $message->setCharset( $locale->getCharset());
+		    // and the "from" address
+		    $config =& Config::getConfig();
+		    $from = $config->getValue( "post_notification_source_address" );
+		    $message->setFrom( $from );
+		    
+		    // now send the message
+		    $service = new EmailService();
+		    if( !$service->sendMessage( $message )) {
+		      // if something went wrong, go back to the previous view
+		      $this->_view = new MailCentreSendMessageView( $this->_blogInfo );
+		      $this->_view->setErrorMessage( $this->_locale->tr( "mailcentre_error_sending_message" ));
+		      // show the view and keep the data that was in the form
+		      $this->setCommonData( true );
+		    }
+		    
+		    // if everything went ok, create our own MailMessage object and save it to the database
+		    $mailMessage = new MailMessage( $subject,
+		                                    $text,
+		                                    $recipients,
+		                                    $recipientsCc,
+		                                    $recipientsBcc );
+		    $mailMessages = new MailMessages();
+		    $mailMessages->addMessage( $mailMessage );
+		
+		    // show the resulting view
+			$this->_view = new MailCentreMessageListView( $this->_blogInfo );
+			$this->_view->setSuccessMessage( $this->_locale->tr("mailcentre_message_sent_ok"));
+            $this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/action/mailcentresentmail.class.php
===================================================================
--- plugins/trunk/mailcentre/class/action/mailcentresentmail.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/action/mailcentresentmail.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,22 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentremessagelistview.class.php" );
+	
+	class MailCentreSentMail extends SiteAdminAction
+	{
+		
+		function MailCentreSentMail( $actionInfo, $request )
+		{
+			$this->SiteAdminAction( $actionInfo, $request );
+		}
+		
+		function perform()
+		{
+			$this->_view = new MailCentreMessageListView( $this->_blogInfo );
+			$this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/action/mailcentreuserselectoraction.class.php
===================================================================
--- plugins/trunk/mailcentre/class/action/mailcentreuserselectoraction.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/action/mailcentreuserselectoraction.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,22 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentreuserselectorview.class.php" );
+		
+	class MailCentreUserSelectorAction extends SiteAdminAction
+	{
+		
+		function MailCentreUserSelectorAction( $actionInfo, $request )
+		{
+			$this->SiteAdminAction( $actionInfo, $request );			
+		}
+		
+		function perform()
+		{
+			$this->_view = new MailCentreUserSelectorView( $this->_blogInfo );
+			$this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/action/mailcentreviewsentmail.class.php
===================================================================
--- plugins/trunk/mailcentre/class/action/mailcentreviewsentmail.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/action/mailcentreviewsentmail.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,54 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentresendmessageview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/view/mailcentremessagelistview.class.php" );	
+    include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/dao/mailmessages.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+	
+	/**
+	 * displays a non-editable view of a message sent before
+	 */
+	class MailCentreViewSentMail extends SiteAdminAction
+	{
+	    function MailCentreViewSentMail( $actionInfo, $request )
+	    {
+	        $this->SiteAdminAction( $actionInfo, $request );
+	        
+	        // check that the message id parameter is valid
+	        $this->registerFieldValidator( "messageId", new IntegerValidator());
+	        $view = new MailCentreMessageListView( $this->_blogInfo );
+	        $view->setErrorMessage( $this->_locale->tr( "mailcentre_incorrect_message_id" ));
+	        $this->setValidationErrorView( $view );
+	    }
+	
+		function perform()
+		{
+		    // try to load the message
+		    $messageId = $this->_request->getValue( "messageId" );
+		    $mailMessages = new MailMessages();
+		    $message = $mailMessages->getMessage( $messageId );
+		    
+		    if( !$message ) {
+		        // if something went wrong loading the message, quit
+    	        $view = new MailCentreMessageListView( $this->_blogInfo );
+	            $view->setErrorMessage( $this->_locale->tr( "mailcentre_incorrect_message_id" ));
+	            $this->setValidationErrorView( $view );
+	            $this->setCommonData();
+	            return( false );    
+		    }
+		
+		    // pass the data to the template if everything's ok  
+			$this->_view = new MailCentreSendMessageView( $this->_blogInfo, false );
+			$this->_view->setValue( "messageRecipient", $message->getTo());
+			$this->_view->setValue( "messageBcc", $message->getBcc());
+			$this->_view->setValue( "messageCc", $message->getCc());			
+			$this->_view->setValue( "messageText", $message->getText());
+			$this->_view->setValue( "messageSubject", $message->getSubject());
+			$this->_view->setValue( "messageSentDate", $message->getSentTimestamp());
+			$this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/dao/mailmessage.class.php
===================================================================
--- plugins/trunk/mailcentre/class/dao/mailmessage.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/dao/mailmessage.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,80 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+	
+	class MailMessage extends Object
+	{
+	
+		var $_subject;
+		var $_text;
+		var $_to;
+		var $_sent;
+		var $_sentTimestamp;
+		var $_id;
+	
+		function MailMessage( $subject, $text, $to, $cc, $bcc, $sent = null, $id = -1 )
+		{
+			$this->Object();
+			
+			$this->_subject = $subject;
+			$this->_text = $text;
+			$this->_to = $to;
+			$this->_cc = $cc;
+			$this->_bcc = $bcc;
+			if( $sent == null ) {
+    			$this->_sentTimestamp = new Timestamp( $sent );			
+    			$this->_sent = $this->_sentTimestamp->getTimestamp();
+			}
+			else {
+    			$this->_sent = $sent;
+	   		    $this->_sentTimestamp = new Timestamp( $sent );
+			}
+			$this->_id = $id;
+		}
+		
+		function getId()
+		{
+			return( $this->_id );	
+		}
+		
+		function getSubject()
+		{
+			return( $this->_subject );	
+		}
+		
+		function getText()
+		{
+			return( $this->_text );	
+		}
+		
+		function getSent()
+		{
+			return( $this->_sent );	
+		}
+		
+		function getSentTimestamp()
+		{
+			return( $this->_sentTimestamp );	
+		}
+		
+		function getTo()
+		{
+			return( $this->_to );	
+		}
+		
+		function getCc()
+		{
+		    return( $this->_cc );
+		}
+		
+		function getBcc()
+		{
+		   return( $this->_bcc );
+		}
+		
+		function setId( $id )
+		{
+			$this->_id = $id;	
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/dao/mailmessages.class.php
===================================================================
--- plugins/trunk/mailcentre/class/dao/mailmessages.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/dao/mailmessages.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,124 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/dao/mailmessage.class.php" );
+
+    /**
+     * class that deals with messages that have been sent via the 
+     * 'mailcentre' plugin
+     */
+	class MailMessages extends Model
+	{
+	
+		function MailMessages()
+		{
+			$this->Model();
+		}
+		
+		/**
+		 * saves a new message to the database
+		 *
+		 * @param message a MailMessage object
+		 * @return true if successful or false otherwise
+		 */
+		function addMessage( &$message )
+		{
+            $prefix = $this->getPrefix();
+            $query = "INSERT INTO {$prefix}mailcentre_sent (recipients,recipients_cc,recipients_bcc,subject,body)
+                      VALUES ('".Db::qstr($message->getTo())."','".
+                      Db::qstr($message->getCc())."','".
+                      Db::qstr($message->getBcc())."','".
+                      Db::qstr($message->getSubject())."','".
+                      Db::qstr($message->getText())."')";
+                      
+            return( $this->Execute( $query ));
+		}
+		
+		/**
+		 * retrieves a message given its id
+		 *
+		 * @param messageId the id of the message we're trying to retrieve
+		 * @return a MailMessage object if successful or false otherwise
+		 */
+		function getMessage( $messageId )
+		{
+            $prefix = $this->getPrefix();
+            $query = "SELECT * FROM {$prefix}mailcentre_sent
+                      WHERE id = '".Db::qstr($messageId)."'";
+            
+            $result = $this->Execute( $query );
+            
+            if( !$result ) 
+                return false;
+                      
+            $row = $result->FetchRow();
+            
+            return( $this->_mapRow( $row ));
+		}
+		
+		/**
+		 * Deletes a sent message
+		 *
+		 * @param messageId The id of the message that we'd like to delete
+		 * @return true if successful or false otherwise
+		 */
+		function deleteMessage( $messageId )
+		{
+            $prefix = $this->getPrefix();
+            $query = "DELETE FROM {$prefix}mailcentre_sent
+                      WHERE id = '".Db::qstr($messageId)."'";
+                      
+            $result = $this->Execute( $query );
+            
+            // if there was an error with the query or no rows were affected,
+            // then something went definitely wrong...
+            if( !$result ) 
+                return false;
+                
+            if( $this->_db->Affected_Rows() == 0 )
+                return false;
+
+            return( true );                      
+		}
+		
+		/**
+		 * Retrives all the messages that have been sent from the database
+		 *
+		 *Ê@return an array of MailMessage objects or false otherwise
+		 */
+		function getMessages()
+		{
+			$prefix = $this->getPrefix();
+			$query = "SELECT * FROM {$prefix}mailcentre_sent ORDER BY date DESC";
+			
+			$result = $this->Execute( $query );
+			
+			if( !$result )
+				return Array();
+			
+			$messages = Array();	
+			while( $row = $result->FetchRow()) {
+				$messages[] = $this->_mapRow( $row );
+			}
+			
+			return( $messages );
+		}
+		
+		/**
+		 * @private
+		 * Maps a row from the database to a MailMessage object
+		 */
+		function _mapRow( $row )
+		{
+			$message = new MailMessage( $row["subject"],
+			                            $row["body"],
+			                            $row["recipients"],
+			                            $row["recipients_cc"],
+			                            $row["recipients_bcc"],
+			                            $row["date"],
+			                            $row["id"] );
+			                 
+			return( $message );
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/view/mailcentremessagelistview.class.php
===================================================================
--- plugins/trunk/mailcentre/class/view/mailcentremessagelistview.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/view/mailcentremessagelistview.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,24 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/mailcentre/class/dao/mailmessages.class.php" );
+	
+	class MailCentreMessageListView extends AdminPluginTemplatedView
+	{		
+		function MailCentreMessageListView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "mailcentre", "messagelist" );
+		}
+		
+		function render()
+		{
+			// load all the mail messages sent so far
+			$messages = new MailMessages();
+			$allMessages = $messages->getMessages();
+			
+			$this->setValue( "messages", $allMessages );
+			
+			parent::render();
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/view/mailcentresendmessageview.class.php
===================================================================
--- plugins/trunk/mailcentre/class/view/mailcentresendmessageview.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/view/mailcentresendmessageview.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,23 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+	
+	class MailCentreSendMessageView extends AdminPluginTemplatedView
+	{
+	    var $_editable;
+			
+		function MailCentreSendMessageView( $blogInfo, $editable = true )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "mailcentre", "sendmail" );
+			
+			$this->_editable = $editable;
+		}
+		
+		function render()
+		{
+		    $this->setValue( "editable", $this->_editable );
+		    
+		    parent::render();
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/class/view/mailcentreuserselectorview.class.php
===================================================================
--- plugins/trunk/mailcentre/class/view/mailcentreuserselectorview.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/class/view/mailcentreuserselectorview.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,93 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
+	
+    /**
+     * \ingroup View
+     * @private
+     *
+	 * shows a list with the users in the blog
+	 */
+	class MailCentreUserSelectorView extends AdminPluginTemplatedView
+	{
+		var $_status;
+		var $_page;
+		var $_dest;
+	
+		function MailCentreUserSelectorView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "mailcentre", "userselector" );		
+		}
+		
+		/**
+		 * retrieves the current status from the request
+		 *
+		 * @private
+		 * @return nothing
+		 */
+		function getStatusFromRequest()
+		{
+			$status = HttpVars::getRequestValue( "status" );
+			
+			// validate the value 
+			$val = new IntegerValidator();
+			if( !$val->validate( $status ))
+				$status = UserStatus::getDefaultStatus();
+				
+			// if the value validated, check if it is a valid status
+			if( !UserStatus::isValidStatus( $status ))
+				$status = UserStatus::getDefaultStatus();
+				
+			return $status;
+		}
+				
+		/**
+		 * @private
+		 */
+		function _getDestination()
+		{
+		    $dest = HttpVars::getRequestValue( "dest" );
+		    $val = new IntegerValidator();
+		    if( !$val->validate( $dest ) || $dest < 1 || $dest > 3 )
+		      $dest = 1;
+		      
+		    return( $dest );
+		}
+		
+		function render()
+		{
+			// get the current page
+			$this->_page = $this->getCurrentPageFromRequest();
+			$this->_status = $this->getStatusFromRequest();
+			$this->_dest = $this->_getDestination();
+			
+        	// get the users of the blog
+            $users = new Users();
+            $siteUsers = $users->getAllUsers( $this->_status, true, $this->_page, DEFAULT_ITEMS_PER_PAGE );
+            $numUsers = $users->getNumUsers( $this->_status );
+            
+            // in case of problems, empty array...
+            if( !$siteUsers )
+            	$siteUsers = Array();
+            
+            // notify the event
+            $this->notifyEvent( EVENT_USERS_LOADED, Array( "users" => &$blogUsers ));
+            
+			// calculate the links to the different pages
+			$pager = new Pager( "?op=mailcentreUserSelector&amp;&dest=".$this->_page."&amp;status=".$this->_status."&amp;page=",
+			                    $this->_page, 
+								$numUsers, 
+								DEFAULT_ITEMS_PER_PAGE );
+            
+            // and generate the view
+            $this->setValue( "siteusers", $siteUsers );	
+            $this->setValue( "userstatus", UserStatus::getStatusList( true ));
+            $this->setValue( "pager", $pager );
+            $this->setValue( "currentstatus", $this->_status );
+            $this->setValue( "dest", $this->_dest );
+			parent::render();
+		}
+	}	
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/locale/locale_en_UK.php
===================================================================
--- plugins/trunk/mailcentre/locale/locale_en_UK.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/locale/locale_en_UK.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,29 @@
+<?php
+$messages["subject"] = "Subject";
+$messages["mailcentre_subject_help"] = "Message subject";
+$messages["to"] = "To";
+$messages["mailcentre_to_help"] = "Recipients of this message. Use the selector to find users from this site or type as many email addresses as needed, separated by commas";
+$messages["text"] = "Text";
+$messages["mailcentre_text_help"] = "Body of the message";
+$messages["send"] = "Send";
+$messages["composeMessage"] = "New Message";
+$messages["sentMail"] = "Sent Messages";
+$messages["mailcentre_sent"] = "Sent";
+$messages["mailcentre_sent_help"] = "This message was sent on";
+$messages["add_recipient"] = "Find user...";
+$messages["mailcentre_error_empty_subject"] = "The subject of the message cannot be empty";
+$messages["mailcentre_error_empty_recipient"] = "You must select at least one recipient for this message in either the To, Cc or Bcc fields";
+$messages["mailcentre_error_empty_text"] = "The body of the message cannot be empty";
+$messages["mailcentre_error_sending_message"] = "There was an error sending the message";
+$messages["mailcentre_message_sent_ok"] = "Message sent successfully";
+$messages["mailcentre_incorrect_message_id"] = "The message identifier is not correct";
+$messages["mailcentre_error_deleting_messages"] = "There was an error removing the messages";
+$messages["mailcentre_error_deleting_message2"] = "There was an error removing messge with identifier \"%s\"";
+$messages["mailcentre_error_deleting_message"] = "There was an error removing message \"%s\"";
+$messages["mailcentre_message_deleted_ok"] = "Message \"%s\" deleted successfully";
+$messages["mailcentre_messages_deleted_ok"] = "%s messages deleted successfully";
+$messages["bcc"] = "Bcc";
+$messages["cc"] = "Cc";
+$messages["mailcentre_bcc_help"] = "Blind carbon copy";
+$messages["mailcentre_cc_help"] = "Carbon copy";
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/pluginmailcentre.class.php
===================================================================
--- plugins/trunk/mailcentre/pluginmailcentre.class.php	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/pluginmailcentre.class.php	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,66 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+	
+	class PluginMailCentre extends PluginBase
+	{
+	
+		function PluginMailCentre()
+		{
+			$this->PluginBase();		
+		
+			$this->id = "mailcentre";
+			$this->desc = "Allows site administrators to send emails to registered users";
+			$this->locale = Array();				
+			
+			// register our menu entries
+			$this->addMenuEntry( "/menu/adminSettings", "MailCentre", "", "" );	
+			$this->addMenuEntry( "/menu/adminSettings/MailCentre", "composeMessage", "?op=mailcentreSendMail" );
+			$this->addMenuEntry( "/menu/adminSettings/MailCentre", "sentMail", "?op=mailcentreSentMail" );
+			
+			// register a few actions
+			$this->registerAdminAction( "mailcentreSendMail", "MailCentreSendMail" );
+			$this->registerAdminAction( "mailcentreSentMail", "MailCentreSentmail" );			
+			$this->registerAdminAction( "mailcentreSendMessage", "MailCentreSendMessage" );
+			$this->registerAdminAction( "mailcentreUserSelector", "MailCentreUserSelectorAction" );	
+			$this->registerAdminAction( "mailcentreShowMessage", "MailCentreViewSentMail" );
+			$this->registerAdminAction( "mailcentreDeleteMessage", "MailCentreDeleteSentMailAction" );
+			$this->registerAdminAction( "mailcentreDeleteMessages", "MailCentreDeleteSentMailAction" );			
+			
+			// and check if the database tables are there
+			$this->_checkTables();			
+		}
+		
+		/**
+		 * @private
+		 */
+		function _checkTables()
+		{
+			// create the table to keep track of the voters, so that people cannot vote
+			// more than once
+			$fields = "
+			      id I(10) NOTNULL PRIMARY AUTOINCREMENT,
+			      recipients TEXT NOTNULL DEFAULT '',
+			      recipients_cc TEXT NOTNULL DEFAULT '',
+			      recipients_bcc TEXT NOTNULL DEFAULT '',
+			      subject C(255) NOTNULL DEFAULT '',
+			      body XL NOTNULL DEFAULT '',
+				  date T(14) DEFDATE
+				  ";
+				  
+			$db =& Db::getDb();				  
+			$dbPrefix = Db::getPrefix();
+			$tableName = $dbPrefix."mailcentre_sent";
+
+			// create the data dictionary and create the table if necessary
+            $dict = NewDataDictionary( $db );
+            $sqlArray = $dict->ChangeTableSQL( $tableName, $fields );
+            $result = $dict->ExecuteSQLArray( $sqlArray );
+            
+            if( !$result )
+            	die( "There was an error creating the plugin tables!" );			
+			
+            return true;		
+		}			
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/mailcentre/templates/messagelist.template
===================================================================
--- plugins/trunk/mailcentre/templates/messagelist.template	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/templates/messagelist.template	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,42 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=sentMail title=$locale->tr("sentMessages")}
+        
+
+<form id="messages" action="admin.php" method="post">
+<div id="list">
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+<table class="info">
+ <thead>
+  <tr>
+   <th style="width:10px;"><input class="checkbox" type="checkbox" class="check" name="all" id="all" value="1" onclick="toggleAllChecks('messages');" /></th>  
+   <th style="width:600px;">{$locale->tr("subject")}</th>
+   <th style="width:170px;">{$locale->tr("date")}</th>
+   <th style="width:95px;">{$locale->tr("actions")}</th>
+  </tr>
+ </thead>
+ <tbody>
+ {foreach from=$messages item=message}
+  <tr class="{cycle values="odd,even"}">
+   <td><input class="checkbox" type="checkbox" name="messageIds[{counter}]" value="{$message->getId()}"/></td>  
+   <td class="col_highlighted"><a href="?op=mailcentreShowMessage&amp;messageId={$message->getId()}">{$message->getSubject()}</a></td>
+   {assign var=sent value=$message->getSentTimestamp()}
+   <td>{$locale->formatDate($sent)}</td>
+   <td>
+     <div class="list_action_button">
+       <a href="?op=mailcentreShowMessage&amp;messageId={$message->getId()}"><img src="imgs/admin/icon_edit-16.png" alt="{$locale->tr("edit")}" /></a>
+       <a href="?op=mailcentreDeleteMessage&amp;messageId={$message->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" /></a>
+     </div>
+   </td>
+  </tr>
+ {/foreach}
+ </tbody>
+ </table>
+ </div>
+ <div id="list_action_bar">
+  <input type="hidden" name="op" value="mailcentreDeleteMessages"/>
+  <input type="submit" name="Delete selected" value="{$locale->tr("delete")}"/>
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file

Added: plugins/trunk/mailcentre/templates/sendmail.template
===================================================================
--- plugins/trunk/mailcentre/templates/sendmail.template	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/templates/sendmail.template	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,79 @@
+{include file="$admintemplatepath/header.template"}
+{if $editable}
+{include file="$admintemplatepath/navigation.template" showOpt=composeMessage title=$locale->tr("composeMessage")}
+{else}
+{include file="$admintemplatepath/navigation.template" showOpt=sentMail title=$locale->tr("viewMessage")}
+{/if}
+<script type="text/javascript" src="js/ui/forms.js"></script>
+<form name="newMailMessage" id="newMailMessage" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("Message")}</legend>  
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}   
+  
+  {if !$editable}
+  <div class="field">
+   <label for="sentDate">{$locale->tr("mailcentre_sent")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("mailcentre_sent_help")}</div>
+   <input type="text" name="sentDate" id="sendDate" value="{$locale->formatDate($messageSentDate)}" readonly="readonly" />
+  </div>  
+  {/if}
+  
+  <div class="field">
+   <label for="messageSubject">{$locale->tr("subject")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("mailcentre_subject_help")}</div>
+   <input type="text" name="messageSubject" id="messageSubject" value="{$messageSubject}" {if !$editable}readonly="readonly"{/if} />
+   {include file="$admintemplatepath/validate.template" field=messageSubject message=$locale->tr("mailcentre_error_empty_subject")}
+  </div>
+  
+  <div class="field">
+   <label for="messageRecipient">{$locale->tr("to")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("mailcentre_to_help")}</div>   
+   <input type="text" name="messageRecipient" style="width:50%" value="{$messageRecipient}" {if !$editable}readonly="readonly"{/if} />
+   {if $editable}<a href="javascript:window.open('?op=mailcentreUserSelector&amp;dest=1','UserSelector','scrollbars=yes,resizable=yes,toolbar=no,height=500,width=400');">{$locale->tr("add_recipient")}</a>{/if}
+   {include file="$admintemplatepath/validate.template" field=messageRecipient message=$locale->tr("mailcentre_error_empty_recipient")}
+  </div>
+  
+  <div class="field">
+   <label for="messageCc">{$locale->tr("cc")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("mailcentre_cc_help")}</div>   
+   <input type="text" name="messageCc" style="width:50%" value="{$messageCc}" {if !$editable}readonly="readonly"{/if} />
+   {if $editable}<a href="javascript:window.open('?op=mailcentreUserSelector&amp;dest=2','UserSelector','scrollbars=yes,resizable=yes,toolbar=no,height=500,width=400');">{$locale->tr("add_recipient")}</a>{/if}
+  </div>
+
+  <div class="field">
+   <label for="messageBcc">{$locale->tr("bcc")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("mailcentre_bcc_help")}</div>   
+   <input type="text" name="messageBcc" style="width:50%" value="{$messageBcc}" {if !$editable}readonly="readonly"{/if} />
+   {if $editable}<a href="javascript:window.open('?op=mailcentreUserSelector&amp;dest=3','UserSelector','scrollbars=yes,resizable=yes,toolbar=no,height=500,width=400');">{$locale->tr("add_recipient")}</a>{/if}
+  </div>
+  
+  
+  <div class="field">
+   <label for="messageText">{$locale->tr("text")}</label>
+   <span class="required">*</span>
+   <div class="formHelp">{$locale->tr("mailcentre_text_help")}</div>   
+   <textarea name="messageText" id="messageText" rows="15" style="width:100%" {if !$editable}readonly="readonly"{/if}>{$messageText}</textarea>
+   {include file="$admintemplatepath/validate.template" field=messageText message=$locale->tr("mailcentre_error_empty_text")}  
+  </div>
+  
+ </fieldset>  
+
+ <div class="buttons">
+  {if $editable}
+  <input type="hidden" name="op" value="mailcentreSendMessage" />  
+  <input type="reset" name="{$locale->tr("reset")}" />    
+  <input type="submit" name="{$locale->tr("send")}" value="{$locale->tr("send")}" />
+  {else}
+  <input type="hidden" name="op" value="mailcentreSentMail" />
+  <input type="submit" name="{$locale->tr("back")}" value="{$locale->tr("back")}" />
+  {/if}
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file

Added: plugins/trunk/mailcentre/templates/userselector.template
===================================================================
--- plugins/trunk/mailcentre/templates/userselector.template	2005-05-22 19:25:38 UTC (rev 2049)
+++ plugins/trunk/mailcentre/templates/userselector.template	2005-05-22 23:21:07 UTC (rev 2050)
@@ -0,0 +1,127 @@
+<html>
+ <head>
+  <meta http-equiv="Content-Type" content="text/html; charset={$locale->getCharset()}"/> 
+  <link rel="stylesheet" href="styles/admin.css" type="text/css" />
+  <title>pLog Admin</title>
+  <script type="text/javascript">
+   {literal}
+   function setEmailAddress(address,dest)
+   {
+    var field;
+    
+    if( dest == 1 )
+      field = parent.opener.document.newMailMessage.messageRecipient;
+    else if( dest == 2 )
+      field = parent.opener.document.newMailMessage.messageCc; 
+    else if( dest == 3 )
+      field = parent.opener.document.newMailMessage.messageBcc; 
+    else
+      field = parent.opener.document.newMailMessage.messageRecipient;
+   
+    if(field.value != '')
+     field.value+=','+address;
+    else
+     field.value+=address;
+     
+    return true; 
+   }
+   {/literal}
+  </script>
+  <style>{literal}
+   html,body {
+    margin           : 0px;
+    padding          : 0px;
+    background       : #FFFFFF;
+   }
+   #container
+   {
+    width            : 400px;
+    text-align       : left;
+    margin-left      : auto;
+    margin-right     : auto;
+   }
+.info
+{
+    margin-bottom    : 10px;
+    width            : 285px;
+}
+#list_action_bar
+{
+    width            : 285px;
+    padding          : 4px;
+}
+  {/literal}</style>
+ </head>
+
+        <div id="list_nav_bar">
+            <div id="list_nav_select">
+            
+<form id="viewUsers" action="admin.php" method="post">
+ <fieldset>
+  <legend>{$locale->tr("show_by")}</legend>
+   <div class="list_nav_option">
+    <label for="status">{$locale->tr("status")}</label>
+	<br />
+    <select name="status" id="status">
+    {foreach from=$userstatus key=name item=status}
+      <option value="{$status}" {if $currentstatus == $status} selected="selected"{/if}>{$locale->tr($name)}</option>
+    {/foreach}
+    </select>
+   </div>
+   <div class="list_nav_option">
+    <br />
+    <input type="hidden" name="op" value="mailcentreUserSelector">
+    <input type="submit" name="Show" value="{$locale->tr("show")}">
+   </div>
+  </fieldset> 
+ </form> 
+ </div>
+ <br style="clear:both">
+ </div>             
+ 
+        <form id="siteUsers" action="admin.php" method="post">
+        <div id="list">
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}
+            <table class="info">
+                <thead>
+                    <tr>
+                        <th style="width:135px;">{$locale->tr("username")}</th>
+                        <th style="width:175px;">{$locale->tr("email")}</th>
+                        <th style="width:50px;">{$locale->tr("status")}</th>
+                    </tr>
+                </thead>
+                <tbody>
+                   {foreach from=$siteusers item=siteuser}
+                    <tr class="{cycle values="odd,even"}">
+                        <td class="col_highlighted">
+                            <a href="javascript:setEmailAddress('{$siteuser->getEmail()}','{$dest}');">
+                             {$siteuser->getUsername()|truncate:20:"..."}
+                            </a>
+                        </td>
+                        <td>
+                            <a href="mailto:{$siteuser->getEmail()}">
+                            {$siteuser->getEmail()}
+                            </a>
+                        </td>
+                        <td>
+                          {foreach from=$userstatus key=name item=status}
+                           {if $siteuser->getStatus() == $status}
+                            {if $status == 2}<span style="color:red">{$locale->tr($name)}</span>
+							{else}{$locale->tr($name)}{/if}
+						   {/if}
+                          {/foreach}                           
+                        </td>
+                    </tr>
+                    {/foreach}
+                </tbody>
+            </table>
+        </div>        
+        <div id="list_action_bar">
+            {include file="$admintemplatepath/adminpager.template" style=list}
+            <a href="javascript:window.close()">{$locale->tr("close")}</a>
+        </div>
+	</form>
+</div>
+</body>
+</html>




More information about the pLog-svn mailing list