public function testget_all_prospect_lists()
 {
     $emailMarketing = new EmailMarketing();
     //execute the method and verify that it retunrs expected results
     $expected = "select prospect_lists.* from prospect_lists  left join prospect_list_campaigns on prospect_list_campaigns.prospect_list_id=prospect_lists.id where prospect_list_campaigns.deleted=0 and prospect_list_campaigns.campaign_id='' and prospect_lists.deleted=0 and prospect_lists.list_type not like 'exempt%'";
     $actual = $emailMarketing->get_all_prospect_lists();
     $this->assertSame($expected, $actual);
 }
function create_marketing_summary($focus)
{
    global $mod_strings, $app_strings;
    $colorclass = '';
    //create new marketing button input
    $new_mrkt_input = "<input id='wiz_new_mrkt_button' name='SUBMIT' ";
    $new_mrkt_input .= "onclick=\"this.form.return_module.value='Campaigns';";
    $new_mrkt_input .= "this.form.module.value='Campaigns';";
    $new_mrkt_input .= "this.form.record.value='';";
    $new_mrkt_input .= "this.form.return_module.value='Campaigns';";
    $new_mrkt_input .= "this.form.action.value='WizardMarketing';";
    $new_mrkt_input .= "this.form.return_action.value='WizardHome';";
    $new_mrkt_input .= "this.form.direct_step.value='1';";
    $new_mrkt_input .= "this.form.campaign_id.value='" . $focus->id . "';";
    $new_mrkt_input .= "this.form.return_id.value='" . $focus->id . "';\" ";
    $new_mrkt_input .= "class='button' value='" . $mod_strings['LBL_CREATE_NEW_MARKETING_EMAIL'] . "' type='submit'>";
    //create marketing email table
    $mrkt_tbl = '';
    $focus->load_relationship('emailmarketing');
    $mrkt_lists = $focus->emailmarketing->get();
    $mrkt_tbl = "<p><table  class='list view' width='100%' border='0' cellspacing='1' cellpadding='1'>";
    $mrkt_tbl .= "<tr class='detail view'><td colspan='3'><h4> " . $mod_strings['LBL_WIZ_MARKETING_TITLE'] . " </h4></td>" . "<td colspan=2 align='right'>{$new_mrkt_input}</td></tr>";
    $mrkt_tbl .= "<tr  class='listViewHRS1'><td scope='col' width='15%'><b>" . $mod_strings['LBL_MRKT_NAME'] . "</b></td><td width='15%' scope='col'><b>" . $mod_strings['LBL_FROM_MAILBOX_NAME'] . "</b></td><td width='15%' scope='col'><b>" . $mod_strings['LBL_STATUS_TEXT'] . "</b></td><td scope='col' colspan=2>&nbsp;</td></tr>";
    if (count($mrkt_lists) > 0) {
        $mrkt_focus = new EmailMarketing();
        foreach ($mrkt_lists as $mrkt_id) {
            $mrkt_focus->retrieve($mrkt_id);
            //create send test marketing button input
            $test_mrkt_input = "<input id='wiz_new_mrkt_button' name='SUBMIT'  ";
            $test_mrkt_input .= "onclick=\"this.form.return_module.value='Campaigns'; ";
            $test_mrkt_input .= "this.form.module.value='Campaigns'; ";
            $test_mrkt_input .= "this.form.record.value='';";
            $test_mrkt_input .= "this.form.return_module.value='Campaigns'; ";
            $test_mrkt_input .= "this.form.action.value='QueueCampaign'; ";
            $test_mrkt_input .= "this.form.return_action.value='WizardHome'; ";
            $test_mrkt_input .= "this.form.wiz_mass.value='" . $mrkt_focus->id . "'; ";
            $test_mrkt_input .= "this.form.mode.value='test'; ";
            $test_mrkt_input .= "this.form.direct_step.value='1'; ";
            $test_mrkt_input .= "this.form.record.value='" . $focus->id . "'; ";
            $test_mrkt_input .= "this.form.return_id.value='" . $focus->id . "';\" ";
            $test_mrkt_input .= "class='button' value='" . $mod_strings['LBL_TEST_BUTTON_LABEL'] . "' type='submit'>";
            //create send marketing button input
            $send_mrkt_input = "<input id='wiz_new_mrkt_button' name='SUBMIT'  ";
            $send_mrkt_input .= "onclick=\"this.form.return_module.value='Campaigns'; ";
            $send_mrkt_input .= "this.form.module.value='Campaigns'; ";
            $send_mrkt_input .= "this.form.record.value='';";
            $send_mrkt_input .= "this.form.return_module.value='Campaigns'; ";
            $send_mrkt_input .= "this.form.action.value='QueueCampaign'; ";
            $send_mrkt_input .= "this.form.return_action.value='WizardHome'; ";
            $send_mrkt_input .= "this.form.wiz_mass.value='" . $mrkt_focus->id . "'; ";
            $send_mrkt_input .= "this.form.mode.value='send'; ";
            $send_mrkt_input .= "this.form.direct_step.value='1'; ";
            $send_mrkt_input .= "this.form.record.value='" . $focus->id . "'; ";
            $send_mrkt_input .= "this.form.return_id.value='" . $focus->id . "';\" ";
            $send_mrkt_input .= "class='button' value='" . $mod_strings['LBL_SEND_EMAIL'] . "' type='submit'>";
            if ($colorclass == "class='evenListRowS1'") {
                $colorclass = "class='oddListRowS1'";
            } else {
                $colorclass = "class='evenListRowS1'";
            }
            if (isset($mrkt_focus->name) && !empty($mrkt_focus->name)) {
                $mrkt_tbl .= "<tr {$colorclass}>";
                $mrkt_tbl .= "<td scope='row' width='40%'><a href='index.php?action=WizardMarketing&module=Campaigns&return_module=Campaigns&return_action=WizardHome";
                $mrkt_tbl .= "&return_id=" . $focus->id . "&campaign_id=" . $focus->id . "&record=" . $mrkt_focus->id . "'>" . $mrkt_focus->name . "</a></td>";
                $mrkt_tbl .= "<td scope='row' width='25%'>" . $mrkt_focus->from_name . "</td>";
                $mrkt_tbl .= "<td scope='row' width='15%'>" . $mrkt_focus->status . "</td>";
                $mrkt_tbl .= "<td scope='row' width='10%'>{$test_mrkt_input}</td>";
                $mrkt_tbl .= "<td scope='row' width='10%'>{$send_mrkt_input}</td>";
                $mrkt_tbl .= "</tr>";
            }
        }
    } else {
        $mrkt_tbl .= "<tr><td colspan='3'>" . $mod_strings['LBL_NONE'] . "</td></tr>";
    }
    $mrkt_tbl .= "</table></p>";
    return $mrkt_tbl;
}
Example #3
0
}
if (isset($_REQUEST['return_action'])) {
    $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
}
if (isset($_REQUEST['return_id'])) {
    $ss->assign("RETURN_ID", $_REQUEST['return_id']);
}
// handle Create $module then Cancel
$ss->assign('CAMPAIGN_ID', $campaign_focus->id);
$seps = get_number_seperators();
$ss->assign("NUM_GRP_SEP", $seps[0]);
$ss->assign("DEC_SEP", $seps[1]);
/**************************** MARKETING UI DIV Stuff *******************/
//$campaign_focus->load_relationship('emailmarketing');
//$mrkt_ids = $campaign_focus->emailmarketing->get();
$mrkt_focus = new EmailMarketing();
//if record param exists and it is not empty, then retrieve this bean
if (isset($_REQUEST['record']) and !empty($_REQUEST['record'])) {
    $mrkt_focus->retrieve($_REQUEST['record']);
} else {
    //check to see if this campaign has an email marketing already attached, and if so, create duplicate
    $campaign_focus->load_relationship('emailmarketing');
    $mrkt_lists = $campaign_focus->emailmarketing->get();
    if (!empty($mrkt_lists)) {
        //reverse array so we always use the most recent one:
        $mrkt_lists = array_reverse($mrkt_lists);
        $mrkt_focus->retrieve($mrkt_lists[0]);
        $mrkt_focus->id = '';
        $mrkt_focus->name = $mod_strings['LBL_COPY_OF'] . ' ' . $mrkt_focus->name;
    }
}
Example #4
0
 function verify_campaign($marketing_id)
 {
     if (!isset($this->verified_email_marketing_ids[$marketing_id])) {
         if (!class_exists('EmailMarketing')) {
         }
         $email_marketing = new EmailMarketing();
         $ret = $email_marketing->retrieve($marketing_id);
         if (empty($ret)) {
             $GLOBALS['log']->fatal('Error retrieving marketing message for the email campaign. marketing_id = ' . $marketing_id);
             return false;
         }
         //verify the email template.
         if (empty($email_marketing->template_id)) {
             $GLOBALS['log']->fatal('Error retrieving template for the email campaign. marketing_id = ' . $marketing_id);
             return false;
         }
         if (!class_exists('EmailTemplate')) {
         }
         $emailtemplate = new EmailTemplate();
         $ret = $emailtemplate->retrieve($email_marketing->template_id);
         if (empty($ret)) {
             $GLOBALS['log']->fatal('Error retrieving template for the email campaign. template_id = ' . $email_marketing->template_id);
             return false;
         }
         if (empty($emailtemplate->subject) and empty($emailtemplate->body) and empty($emailtemplate->body_html)) {
             $GLOBALS['log']->fatal('Email template is empty. email_template_id=' . $email_marketing->template_id);
             return false;
         }
     }
     $this->verified_email_marketing_ids[$marketing_id] = 1;
     return true;
 }
