Beispiel #1
0
 * 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".
 ********************************************************************************/
/*********************************************************************************
 * Description: Schedules email for delivery. emailman table holds emails for delivery.
 * A cron job polls the emailman table and delivers emails when intended send date time is reached.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
global $timedate;
global $current_user;
global $mod_strings;
$campaign = new Campaign();
$campaign->retrieve($_REQUEST['record']);
$err_messages = array();
$test = false;
if (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'test') {
    $test = true;
}
//this is to account for the case of sending directly from summary page in wizards
$from_wiz = false;
if (isset($_REQUEST['wiz_mass'])) {
    $mass[] = $_REQUEST['wiz_mass'];
    $_POST['mass'] = $mass;
    $from_wiz = true;
}
if (isset($_REQUEST['from_wiz'])) {
    $from_wiz = true;
}
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
/**************************** general UI Stuff *******************/
require_once 'modules/Campaigns/utils.php';
global $app_strings;
global $timedate;
global $app_list_strings;
global $mod_strings;
global $current_user;
global $sugar_version, $sugar_config;
/**************************** GENERAL SETUP WORK*******************/
$campaign_focus = new Campaign();
if (isset($_REQUEST['campaign_id']) && !empty($_REQUEST['campaign_id'])) {
    $campaign_focus->retrieve($_REQUEST['campaign_id']);
} else {
    sugar_die($app_strings['ERROR_NO_RECORD']);
}
global $theme;
$json = getJSONobj();
$GLOBALS['log']->info("Wizard Continue Create Wizard");
if ($campaign_focus->campaign_type == 'NewsLetter') {
    echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_NEWSLETTER WIZARD_TITLE'] . ' ' . $campaign_focus->name, true);
} else {
    echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_CAMPAIGN'] . ' ' . $campaign_focus->name, true);
}
$ss = new Sugar_Smarty();
$ss->assign("MOD", $mod_strings);
$ss->assign("APP", $app_strings);
if (isset($_REQUEST['return_module'])) {
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
/******** general UI Stuff ***********/
require_once 'modules/Campaigns/utils.php';
require_once 'modules/Campaigns/Forms.php';
global $app_strings;
global $timedate;
global $app_list_strings;
global $mod_strings;
global $current_user;
global $sugar_version, $sugar_config;
/*************** GENERAL SETUP WORK **********/
$focus = new Campaign();
if (isset($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
}
if (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $focus->id = "";
}
global $theme;
$json = getJSONobj();
$GLOBALS['log']->info("Campaign NewsLetter Wizard");
if (isset($_REQUEST['wizardtype']) && $_REQUEST['wizardtype'] == 1 || $focus->campaign_type == 'NewsLetter') {
    echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_NEWSLETTER WIZARD_TITLE'] . $focus->name, true);
} else {
    echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_CAMPAIGN'] . $focus->name, true);
}
$ss = new Sugar_Smarty();
$ss->assign("MOD", $mod_strings);
$ss->assign("APP", $app_strings);
Beispiel #4
0
 public function testSaveAndMarkDeleted()
 {
     $campaign = new Campaign();
     $campaign->name = 'test';
     $campaign->amount = 100;
     $campaign->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($campaign->id));
     $this->assertEquals(36, strlen($campaign->id));
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $campaign->mark_deleted($campaign->id);
     $result = $campaign->retrieve($campaign->id);
     $this->assertEquals(null, $result);
 }
 * 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): ______________________________________..
 ********************************************************************************/
