Skip to content
Browse files

Added the sendmessage pages and events inside the Marketing plug in.

Created a ContactMailing object that extend contacts and move the methods sendMessage and eventSendMessage to that new class
could not full test as local setup can't send emails with sendmail
Overal it seems to work.
  • Loading branch information...
1 parent 8976566 commit 8d0aeb92165fa635b2335865f56bd66bee3fe647 @philfree committed Jan 7, 2012
View
29 plugin/Marketing.conf.inc.php
@@ -24,17 +24,19 @@
);
// Classes
- include_once("plugin/Marketing/AutoResponder.class.php");
- include_once("plugin/Marketing/AutoResponderEmail.class.php");
+ include_once("plugin/Marketing/class/ContactMailing.class.php");
+ include_once("plugin/Marketing/class/AutoResponder.class.php");
+ include_once("plugin/Marketing/class/AutoResponderEmail.class.php");
//include_once("plugin/Marketing/WebForm.class.php");
- include_once("plugin/Marketing/WebFormField.class.php");
- include_once("plugin/Marketing/WebFormUserField.class.php");
- include_once("plugin/Marketing/WebFormUser.class.php");
+ include_once("plugin/Marketing/class/WebFormField.class.php");
+ include_once("plugin/Marketing/class/WebFormUserField.class.php");
+ include_once("plugin/Marketing/class/WebFormUser.class.php");
// blocks
- include_once("plugin/Marketing/BlockMarketing.class.php");
- include_once("plugin/Marketing/BlockWebFormList.class.php");
- include_once("plugin/Marketing/BlockEmailTemplateList.class.php");
-
+ include_once("plugin/Marketing/class/BlockMarketing.class.php");
+ include_once("plugin/Marketing/class/BlockWebFormList.class.php");
+ include_once("plugin/Marketing/class/BlockEmailTemplateList.class.php");
+
+ define('OFUZ_LOG_RUN_PLUGIN_MARKETING', true);
$cfg_plugin_mkt_path = "/Tab/Marketing/";
@@ -46,7 +48,7 @@
$GLOBALS['cfg_plugin_eventmultiple_placement']['contacts'][] =
Array('name'=> 'Send a Message ',
'confirm' => '',
- 'event' => 'do_Contacts->eventGetForMailMerge',
+ 'event' => 'ContactMailing->eventGetForMailMerge',
'action' => '');
@@ -73,7 +75,9 @@
"AutoResponder",
"AutoResponderEmail",
"AutoResponderEmailEdit",
- "settings_auto_responder_edit"
+ "settings_auto_responder_edit",
+ "SendMessage",
+ "SaveTemplate"
))
->setMenu($plugin_marketing_menu)
->setDefaultPage("MEmailTemplate");
@@ -86,6 +90,7 @@
// $GLOBALS['cfg_submenu_placement']['WebForm'] = $plugin_marketing_menu;
// $GLOBALS['cfg_submenu_placement']['WebFormURL'] = $plugin_marketing_menu;
// $GLOBALS['cfg_submenu_placement']['MEmailTemplate'] = $plugin_marketing_menu;
-
+ $GLOBALS['cfg_submenu_placement']['SendMessage'] = '';
+ $GLOBALS['cfg_submenu_placement']['SaveTemplate'] = '';
?>
View
11 plugin/Marketing/MEmailTemplate.php
@@ -42,15 +42,10 @@ function fnInsertMergeField(merge){
}
?>
<div class="banner50 pad020 text16 fuscia_text"><?php echo _('Email Templates'); ?></div>
- <div class="contentfull">
- <div class="messageshadow">
- <div class="messages">
<?php
$msg = new Message();
//echo $msg->getMessage('web form creator instruction');
?>
- </div>
- </div><br />
<div align="right">
<form id="select_merge_field">
<select name="merge_fields" onchange="fnInsertMergeField(this)">
@@ -88,9 +83,5 @@ function fnInsertMergeField(merge){
echo '<div align="right">'.$do_user_email_teml->form->getFormFooter(_('Create')).'</div>';
}
?>
- </div>
+
<div class="solidline"></div>
- </td></tr></table>
- <div class="spacerblock_40"></div>
- <div class="layout_footer"></div>
-</div>
View
52 contact_sendemail_save_template.php → plugin/Marketing/SaveTemplate.php
@@ -1,26 +1,15 @@
<?php
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
-// Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com
+// Copyright 2008 - 2012 all rights reserved, SQLFusion LLC, info@sqlfusion.com
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
/*
* contact_sendemail_save_tempatle.php
*
- * Copyright 2009 SQLFusion LLC, Philippe Lewicki <philippe@sqlfusion.com>
+ * Copyright 2009-2012 SQLFusion LLC, Philippe Lewicki <philippe@sqlfusion.com>
*
*/
-
- include_once('config.php');
- $pageTitle = _('Ofuz :: Contacts Send Email Save Template');
- $Author = 'SQLFusion LLC';
- $Keywords = 'Keywords for search engine';
- $Description = 'Description for search engine';
- $background_color = 'white';
-
- include_once('includes/ofuz_check_access.script.inc.php');
- include_once('includes/header.inc.php');
-
$do_message = new EmailTemplateUser("blank");
if ($_GET['idtemplate']) {
@@ -29,29 +18,18 @@
?>
-
-<table class="layout_columns"><tr><td class="layout_lmargin"></td><td>
-<div class="layout_content">
-
-
-<?php $thistab = 'Contacts'; include_once('includes/ofuz_navtabs.php');
-
- $do_breadcrumb = new Breadcrumb(); $do_breadcrumb->getBreadcrumbs(); ?>
- <div class="grayline1"></div>
- <div class="spacerblock_20"></div>
- <div class="mainheader">
- <div class="pad20">
- <span class="headline11"><?php echo _('Save Template');?></span>
- </div>
- </div>
- <div class="contentfull">
<div class="messageshadow">
<div class="messages">
<?php
- $msg = new Message();
- echo $msg->getMessage('save as template');
- echo "<br>".$_SESSION['in_page_message'] ;
- $_SESSION['in_page_message'] = '';
+ $message = new Message();
+ $message->getMessage("save as template");
+ $message->displayMessage();
+ if (!empty($_SESSION['in_page_message'])) {
+ $in_page_message = new Message();
+ $in_page_message->setContent($_SESSION['in_page_message'] );
+ $in_page_message->displayMessage();
+ $_SESSION['in_page_message'] = '';
+ }
?>
</div>
</div>
@@ -96,11 +74,3 @@
}
?>
-
-
-
- </div>
- <div class="spacerblock_40"></div>
- <div class="layout_footer"></div>
-</div>
-</td><td class="layout_rmargin"></td></tr></table>
View
44 contact_sendemail.php → plugin/Marketing/SendMessage.php
@@ -1,16 +1,6 @@
<?php
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
-// Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com
-/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
-
- $pageTitle = 'Ofuz :: Contacts Send Email';
- $Author = 'SQLFusion LLC';
- $Keywords = 'Keywords for search engine';
- $Description = 'Description for search engine';
- $background_color = 'white';
- include_once('config.php');
- include_once('includes/ofuz_check_access.script.inc.php');
- include_once('includes/header.inc.php');
+// Copyright 2008 - 2012 all rights reserved, SQLFusion LLC, info@sqlfusion.com
$do_message = new EmailTemplateUser("blank");
$do_message->sessionPersistent("do_message", "contacts.php", OFUZ_TTL);
@@ -20,6 +10,7 @@
$do_note_draft->sessionPersistent("do_message_draft","index.php",OFUZ_TTL);
}
?>
+
<script type="text/javascript">
//<![CDATA[
function fnInsertMergeField(merge){
@@ -108,23 +99,7 @@ function discardDraft(id){
});
//]]>
</script>
-<table class="layout_columns"><tr><td class="layout_lmargin"></td><td>
-<div class="layout_content">
-
-
-<?php $thistab = 'Contacts'; include_once('includes/ofuz_navtabs.php');
-
- $do_breadcrumb = new Breadcrumb(); $do_breadcrumb->getBreadcrumbs(); ?>
- <div class="grayline1"></div>
- <div class="spacerblock_20"></div>
- <div class="mainheader">
- <div class="pad20">
- <span class="headline11"><?php echo _('Send Message'); ?></span>
- </div>
- </div>
- <div class="contentfull">
- <div align="right">
- <?php echo _('Select an email template');
+<?php echo _('Select an email template');
echo '<form id="select_email_template"><select name="idtemplate" onchange=\'$("#select_email_template").submit();\'><option value="0"></option><option value="0">'._('New Template').'</option>';
$template_list = new EmailTemplateUser();
$template_list->query('SELECT * FROM '.$template_list->getTable().' WHERE iduser='.$_SESSION['do_User']->iduser.' AND name <> \'\'');
@@ -190,9 +165,9 @@ function discardDraft(id){
$do_message->form->setLevel(920);
$do_message->form->addEventAction('do_message_draft->eventDeleteSavedDraft', 900);//added to delete the draft
//$do_message->form->addEventAction('do_message->eventPrepareSaving', 920);
- $do_message->form->addEventAction('do_Contacts->eventSendMessage', 2340);
+ $do_message->form->addEventAction('do_ContactMailing->eventSendMessage', 2340);
$do_message->form->addEventAction('mydb.gotoPage', 2430);
- $do_message->form->goto = 'contact_sendemail_save_template.php';
+ $do_message->form->goto = $GLOBALS['cfg_plugin_mkt_path'].'SaveTemplate';
$do_message->form->type = 'contact_email';//Message Draft Type
$do_message->iduser = $_SESSION['do_User']->iduser;
$do_message->setFields("emailtemplate_user");
@@ -234,12 +209,3 @@ function discardDraft(id){
// echo '<br/><div align="right">'._('Or').' '.$do_message->name.' '.$do_message->form->getFormFooter(_('Save as template')).'</div>';
// }
?>
- </div>
- <div class="spacerblock_40"></div>
- <div class="layout_footer"></div>
-</div>
-</td><td class="layout_rmargin"></td></tr></table>
-
-</body>
-</html>
-
View
0 plugin/Marketing/AutoResponder.class.php → ...n/Marketing/class/AutoResponder.class.php
File renamed without changes.
View
0 ...in/Marketing/AutoResponderEmail.class.php → ...keting/class/AutoResponderEmail.class.php
File renamed without changes.
View
0 ...arketing/BlockEmailTemplateList.class.php → ...ng/class/BlockEmailTemplateList.class.php
File renamed without changes.
View
0 plugin/Marketing/BlockMarketing.class.php → .../Marketing/class/BlockMarketing.class.php
File renamed without changes.
View
0 plugin/Marketing/BlockWebFormList.class.php → ...arketing/class/BlockWebFormList.class.php
File renamed without changes.
View
259 plugin/Marketing/class/ContactMailing.class.php
@@ -0,0 +1,259 @@
+<?php
+// Copyright 2008 - 2012 all rights reserved, SQLFusion LLC, info@sqlfusion.com
+/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html
+ **/
+
+
+ /**
+ * ContactMailing class
+ * Using the Contact and DataObject
+ *
+ * Method to reuse:
+ * sendMessage() its a very simple and easy way to send messages to contacts.
+ *
+ *
+ * @author SQLFusion's Dream Team 2 <info@sqlfusion.com>
+ * @package Marketing
+ * @license GNU Affero General Public License
+ * @version 0.6
+ * @date 2010-09-03
+ * @since 0.1
+ */
+
+class ContactMailing extends Contact {
+
+ function __construct(sqlConnect $conx=NULL, $table_name="") {
+ parent::__construct($conx, $table_name);
+ if (RADRIA_LOG_RUN_OFUZ) {
+ $this->setLogRun(OFUZ_LOG_RUN_PLUGIN_MARKETING);
+ }
+
+ $this->setLog("\n ContactMailing Object instantiated");
+ }
+
+ /**
+ * eventGetForMailMerge
+ * Get the list of contact for mailmerge
+ * load in the current contact object the list of
+ * selected contacts from the contacts.php
+ * Then redirect to the contact_sendemail.php.
+ */
+ function eventGetForMailMerge(EventControler $event_controler) {
+
+ $idcontacts = $event_controler->getParam("ck");
+ $sql_in = "(";
+ foreach($idcontacts as $idcontact) {
+ $sql_in .= $idcontact.",";
+ }
+ $sql_in = substr($sql_in, 0, -1);
+ $sql_in .= ")";
+ $tag_search = $this->getSearchTags();
+ if(is_array($tag_search) && count($tag_search > 0)){
+ $_SESSION['searched_tags'] = $tag_search ;
+ }
+
+ $this->clearSearch();
+ $this->setSqlQuery("SELECT * FROM contact WHERE idcontact in ".$sql_in);
+ $this->sessionPersistent("do_ContactMailing", "contacts.php", 36000);
+ $event_controler->goto = $GLOBALS['cfg_plugin_mkt_path']."SendMessage";
+ //$event_controler->setDisplayNext(new Display($GLOBALS['cfg_plugin_mkt_path']."SendMessage/"));
+ }
+
+ /**
+ * eventSendMessage
+ * This will send a message to one or multiple users.
+ * @todo Problem with the getBodyText(true) it returns some bad encoding and no newline, could also be the problem in the template it self...
+ */
+
+ function eventSendMessage(EventControler $event_controler) {
+ $this->setLog("\n eventSendMessage (".date("Y/m/d H:i:s").")");
+ if ($event_controler->send == _('Send Mailing')) {
+ $email_template = $_SESSION['do_message'];
+ $email_template->setApplyFieldFormating(false);
+ $this->setLog("\n EmailTemplate id: ".$email_template->getPrimarykeyValue());
+ //$this->setLogObject($email_template);
+ $this->setLog("\n SQL:".$this->getSqlQuery());
+ $this->query();
+ $this->setLog("\n ".$this->getNumRows()." contacts to send the message");
+
+ while ($this->next()) {
+ set_time_limit(500);
+ if($event_controler->unsubtag == 'on'){ // set unsubscribe auto-responder list
+ $values_contact = $this->getValues();
+ $tag_values = array("flag"=>"unsubscribe_autoresponder","idtag"=>$event_controler->idtag);
+ $values = array_merge($values_contact,$tag_values);
+ $message = $this->sendMessage($email_template, $values);
+ }else{
+ $message = $this->sendMessage($email_template, $this->getValues());
+ }
+ if ($this->last_message_sent) {
+ //$do_contact_notes->iduser = $_SESSION['do_User']->iduser;
+ $do_contact_notes = new ContactNotes();
+ $do_contact_notes->iduser = $_SESSION['do_User']->iduser;
+ //$do_contact_notes->note = '<b>'.$message->getSubject().'</b><br/>'.$message->getBodyText(true);
+ //->getTemplateBodyHtml();
+ $note_text = preg_replace('/^(.*?)<hr>.*$/','$1',str_replace("\n",'',$message->getBodyHtml(true)));
+ $do_contact_notes->note = '<b>'.$message->getSubject().'</b><br/>'.$note_text;
+ $do_contact_notes->date_added = date("Y-m-d");
+ $do_contact_notes->idcontact = $this->getPrimaryKeyValue();
+ $do_contact_notes->add();
+
+
+ /*
+ * Recording the messages sent by User
+ */
+ $msg_con = new sqlQuery($this->getDbCon());
+ $sql_msg_check = "SELECT * FROM `message_usage` WHERE `iduser` = ".$_SESSION['do_User']->iduser." AND `date_sent` = '".date("Y-m-d")."'";
+ $msg_con->query($sql_msg_check);
+ if($msg_con->getNumRows()) {
+ $msg_con->fetch();
+ $sql_con_update = new sqlQuery($this->getDbCon());
+ $sql_msg_update = "UPDATE `message_usage` SET `num_msg_sent` = num_msg_sent+1 WHERE `idmessage_usage` = ".$msg_con->getData("idmessage_usage");
+ $sql_con_update->query($sql_msg_update);
+ } else {
+ $sql_con_ins = new sqlQuery($this->getDbCon());
+ $sql_msg_ins = "INSERT INTO `message_usage`(iduser,date_sent,num_msg_sent) VALUES(".$_SESSION['do_User']->iduser.",'".date("Y-m-d")."',1)";
+ $sql_con_ins->query($sql_msg_ins);
+ }
+
+
+
+ }
+ }
+ } else { $event_controler->goto = "contacts.php"; }
+ $this->clearSearch();
+ $this->free();
+ }
+
+ /**
+ * eventSendNote
+ * This event is triggered when adding a note in a contact
+ * It will send a copy of the note the contact.
+ */
+
+ function eventSendNote(EventControler $event_controler) {
+ $send_note = $event_controler->fields['send_email'];
+ $this->setLog("eventSendNote starting (".date("Y/m/d H:i:s").")");
+ $this->setLog("do we send a message:".$send_note);
+ if ($send_note == "y") {
+ $template = new EmailTemplate();
+ $template->setSubject("{Ofuz} Message: ".substr($event_controler->fields['note'], 0, 70)."...")
+ ->setMessage($event_controler->fields['note']);
+ $this->sendMessage($template);
+ }
+ }
+
+ /**
+ * sendMessage
+ * This abstract the message sending so we use a general function
+ * that will send email or facebook or twitter based on the user
+ * preferences and settings.
+ * its possible to generate an EmailTemplate on the fly with no records in the DB
+ * Here is an exemple:
+ * <code php>
+ * $do_template = new EmailTemplate();
+ * $do_template->senderemail = "philippe@sqlfusion.com";
+ * $do_template->sendername = "Philippe Lewicki";
+ * $do_template->subject = "This is an example";
+ * $do_template->bodytext = "This is the content of the sample message";
+ * $do_template->bodyhtml = nl2br($do_template->bodytext);
+ * </code>
+ *
+ * An other example more OO / stylish
+ * <code php>
+ * $do_template = new EmailTemplate();
+ * $do_template->setFrom("phil@sqlfusion.com", "Philippe Lewicki")
+ * ->setSubject("This is an example")
+ * ->setMessage("This is the content of the sample message");
+ * </code>
+ * setFrom() is optional, if not provided it takes the do_User data
+ *
+ * Then send the message with: $contact->sendMessage($do_template);
+ *
+ * If you used a saved EmailTemplate like
+ * $do_template = new EmailTemplate("my template in email template table");
+ * and want the sender to be the currently signed in user, make sure the senderemail field
+ * is empty.
+ *
+ * @param $message an EmailTemplate object.
+ * @param $values an array with values to merge, optional.
+ *
+ */
+ function sendMessage($template, $values=Array()) {
+ if (!is_object($template)) { return false; }
+ if (empty($values)) { $values = $this->getValues(); }
+ $this->last_message_sent = false;
+ $do_contact_email = $this->getChildContactEmail();
+ $email_to = $do_contact_email->getDefaultEmail();
+ $this->setLog("\n Sending message to:".$email_to);
+ $contact_link = '<a href="/Contact/'.$this->idcontact.'">'.$this->firstname.' '.$this->lastname.'</a>';
+ if (strlen($email_to) > 4) {
+ if ($this->email_optout != 'y') {
+ $emailer = new Ofuz_Emailer('UTF-8');
+ if (strlen($template->senderemail) == 0) {
+ $template->setFrom($_SESSION['do_User']->email, $_SESSION['do_User']->getFullName());
+ }
+ $emailer->setEmailTemplate($template);
+ $emailer->mergeArrayWithFooter($values);
+ $emailer->addTo($email_to);
+ $this->last_message_sent = true;
+ return $emailer->send();
+ } else {
+ $_SESSION['in_page_message'] .= _("<br>".$contact_link." has opt-out and will not receive this email");
+ }
+ } elseif (strlen($this->tw_user_id) > 0) {
+ // send direct message using twitter api.
+ try{
+ $do_twitter = new OfuzTwitter();
+ $tw_config = $do_twitter->getTwitterConfig();
+ $serialized_token = $do_twitter->getAccessToken();
+ $token = unserialize($serialized_token);
+ $ofuz_twitter = new Ofuz_Service_Twitter($token->getParam('user_id'), $tw_config, $token);
+ $followers = $ofuz_twitter->userFollowers(false);
+ if (is_object($followers) && count($followers->user) > 0) {
+ foreach ($followers->user as $follower) {
+ if ($follower->id == $this->tw_user_id) {
+ $merge = new MergeString();
+ $message = $merge->withArray($template->bodytext, $values);
+ $ofuz_twitter->directMessageNew($this->tw_user_id, $message);
+ $do_contact_notes = new ContactNotes();
+ $do_contact_notes->iduser = $_SESSION['do_User']->iduser;
+ $do_contact_notes->note = $message;
+ $do_contact_notes->date_added = date('Y-m-d');
+ $do_contact_notes->idcontact = $this->idcontact;
+ $do_contact_notes->add();
+ return true;
+ }
+ }
+ }
+ $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to ".$contact_link);
+ }catch(Exception $e){
+ $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to ".$contact_link);
+ }
+ } elseif ($this->fb_userid && $_SESSION["do_User"]->global_fb_connected) {
+ // send message using facebook api.
+ include_once 'facebook_client/facebook.php';
+ include_once 'class/OfuzFacebook.class.php';
+ $facebook = new Facebook(FACEBOOK_API_KEY, FACEBOOK_APP_SECRET);
+ try{
+ $msg = _(' has sent the following message using ofuz').'<br />';
+ $msg .= '<b>'.$template->subject.'</b><br/>'.$template->bodyhtml;
+ $facebook->api_client->notifications_send($this->fb_userid, $msg, 'user_to_user');
+ //$this->last_message_sent = true;
+ }catch(Exception $e){
+ $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to ".$contact_link);
+ }
+ } else {
+ $_SESSION['in_page_message'] .= _("<br>".$contact_link." doesn't have a valid email address, facebook account, or twitter id.");
+ }
+
+ if ($this->last_message_sent) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+
+}
View
0 plugin/Marketing/WebFormField.class.php → ...in/Marketing/class/WebFormField.class.php
File renamed without changes.
View
0 plugin/Marketing/WebFormUser.class.php → plugin/Marketing/class/WebFormUser.class.php
File renamed without changes.
View
0 plugin/Marketing/WebFormUserField.class.php → ...arketing/class/WebFormUserField.class.php
File renamed without changes.

0 comments on commit 8d0aeb9

Please sign in to comment.
Something went wrong with that request. Please try again.