Example #5
0
    if ($_REQUEST['wiz_home_next_step'] == 3) {
        //user has chosen to save and schedule this campaign for email
        $master = 'send';
    } elseif ($_REQUEST['wiz_home_next_step'] == 2) {
        //user has chosen to save and send this campaign in test mode
        $master = 'test';
    } else {
        //user has chosen to simply save
        $master = 'save';
    }
} else {
    //default to just saving and exiting wizard
    $master = 'save';
}
$prefix = 'wiz_step3_';
$marketing = new EmailMarketing();
if (isset($_REQUEST['record']) && !empty($_REQUEST['record'])) {
    $marketing->retrieve($_REQUEST['record']);
}
if (!$marketing->ACLAccess('Save')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
if (!empty($_REQUEST['assigned_user_id']) && $marketing->assigned_user_id != $_REQUEST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) {
    $check_notify = TRUE;
} else {
    $check_notify = FALSE;
}
foreach ($_REQUEST as $key => $val) {
    if (strstr($key, $prefix) && strpos($key, $prefix) == 0) {
        $newkey = substr($key, strlen($prefix));
Example #6
0
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/
/*********************************************************************************
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
$focus = new EmailMarketing();
if (!isset($_REQUEST['record'])) {
    sugar_die("A record number must be specified to delete the marketing campaign.");
}
$focus->retrieve($_REQUEST['record']);
if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
$focus->mark_deleted($_REQUEST['record']);
if (isset($_REQUEST['record'])) {
    $query = "DELETE FROM emailman WHERE marketing_id ='" . $_REQUEST['record'] . "'";
    $focus->db->query($query);
}
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
Example #7
0
        $query .= " and prospect_lists.deleted=0 ";
        $query .= " and prospect_lists.list_type='test' ";
        $query .= " and plc.deleted=0 ";
        $query .= " and plc.campaign_id='{$campaign_id}'";
        $query .= " and email_marketing.campaign_id='{$campaign_id}'";
        $query .= " and email_marketing.deleted=0 ";
        $query .= " and email_marketing.all_prospect_lists=0 ";
        $seed = array();
        $result = $focus->db->query($query);
        while (($row = $focus->db->fetchByAssoc($result)) != null) {
            $bean = new EmailMarketing();
            $bean->retrieve($row['email_marketing_id']);
            $bean->mode = 'test';
            $seed[] = $bean;
        }
        $query = " select email_marketing.id email_marketing_id from email_marketing ";
        $query .= " WHERE email_marketing.campaign_id='{$campaign_id}'";
        $query .= " and email_marketing.deleted=0 ";
        $query .= " and email_marketing.all_prospect_lists=1 ";
        $result = $focus->db->query($query);
        while (($row = $focus->db->fetchByAssoc($result)) != null) {
            $bean = new EmailMarketing();
            $bean->retrieve($row['email_marketing_id']);
            $bean->mode = 'test';
            $seed[] = $bean;
        }
        $ListView->processListView($seed, "main", "EMAILMARKETING");
    } else {
        $ListView->processListView($focus, "main", "EMAILMARKETING");
    }
}
Example #8
0
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 ********************************************************************************/

global $db;

$campaignId = $db->quote($_POST['campaignId']);
$marketingId = $db->quote($_POST['marketingId']);
if(!empty($_POST['templateId'])) {
    $templateId = $db->quote($_POST['templateId']);
}

//$campaign = new Campaign();
//$campaign->retrieve($campaignId);

$marketing = new EmailMarketing();
$marketing->retrieve($marketingId);
$marketing->campaign_id = $campaignId;
if(!empty($_POST['templateId'])) {
    $marketing->template_id = $templateId;
}
$marketing->save();

$_SESSION['campaignWizardSelectedMarketingId'] = $marketing->id;

echo json_encode($_POST);
Example #9
0
/*********************************************************************************
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/EmailMarketing/Forms.php';
global $app_strings;
global $app_list_strings;
global $mod_strings;
global $current_user;
// Unimplemented until jscalendar language files are fixed
// global $current_language;
// global $default_language;
// global $cal_codes;
$focus = new EmailMarketing();
if (isset($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
}
global $theme;
$GLOBALS['log']->info("EmailMarketing Edit View");
$xtpl = new XTemplate('modules/EmailMarketing/DetailView.html');
$xtpl->assign("MOD", $mod_strings);
$xtpl->assign("APP", $app_strings);
if (isset($_REQUEST['return_module'])) {
    $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
} else {
    $xtpl->assign("RETURN_MODULE", 'Campaigns');
}
if (isset($_REQUEST['return_action'])) {
    $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
    if ($_REQUEST['wiz_home_next_step'] == 3) {
        //user has chosen to save and schedule this campaign for email
        $master = 'send';
    } elseif ($_REQUEST['wiz_home_next_step'] == 2) {
        //user has chosen to save and send this campaign in test mode
        $master = 'test';
    } else {
        //user has chosen to simply save
        $master = 'save';
    }
} else {
    //default to just saving and exiting wizard
    $master = 'save';
}
$prefix = 'wiz_step3_';
$marketing = new EmailMarketing();
if (isset($_REQUEST['record']) && !empty($_REQUEST['record'])) {
    $marketing->retrieve($_REQUEST['record']);
} else {
    if (!empty($_SESSION['campaignWizard'][$_REQUEST['campaign_id']]['defaultSelectedMarketingId'])) {
        $marketing->retrieve($_SESSION['campaignWizard'][$_REQUEST['campaign_id']]['defaultSelectedMarketingId']);
    }
}
if (!$marketing->ACLAccess('Save')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
if (!empty($_REQUEST['assigned_user_id']) && $marketing->assigned_user_id != $_REQUEST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) {
    $check_notify = TRUE;
} else {
    $check_notify = FALSE;
Example #11
0
if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
// handle Create $module then Cancel
$ss->assign('CAMPAIGN_ID', $campaign_focus->id);

$seps = get_number_seperators();
$ss->assign("NUM_GRP_SEP", $seps[0]);
$ss->assign("DEC_SEP", $seps[1]);


/**************************** MARKETING UI DIV Stuff *******************/
//$campaign_focus->load_relationship('emailmarketing');
//$mrkt_ids = $campaign_focus->emailmarketing->get();

$mrkt_focus = new EmailMarketing();

//override marketing by session stored selection earlier..

if(isset($_REQUEST['func']) && $_REQUEST['func'] == 'createEmailMarketing') {
    unset($_SESSION['campaignWizardSelectedMarketingId']);
}
else {
    //check to see if this campaign has an email marketing already attached, and if so, create duplicate
    $campaign_focus->load_relationship('emailmarketing');
    $mrkt_lists = $campaign_focus->emailmarketing->get();
}

if(!empty($_SESSION['campaignWizardSelectedMarketingId']) && !in_array($_SESSION['campaignWizardSelectedMarketingId'], $mrkt_lists)) {
    unset($_SESSION['campaignWizardSelectedMarketingId']);
}
Example #12
0
/**
 * To make your changes upgrade safe create a file called leadCapture_override.php and place the changes there
 */
$users = array('PUT A RANDOM KEY FROM THE WEBSITE HERE' => array('name' => 'PUT THE USER_NAME HERE', 'pass' => 'PUT THE USER_HASH FOR THE RESPECTIVE USER HERE'));
if (isset($_POST['campaign_id']) && !empty($_POST['campaign_id'])) {
    //adding the client ip address
    $_POST['client_id_address'] = query_client_ip();
    $campaign_id = $_POST['campaign_id'];
    $campaign = new Campaign();
    $camp_query = "select name,id from campaigns where id='{$campaign_id}'";
    $camp_query .= " and deleted=0";
    $camp_result = $campaign->db->query($camp_query);
    $camp_data = $campaign->db->fetchByAssoc($camp_result);
    // Bug 41292 - have to select marketing_id for new lead
    $db = DBManagerFactory::getInstance();
    $marketing = new EmailMarketing();
    $marketing_query = $marketing->create_new_list_query('date_start desc, date_modified desc', "campaign_id = '{$campaign_id}' and status = 'active' and date_start < " . $db->convert('', 'today'), array('id'));
    $marketing_result = $db->limitQuery($marketing_query, 0, 1, true);
    $marketing_data = $db->fetchByAssoc($marketing_result);
    // .Bug 41292
    if (isset($_REQUEST['assigned_user_id']) && !empty($_REQUEST['assigned_user_id'])) {
        $current_user = new User();
        $current_user->retrieve($_REQUEST['assigned_user_id']);
    }
    if (isset($camp_data) && $camp_data != null) {
        $leadForm = new LeadFormBase();
        $lead = new Lead();
        $prefix = '';
        if (!empty($_POST['prefix'])) {
            $prefix = $_POST['prefix'];
        }
Example #13
0
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 ********************************************************************************/
require_once 'modules/EmailMarketing/Forms.php';
global $timedate;
global $app_strings;
global $app_list_strings;
global $mod_strings;
global $current_user;
// Unimplemented until jscalendar language files are fixed
// global $current_language;
// global $default_language;
// global $cal_codes;
$focus = new EmailMarketing();
if (isset($_REQUEST['record'])) {
    SugarApplication::redirect('index.php?action=WizardMarketing&module=Campaigns&return_module=Campaigns&return_action=WizardHome&return_id=' . $_REQUEST['parent_id'] . '&campaign_id=' . $_REQUEST['parent_id'] . '&marketing_id=' . $_REQUEST['record'] . '&func=editEmailMarketing');
    return;
    $focus->retrieve($_REQUEST['record']);
}
if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $focus->id = "";
}
global $theme;
$GLOBALS['log']->info("EmailMarketing Edit View");
$xtpl = new XTemplate('modules/EmailMarketing/EditView.html');
if (!ACLController::checkAccess('EmailTemplates', 'edit', true)) {
    unset($mod_strings['LBL_CREATE_EMAIL_TEMPLATE']);
    unset($mod_strings['LBL_EDIT_EMAIL_TEMPLATE']);
}
Example #14
0
}
if (isset($_REQUEST['from_wiz'])) {
    $from_wiz = true;
}
//if campaign status is 'sending' disallow this step.
if (!empty($campaign->status) && $campaign->status == 'sending') {
    $err_messages[] = $mod_strings['ERR_SENDING_NOW'];
}
$current_date = $campaign->db->now();
//start scheduling now.....
foreach ($_POST['mass'] as $message_id) {
    //fetch email marketing definition.
    if (!class_exists('EmailMarketing')) {
        require_once 'modules/EmailMarketing/EmailMarketing.php';
    }
    $marketing = new EmailMarketing();
    $marketing->retrieve($message_id);
    //make sure that the marketing message has a mailbox.
    //
    if (empty($marketing->inbound_email_id)) {
        echo "<p>";
        echo "<h4>{$mod_strings['ERR_NO_MAILBOX']}</h4>";
        echo "<BR><a href='index.php?module=EmailMarketing&action=EditView&record={$marketing->id}'>{$marketing->name}</a>";
        echo "</p>";
        sugar_die('');
    }
    global $timedate;
    $mergedvalue = $timedate->merge_date_time($marketing->date_start, $marketing->time_start);
    if ($test) {
        $send_date_time = $timedate->getNow()->get("-60 seconds")->asDb();
    } else {
Example #15
0
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/EmailMarketing/Forms.php';
global $timedate;
global $app_strings;
global $app_list_strings;
global $mod_strings;
global $current_user;
// Unimplemented until jscalendar language files are fixed
// global $current_language;
// global $default_language;
// global $cal_codes;
$focus = new EmailMarketing();
if (isset($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
}
if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $focus->id = "";
}
global $theme;
$GLOBALS['log']->info("EmailMarketing Edit View");
//echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME'].": ".$focus->name, true);
$xtpl = new XTemplate('modules/EmailMarketing/EditView.html');
if (!ACLController::checkAccess('EmailTemplates', 'edit', true)) {
    unset($mod_strings['LBL_CREATE_EMAIL_TEMPLATE']);
    unset($mod_strings['LBL_EDIT_EMAIL_TEMPLATE']);
}
$xtpl->assign("MOD", $mod_strings);
Example #16
0
 }
 //fetch user that scheduled the campaign.
 if (empty($current_user) or $row['user_id'] != $current_user->id) {
     $current_user->retrieve($row['user_id']);
 }
 if (!$emailman->verify_campaign($row['marketing_id'])) {
     $GLOBALS['log']->fatal('Error verifying templates for the campaign, exiting');
     continue;
 }
 //verify the email template too..
 //find the template associated with marketing message. make sure that template has a subject and
 //a non-empty body
 if (!isset($template_status[$row['marketing_id']])) {
     if (!class_exists('EmailMarketing')) {
     }
     $current_emailmarketing = new EmailMarketing();
     $current_emailmarketing->retrieve($row['marketing_id']);
     if (!class_exists('EmailTemplate')) {
     }
     $current_emailtemplate = new EmailTemplate();
     $current_emailtemplate->retrieve($current_emailmarketing->template_id);
 }
 //acquire a lock.
 //if the database does not support repeatable read isolation by default, we might get data that does not meet
 //the criteria in the original query, and we care most about the in_queue_date and process_date_time,
 //if they are null or in past(older than 24 horus) then we are okay.
 $lock_query = "UPDATE emailman SET in_queue=1, in_queue_date=" . $db->now() . " WHERE id = " . intval($row['id']);
 $lock_query .= " AND (in_queue ='0' OR in_queue IS NULL OR ( in_queue ='1' AND in_queue_date <= " . $db->convert($db->quoted($timedate->fromString("-1 day")->asDb()), "datetime") . "))";
 //if the query fails to execute.. terminate campaign email process.
 $lock_result = $db->query($lock_query, true, 'Error acquiring a lock for emailman entry.');
 $lock_count = $db->getAffectedRowCount($lock_result);
    if (!$marketingId) {
        if (!empty($_SESSION['campaignWizard'][$campaignId]['defaultSelectedMarketingId']) && $func != 'createEmailMarketing') {
            $marketingId = $_SESSION['campaignWizard'][$campaignId]['defaultSelectedMarketingId'];
        } else {
            if ($func != 'createEmailMarketing') {
                $marketing = new EmailMarketing();
                $marketing->save();
                $marketingId = $marketing->id;
            }
        }
    }
    if (!empty($_POST['templateId'])) {
        $templateId = $db->quote($_POST['templateId']);
    }
    //$campaign = new Campaign();
    //$campaign->retrieve($campaignId);
    $marketing = new EmailMarketing();
    $marketing->retrieve($marketingId);
    $marketing->campaign_id = $campaignId;
    if (!empty($_POST['templateId'])) {
        $marketing->template_id = $templateId;
    }
    if ($func != 'createEmailMarketing') {
        $marketing->save();
    }
    $_SESSION['campaignWizard'][$campaignId]['defaultSelectedMarketingId'] = $marketing->id;
    $return = $_POST;
    $return['templateValidationMessages'] = getTemplateValidationMessages($marketing->template_id);
    $return['marketingValidationMessages'] = $marketing->validate();
    echo json_encode($return);
}