require_once 'include/formbase.php';
global $mod_strings;
//create new campaign bean and populate
$campaign_focus = new Campaign();
if (isset($_REQUEST['record'])) {
    $campaign_focus->retrieve($_REQUEST['record']);
}
$camp_steps[] = 'wiz_step1_';
$camp_steps[] = 'wiz_step2_';
$campaign_focus = populateFromPost('', $campaign_focus);
foreach ($camp_steps as $step) {
    $campaign_focus = populate_wizard_bean_from_request($campaign_focus, $step);
}
//save here so we can link relationships
$campaign_focus->save();
$GLOBALS['log']->debug("Saved record with id of " . $campaign_focus->id);
//process prospect lists
//process subscription lists if this is a newsletter
if ($campaign_focus->campaign_type == 'NewsLetter') {
    $pl_list = process_subscriptions_from_request($campaign_focus->name);
    $campaign_focus->load_relationship('prospectlists');
Beispiel #6
0
global $app_strings;
global $app_list_strings;
global $current_language;
global $current_user;
global $urlPrefix;
global $currentModule;
$current_module_strings = return_module_language($current_language, 'EmailMarketing');
if ($test) {
    echo getClassicModuleTitle('Campaigns', array($current_module_strings['LBL_MODULE_SEND_TEST']), false);
} else {
    echo getClassicModuleTitle('Campaigns', array($current_module_strings['LBL_MODULE_SEND_EMAILS']), false);
}
$campaign_id = isset($_REQUEST['record']) ? $_REQUEST['record'] : false;
if (!empty($campaign_id)) {
    $campaign = new Campaign();
    $campaign->retrieve($campaign_id);
}
if ($campaign_id && isset($campaign) && $campaign->status == 'Inactive') {
    $ss = new Sugar_Smarty();
    $data = array($campaign->name);
    $ss->assign('campaignInactive', string_format(translate('LBL_CAMPAIGN_INACTIVE_SCHEDULE', 'Campaigns'), $data));
    $ss->display('modules/Campaigns/tpls/campaign-inactive.tpl');
} else {
    $focus = new EmailMarketing();
    if ($campaign_id) {
        $where_clauses = array();
        if (!empty($campaign_id)) {
            array_push($where_clauses, "campaign_id = '" . $GLOBALS['db']->quote($campaign_id) . "'");
        }
        $where = "";
        foreach ($where_clauses as $clause) {
 function fill_in_additional_detail_fields()
 {
     parent::fill_in_additional_detail_fields();
     if (!empty($this->currency_id)) {
         $currency = new Currency();
         $currency->retrieve($this->currency_id);
         if ($currency->id != $this->currency_id || $currency->deleted == 1) {
             $this->amount = $this->amount_usdollar;
             $this->currency_id = $currency->id;
         }
     }
     //get campaign name
     if (!empty($this->campaign_id)) {
         $camp = new Campaign();
         $camp->retrieve($this->campaign_id);
         $this->campaign_name = $camp->name;
     }
     $this->account_name = '';
     $this->account_id = '';
     if (!empty($this->id)) {
         $ret_values = Opportunity::get_account_detail($this->id);
         if (!empty($ret_values)) {
             $this->account_name = $ret_values['name'];
             $this->account_id = $ret_values['id'];
             $this->account_id_owner = $ret_values['assigned_user_id'];
         }
     }
 }
Beispiel #8
0
/**
 * Handle campaign log entry creation for mail-merge activity. The function will be called by the soap component.
 *
 * @param String campaign_id Primary key of the campaign
 * @param array targets List of keys for entries from prospect_lists_prosects table
 */
 function campaign_log_mail_merge($campaign_id, $targets) {

    $campaign= new Campaign();
    $campaign->retrieve($campaign_id);

    if (empty($campaign->id)) {
        $GLOBALS['log']->debug('set_campaign_merge: Invalid campaign id'. $campaign_id);
    } else {
        foreach ($targets as $target_list_id) {
            $pl_query = "select * from prospect_lists_prospects where id='".$GLOBALS['db']->quote($target_list_id)."'";
            $result=$GLOBALS['db']->query($pl_query);
            $row=$GLOBALS['db']->fetchByAssoc($result);
            if (!empty($row)) {
                write_mail_merge_log_entry($campaign_id,$row);
            }
        }
    }

 }
Beispiel #9
0
} else {
    $check_notify = FALSE;
}
require_once 'include/formbase.php';
$focus = populateFromPost('', $focus);
//store preformatted dates for 2nd save
$preformat_start_date = $focus->start_date;
$preformat_end_date = $focus->end_date;
//_ppd($preformat_end_date);
$focus->save($check_notify);
$return_id = $focus->id;
$GLOBALS['log']->debug("Saved record with id of " . $return_id);
//copy compaign targets on duplicate
if (!empty($_REQUEST['duplicateSave']) && !empty($_REQUEST['duplicateId'])) {
    $copyFromCompaign = new Campaign();
    $copyFromCompaign->retrieve($_REQUEST['duplicateId']);
    $copyFromCompaign->load_relationship('prospectlists');
    $focus->load_relationship('prospectlists');
    $target_lists = $copyFromCompaign->prospectlists->get();
    if (count($target_lists) > 0) {
        foreach ($target_lists as $prospect_list_id) {
            $focus->prospectlists->add($prospect_list_id);
        }
    }
    $focus->save();
}
//if type is set to newsletter then make sure there are propsect lists attached
if ($focus->campaign_type == 'NewsLetter') {
    //if this is a duplicate, and the "relate_to" and "relate_id" elements are not cleared out,
    //then prospect lists will get related to the original campaign on save of the prospect list, and then
    //will get related to the new newsletter campaign, meaning the same (un)subscription list will belong to
 protected function constructQuery($datay = array(), $targets = array(), $campaign_id, $cache_file_name = 'a_file', $refresh = false, $marketing_id = '', $is_dashlet = false, $dashlet_id = '')
 {
     //global $app_strings,$mod_strings, $current_module_strings, $charset, $lang, $app_list_strings, $current_language,$sugar_config;
     global $mod_strings;
     $not_empty = false;
     $chartData = array();
     $focus = new Campaign();
     $focus->retrieve($campaign_id);
     $opp_count = 0;
     $opp_query = "select count(*) opp_count,sum(" . db_convert("amount_usdollar", "IFNULL", array(0)) . ")  total_value";
     $opp_query .= " from opportunities";
     $opp_query .= " where campaign_id='{$campaign_id}'";
     $opp_query .= " and sales_stage='Prospecting'";
     $opp_query .= " and deleted=0";
     $opp_result = $focus->db->query($opp_query);
     $opp_data = $focus->db->fetchByAssoc($opp_result);
     if (empty($opp_data['total_value'])) {
         $opp_data['total_value'] = 0;
     }
     $chartData['Total Value'] = $opp_data['total_value'];
     //report query
     $opp_query1 = "select SUM(opp.amount) as revenue";
     $opp_query1 .= " from opportunities opp";
     $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id";
     $opp_query1 .= " where opp.sales_stage = 'Closed Won'and camp.id='{$campaign_id}' and opp.deleted=0";
     $opp_query1 .= " group by camp.name";
     $opp_result1 = $focus->db->query($opp_query1);
     $opp_data1 = $focus->db->fetchByAssoc($opp_result1);
     //if (empty($opp_data1[]))
     if (empty($opp_data1['revenue'])) {
         $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']] = 0;
         unset($opp_data1['revenue']);
     } else {
         $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']] = $opp_data1['revenue'];
         unset($opp_data1['revenue']);
         $not_empty = true;
     }
     $chartData['Revenue'] = $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']];
     $camp_query1 = "select camp.name, SUM(camp.actual_cost) as investment,SUM(camp.budget) as budget,SUM(camp.expected_revenue) as expected_revenue";
     $camp_query1 .= " from campaigns camp";
     $camp_query1 .= " where camp.id='{$campaign_id}'";
     $camp_query1 .= " group by camp.name";
     $camp_result1 = $focus->db->query($camp_query1);
     $camp_data1 = $focus->db->fetchByAssoc($camp_result1);
     if (empty($camp_data1['investment'])) {
         $camp_data1['investment'] = 0;
     } else {
         $not_empty = true;
     }
     if (empty($camp_data1['budget'])) {
         $camp_data1['budget'] = 0;
     } else {
         $not_empty = true;
     }
     if (empty($camp_data1['expected_revenue'])) {
         $camp_data1['expected_revenue'] = 0;
     } else {
         $not_empty = true;
     }
     $chartData['Investment'] = $camp_data1['investment'];
     $chartData['Budget'] = $camp_data1['budget'];
     $chartData['Expected Revenue'] = $camp_data1['expected_revenue'];
     /*
                 $opp_data1[$mod_strings['LBL_ROI_CHART_INVESTMENT']]=$camp_data1['investment'];
                 $opp_data1[$mod_strings['LBL_ROI_CHART_BUDGET']]=$camp_data1['budget'];
                 $opp_data1[$mod_strings['LBL_ROI_CHART_EXPECTED_REVENUE']]=$camp_data1['expected_revenue'];
     
     
                 $query = "SELECT activity_type,target_type, count(*) hits ";
                 $query.= " FROM campaign_log ";
                 $query.= " WHERE campaign_id = '$campaign_id' AND archived=0 AND deleted=0";
                 //if $marketing id is specified, then lets filter the chart by the value
                 if (!empty($marketing_id)){
                     $query.= " AND marketing_id ='$marketing_id'";
                 }
                 $query.= " GROUP BY  activity_type, target_type";
                 $query.= " ORDER BY  activity_type, target_type";
                 $result = $focus->db->query($query);
     */
     return $chartData;
 }
 * The Original Code is: SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
/*********************************************************************************
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'include/formbase.php';
require_once 'modules/Campaigns/Campaign.php';
$focus = new Campaign();
$focus->retrieve($_POST['record']);
if (!$focus->ACLAccess('Save')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
if (!empty($_POST['assigned_user_id']) && $focus->assigned_user_id != $_POST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) {
    $check_notify = TRUE;
} else {
    $check_notify = FALSE;
}
foreach ($focus->column_fields as $field) {
    if (isset($_POST[$field])) {
        $value = $_POST[$field];
        $focus->{$field} = $value;
    }
}
Beispiel #12
0
 function campaign_response_roi($datay = array(), $targets = array(), $campaign_id, $cache_file_name = 'a_file', $refresh = false, $marketing_id = '', $is_dashlet = false, $dashlet_id = '')
 {
     global $app_strings, $mod_strings, $current_module_strings, $charset, $lang, $app_list_strings, $current_language, $sugar_config;
     $not_empty = false;
     if ($is_dashlet) {
         $mod_strings = return_module_language($current_language, 'Campaigns');
     }
     if (!file_exists($cache_file_name) || $refresh == true) {
         $GLOBALS['log']->debug("datay is:");
         $GLOBALS['log']->debug($datay);
         $GLOBALS['log']->debug("user_id is: ");
         $GLOBALS['log']->debug("cache_file_name is: {$cache_file_name}");
         $focus = new Campaign();
         $focus->retrieve($campaign_id);
         $opp_count = 0;
         $opp_query = "select count(*) opp_count,sum(" . db_convert("amount_usdollar", "IFNULL", array(0)) . ")  total_value";
         $opp_query .= " from opportunities";
         $opp_query .= " where campaign_id='{$campaign_id}'";
         $opp_query .= " and sales_stage='Prospecting'";
         $opp_query .= " and deleted=0";
         $opp_result = $focus->db->query($opp_query);
         $opp_data = $focus->db->fetchByAssoc($opp_result);
         //            if (empty($opp_data['opp_count'])) $opp_data['opp_count']=0;
         if (empty($opp_data['total_value'])) {
             $opp_data['total_value'] = 0;
         }
         //report query
         $opp_query1 = "select SUM(opp.amount) as revenue";
         $opp_query1 .= " from opportunities opp";
         $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id";
         $opp_query1 .= " where opp.sales_stage = 'Closed Won'and camp.id='{$campaign_id}' and opp.deleted=0";
         $opp_query1 .= " group by camp.name";
         $opp_result1 = $focus->db->query($opp_query1);
         $opp_data1 = $focus->db->fetchByAssoc($opp_result1);
         //if (empty($opp_data1[]))
         if (empty($opp_data1['revenue'])) {
             $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']] = 0;
             unset($opp_data1['revenue']);
         } else {
             $opp_data1[$mod_strings['LBL_ROI_CHART_REVENUE']] = $opp_data1['revenue'];
             unset($opp_data1['revenue']);
             $not_empty = true;
         }
         $camp_query1 = "select camp.name, SUM(camp.actual_cost) as investment,SUM(camp.budget) as budget,SUM(camp.expected_revenue) as expected_revenue";
         $camp_query1 .= " from campaigns camp";
         $camp_query1 .= " where camp.id='{$campaign_id}'";
         $camp_query1 .= " group by camp.name";
         $camp_result1 = $focus->db->query($camp_query1);
         $camp_data1 = $focus->db->fetchByAssoc($camp_result1);
         //query needs to be lowercase, but array keys need to be propercased, as these are used in
         //chart to display legend
         if (empty($camp_data1['investment'])) {
             $camp_data1['investment'] = 0;
         } else {
             $not_empty = true;
         }
         if (empty($camp_data1['budget'])) {
             $camp_data1['budget'] = 0;
         } else {
             $not_empty = true;
         }
         if (empty($camp_data1['expected_revenue'])) {
             $camp_data1['expected_revenue'] = 0;
         } else {
             $not_empty = true;
         }
         $opp_data1[$mod_strings['LBL_ROI_CHART_INVESTMENT']] = $camp_data1['investment'];
         $opp_data1[$mod_strings['LBL_ROI_CHART_BUDGET']] = $camp_data1['budget'];
         $opp_data1[$mod_strings['LBL_ROI_CHART_EXPECTED_REVENUE']] = $camp_data1['expected_revenue'];
         $query = "SELECT activity_type,target_type, count(*) hits ";
         $query .= " FROM campaign_log ";
         $query .= " WHERE campaign_id = '{$campaign_id}' AND archived=0 AND deleted=0";
         //if $marketing id is specified, then lets filter the chart by the value
         if (!empty($marketing_id)) {
             $query .= " AND marketing_id ='{$marketing_id}'";
         }
         $query .= " GROUP BY  activity_type, target_type";
         $query .= " ORDER BY  activity_type, target_type";
         $result = $focus->db->query($query);
         $leadSourceArr = array();
         $total = 0;
         $total_targeted = 0;
     }
     global $current_user;
     $user_id = $current_user->id;
     $width = '100%';
     $return = '';
     if (!$is_dashlet) {
         $return .= '<br />';
     }
     $currency_id = $focus->currency_id;
     $currency_symbol = $sugar_config['default_currency_symbol'];
     if (!empty($currency_id)) {
         $cur = new Currency();
         $cur->retrieve($currency_id);
         $currency_symbol = $cur->symbol;
     }
     $sugarChart = SugarChartFactory::getInstance();
     $sugarChart->is_currency = true;
     $sugarChart->currency_symbol = $currency_symbol;
     if ($not_empty) {
         $sugarChart->setData($opp_data1);
     } else {
         $sugarChart->setData(array());
     }
     $sugarChart->setProperties($mod_strings['LBL_CAMPAIGN_RETURN_ON_INVESTMENT'], $mod_strings['LBL_AMOUNT_IN'] . $currency_symbol, 'bar chart');
     if (!$is_dashlet) {
         $xmlFile = $sugarChart->getXMLFileName('roi_details_chart');
         $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
         $return .= $sugarChart->display('roi_details_chart', $xmlFile, $width, '480');
     } else {
         $xmlFile = $sugarChart->getXMLFileName($dashlet_id);
         $sugarChart->saveXMLFile($xmlFile, $sugarChart->generateXML());
         $return .= $sugarChart->display($dashlet_id, $xmlFile, $width, '480');
     }
     return $return;
 }
Beispiel #13
0
 function createTargeList($listname, $campaign_id = '')
 {
     global $current_user, $db;
     $results = $this->getSelectionResults(array());
     if (count($results > 0)) {
         require_once 'modules/ProspectLists/ProspectList.php';
         $newProspectList = new ProspectList();
         $newProspectList->name = $listname;
         $newProspectList->list_type = 'default';
         $newProspectList->assigned_user_id = $current_user->id;
         $newProspectList->save();
         // add to campaign
         if ($campaign_id != '') {
             require_once 'modules/Campaigns/Campaign.php';
             $thisCampaign = new Campaign();
             $thisCampaign->retrieve($campaign_id);
             $thisCampaign->load_relationships();
             $campaignLinkedFields = $thisCampaign->get_linked_fields();
             foreach ($campaignLinkedFields as $linkedField => $linkedFieldData) {
                 if ($thisCampaign->{$linkedField}->_relationship->rhs_module == 'ProspectList') {
                     $thisCampaign->{$linkedField}->add($newProspectList->id);
                 }
             }
         }
         // fill with results:
         $newProspectList->load_relationships();
         $linkedFields = $newProspectList->get_linked_fields();
         foreach ($linkedFields as $linkedField => $linkedFieldData) {
             if ($newProspectList->{$linkedField}->_relationship->rhs_module == $this->report_module) {
                 foreach ($results as $thisRecord) {
                     $newProspectList->{$linkedField}->add($thisRecord['sugarRecordId']);
                 }
             } elseif ($newProspectList->{$linkedField}->_relationship->rhs_module == 'Campaigns' and $campaign_id != '') {
                 $newProspectList->{$linkedField}->add($campaign_id);
             }
         }
     }
 }
 function createTargeList($listname, $campaign_id = '')
 {
     global $current_user, $db;
     $results = $this->getSelectionResults(array());
     if (count($results > 0)) {
         require_once 'modules/ProspectLists/ProspectList.php';
         $newProspectList = new ProspectList();
         $newProspectList->name = $listname;
         $newProspectList->list_type = 'default';
         $newProspectList->assigned_user_id = $current_user->id;
         $db = DBManagerFactory::getInstance();
         /*
         $sugarQuery = new SugarQuery();
         $sugarQuery->select('id');
         $sugarQuery->from(BeanFactory::getBean('Accounts'));
         $sugarQuery->where()->equals('name',$newProspectList->name);
         $id_prospect = $sugarQuery->execute();
         $id_prospect = $id_prospect[0];         
         */
         $sql = "SELECT id, name from prospect_lists where deleted = '0' and name = '" . $newProspectList->name . "' limit 1";
         $result = $db->query($sql);
         if ($db->getRowCount($result) > 0) {
             if ($row = $db->fetchByAssoc($result)) {
                 $newProspectList->id = $row['id'];
             }
         }
         if ($newProspectList->save()) {
             /* Força update do campo da base de dados com o sql do relatório */
             $sql = 'UPDATE prospect_lists SET sql_query = "' . str_replace('"', "'", $_SESSION['kreport_sql']) . '" where id = "' . $newProspectList->id . '"';
             $result = $db->query($sql);
             if ($result) {
                 $GLOBALS['log']->debug("Atualizou prospect list sql");
             } else {
                 $GLOBALS['log']->debug("Falha ao atualizar prospect list sql");
             }
             /* Fim */
         }
         // add to campaign
         if ($campaign_id != '') {
             require_once 'modules/Campaigns/Campaign.php';
             $thisCampaign = new Campaign();
             $thisCampaign->retrieve($campaign_id);
             $thisCampaign->load_relationships();
             $campaignLinkedFields = $thisCampaign->get_linked_fields();
             foreach ($campaignLinkedFields as $linkedField => $linkedFieldData) {
                 if ($thisCampaign->{$linkedField}->_relationship->rhs_module == 'ProspectList') {
                     $thisCampaign->{$linkedField}->add($newProspectList->id);
                 }
             }
         }
         // fill with results:
         $newProspectList->load_relationships();
         $linkedFields = $newProspectList->get_linked_fields();
         foreach ($linkedFields as $linkedField => $linkedFieldData) {
             if ($newProspectList->{$linkedField}->_relationship->rhs_module == $this->report_module) {
                 foreach ($results as $thisRecord) {
                     $newProspectList->{$linkedField}->add($thisRecord['sugarRecordId']);
                 }
             } elseif ($newProspectList->{$linkedField}->_relationship->rhs_module == 'Campaigns' and $campaign_id != '') {
                 $newProspectList->{$linkedField}->add($campaign_id);
             }
         }
     }
 }