public function testsave() { $prospectList = new ProspectList(); $prospectList->name = "test"; $prospectList->description = "test description"; $result = $prospectList->save(); //test for record ID to verify that record is saved $this->assertTrue(isset($prospectList->id)); $this->assertEquals(36, strlen($prospectList->id)); //test set_prospect_relationship method $this->set_prospect_relationship($prospectList->id); //test set_prospect_relationship_single method $this->set_prospect_relationship_single($prospectList->id); //mark the record as deleted and verify that this record cannot be retrieved anymore. $prospectList->mark_deleted($prospectList->id); $result = $prospectList->retrieve($prospectList->id); $this->assertEquals(null, $result); }
public static function createProspectList($id = '', $aParams = array()) { $time = mt_rand(); $oProspectList = new ProspectList(); $oProspectList->name = 'ProspectList' . $time; if (!empty($id)) { $oProspectList->id = $id; } if (!empty($aParams)) { foreach ($aParams as $key => $val) { $oProspectList->{$key} = $val; } } $oProspectList->save(); self::$_aCreatedProspectLists[] = $oProspectList; self::$_aCreatedProspectListsIds[] = $oProspectList->id; return $oProspectList; }
* 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: TODO: To be written. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ global $mod_strings; $focus = new ProspectList(); $focus->retrieve($_POST['record']); if (isset($_POST['isDuplicate']) && $_POST['isDuplicate'] == true) { $focus->id = ''; $focus->name = $mod_strings['LBL_COPY_PREFIX'] . ' ' . $focus->name; $focus->save(); $return_id = $focus->id; //duplicate the linked items. $query = "select * from prospect_lists_prospects where prospect_list_id = '" . $_POST['record'] . "'"; $result = $focus->db->query($query); if ($result != null) { while (($row = $focus->db->fetchByAssoc($result)) != null) { $iquery = "INSERT INTO prospect_lists_prospects (id,prospect_list_id, related_id, related_type,date_modified) "; $iquery .= "VALUES (" . "'" . create_guid() . "'," . "'" . $focus->id . "'," . "'" . $row['related_id'] . "'," . "'" . $row['related_type'] . "'," . "'" . TimeDate::getInstance()->nowDb() . "')"; $focus->db->query($iquery); //save the record. } } } header("Location: index.php?action=DetailView&module=ProspectLists&record={$return_id}");
function process_subscriptions_from_request($campaign_name) { global $mod_strings; $pl_list = array(); //process default target list $create_new = true; $pl_subs = new ProspectList($campaign_name); if (!empty($_REQUEST['wiz_step3_subscription_list_id'])) { //if subscription list is specified then attach $pl_subs->retrieve($_REQUEST['wiz_step3_subscription_list_id']); //check to see name matches the bean, if not, then the user has chosen to create new bean if ($pl_subs->name == $_REQUEST['wiz_step3_subscription_name']) { $pl_list[] = $pl_subs; $create_new = false; } } //create new bio if one was not retrieved succesfully if ($create_new) { //use default name if one has not been specified $name = $campaign_name . " " . $mod_strings['LBL_SUBSCRIPTION_LIST']; if (isset($_REQUEST['wiz_step3_subscription_name']) && !empty($_REQUEST['wiz_step3_subscription_name'])) { $name = $_REQUEST['wiz_step3_subscription_name']; } //if subscription list is not specified then create and attach default one $pl_subs->name = $name; $pl_subs->list_type = 'default'; $pl_subs->assigned_user_id = $GLOBALS['current_user']->id; $pl_subs->save(); $pl_list[] = $pl_subs; } //process exempt target list $create_new = true; $pl_un_subs = new ProspectList(); if (!empty($_REQUEST['wiz_step3_unsubscription_list_id'])) { //if unsubscription list is specified then attach $pl_un_subs->retrieve($_REQUEST['wiz_step3_unsubscription_list_id']); //check to see name matches the bean, if not, then the user has chosen to create new bean if ($pl_un_subs->name == $_REQUEST['wiz_step3_unsubscription_name']) { $pl_list[] = $pl_un_subs; $create_new = false; } } //create new bean if one was not retrieved succesfully if ($create_new) { //use default name if one has not been specified $name = $campaign_name . " " . $mod_strings['LBL_UNSUBSCRIPTION_LIST']; if (isset($_REQUEST['wiz_step3_unsubscription_name']) && !empty($_REQUEST['wiz_step3_unsubscription_name'])) { $name = $_REQUEST['wiz_step3_unsubscription_name']; } //if unsubscription list is not specified then create and attach default one $pl_un_subs->name = $name; $pl_un_subs->list_type = 'exempt'; $pl_un_subs->assigned_user_id = $GLOBALS['current_user']->id; $pl_un_subs->save(); $pl_list[] = $pl_un_subs; } //process test target list $pl_test = new ProspectList(); $create_new = true; if (!empty($_REQUEST['wiz_step3_test_list_id'])) { //if test list is specified then attach $pl_test->retrieve($_REQUEST['wiz_step3_test_list_id']); //check to see name matches the bean, if not, then the user has chosen to create new bean if ($pl_test->name == $_REQUEST['wiz_step3_test_name']) { $pl_list[] = $pl_test; $create_new = false; } } //create new bio if one was not retrieved succesfully if ($create_new) { //use default name if one has not been specified $name = $campaign_name . " " . $mod_strings['LBL_TEST_LIST']; if (isset($_REQUEST['wiz_step3_test_name']) && !empty($_REQUEST['wiz_step3_test_name'])) { $name = $_REQUEST['wiz_step3_test_name']; } //if test list is not specified then create and attach default one $pl_test->name = $name; $pl_test->list_type = 'test'; $pl_test->assigned_user_id = $GLOBALS['current_user']->id; $pl_test->save(); $pl_list[] = $pl_test; } return $pl_list; }
global $current_user; global $mod_strings; //if no prospect lists are attached, then lets create a subscription and unsubscription //default prospect lists as these are required for newsletters. //create subscription list $subs = new ProspectList(); $subs->name = $focus->name . ' ' . $mod_strings['LBL_SUBSCRIPTION_LIST']; $subs->assigned_user_id = $current_user->id; $subs->list_type = "default"; $subs->save(); $focus->prospectlists->add($subs->id); //create unsubscription list $unsubs = new ProspectList(); $unsubs->name = $focus->name . ' ' . $mod_strings['LBL_UNSUBSCRIPTION_LIST']; $unsubs->assigned_user_id = $current_user->id; $unsubs->list_type = "exempt"; $unsubs->save(); $focus->prospectlists->add($unsubs->id); //create unsubscription list $test_subs = new ProspectList(); $test_subs->name = $focus->name . ' ' . $mod_strings['LBL_TEST_LIST']; $test_subs->assigned_user_id = $current_user->id; $test_subs->list_type = "test"; $test_subs->save(); $focus->prospectlists->add($test_subs->id); } //save new relationships $focus->save(); } //finish newsletter processing handleRedirect($focus->id, 'Campaigns');
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 execute($format = 'TABLE', $parameter_values = array()) { global $sugar_config, $current_user, $current_language; global $beanList, $beanFiles; $beanName = $beanList[$this->mainmodule]; $beanFile = $beanFiles[$beanName]; if (!empty($beanName) && !empty($beanFile)) { require_once $beanFile; $seed = new $beanName(); $filters = $this->get_filters(); $sql_where = array(); foreach ($filters as $filter) { $sql_where[] = $filter->create_where_clause($parameter_values); } $orders = $this->get_orders(); $sql_order = array(); foreach ($orders as $order) { $sql_order[] = $order->create_order_clause($parameter_values); } if ($this->filtertype == "AND") { $sql_join = " and "; } else { if ($this->filtertype == "OR") { $sql_join = " or "; } else { $sql_join = " and "; } } if (!empty($sql_join) && !empty($sql_where)) { $where_clause = "(" . join($sql_join, $sql_where) . ")"; } if (!empty($sql_order)) { $order_clause = join(", ", $sql_order); } if (!empty($this->customwhere1)) { $where_clause = $this->customwhere1 . " " . $where_clause; } if (!empty($this->customwhere2)) { $where_clause = $where_clause . " " . $this->customwhere1; } $rows = $seed->get_full_list($order_clause, $where_clause); if (empty($rows)) { $rows = array(); } $this->report_output .= "Found " . count($rows) . " rows<br/>"; if ($format == "TABLE" || $format == "HTML" || $format == "SIMPLEHTML" || $format == "CSV") { $list_data = array(); $list_fields = array(); foreach ($rows as $row) { $row_data = $row->get_list_view_data(); $row_data_mapped = array(); foreach (array_keys($row_data) as $key) { $row_data_mapped[strtoupper($this->mainmodule) . "_" . $key] = $row_data[$key]; } $list_data[] = new ListingRow($row_data_mapped); if (empty($list_fields)) { foreach (array_keys($row_data) as $key) { $list_fields[] = $key; } } } if ($format == "HTML" || $format == "TABLE") { if ($this->list_template == "default") { require_once 'include/ListView/ListViewSmarty.php'; if (file_exists('custom/modules/' . $this->mainmodule . '/metadata/listviewdefs.php')) { require_once 'custom/modules/' . $this->mainmodule . '/metadata/listviewdefs.php'; } else { require_once 'modules/' . $this->mainmodule . '/metadata/listviewdefs.php'; } $lv = new ListViewSmarty(); $displayColumns = array(); foreach ($listViewDefs[$this->mainmodule] as $col => $params) { if (!empty($params['default']) && $params['default']) { $displayColumns[$col] = $params; } } $lv->displayColumns = $displayColumns; $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where_clause, $params); ob_start(); echo $lv->display(); } else { require_once 'include/ListView/ListView.php'; $lv = new ListView(); if ($_REQUEST["is_scheduler"] = "true") { $lv->setDisplayHeaderAndFooter(false); } $lv->initNewXTemplate('modules/ZuckerListingTemplate/lists/' . $this->list_template, return_module_language($current_language, $this->mainmodule)); $lv->xTemplateAssign("SITE_URL", $sugar_config["site_url"]); ob_start(); $lv->processListViewTwo($list_data, "rows", "ROW"); } if ($format == "HTML") { $date = date("ymd_His"); $this->report_result_type = "FILE"; $this->report_result_name = $date . "_" . $this->name . ".html"; $this->report_result_name = strtolower(join("_", explode(" ", $this->report_result_name))); $this->report_result = $this->archive_dir . "/" . $this->report_result_name; $f = fopen($this->report_result, "w"); $c = file_get_contents("modules/ZuckerListingTemplate/lists/header.html"); $c = str_replace("{SITE_URL}", $sugar_config["site_url"], $c); $c = str_replace("{THEME_URL}", $sugar_config["site_url"] . "/themes/" . $theme, $c); fwrite($f, $c); fwrite($f, ob_get_clean()); fwrite($f, file_get_contents("modules/ZuckerListingTemplate/lists/footer.html")); fclose($f); } else { $this->report_result_type = "INLINE"; $this->report_result = ob_get_clean(); } } else { if ($format == "SIMPLEHTML") { $date = date("ymd_His"); $this->report_result_type = "FILE"; $this->report_result_name = $date . "_" . $this->name . ".html"; $this->report_result_name = strtolower(join("_", explode(" ", $this->report_result_name))); $this->report_result = $this->archive_dir . "/" . $this->report_result_name; $f = fopen($this->report_result, "w"); fwrite($f, "<!DOCTYPE html PUBLIC \"-//W3C//DTD html 4.01 Transitional//EN\">\n"); fwrite($f, "<html><body><table border=\"1\">"); if ($this->include_header && !empty($list_fields)) { fwrite($f, "\n<tr>"); foreach ($list_fields as $col_name) { fwrite($f, "<th>" . $col_name . "</th>"); } fwrite($f, "</tr>"); } foreach ($list_data as $list_row) { fwrite($f, "\n<tr>"); foreach (array_keys($list_row->list_view_data) as $col_name) { $field = $list_row->list_view_data[$col_name]; if (empty($field)) { fwrite($f, "<td> </td>"); } else { fwrite($f, "<td>" . $this->format_value_for_html($field) . "</td>"); } } fwrite($f, "</tr>"); } fwrite($f, "\n</table></body></html>"); fclose($f); } else { if ($format == "CSV") { $date = date("ymd_His"); $this->report_result_type = "FILE"; $this->report_result_name = $date . "_" . $this->name . ".csv"; $this->report_result_name = strtolower(join("_", explode(" ", $this->report_result_name))); $this->report_result = $this->archive_dir . "/" . $this->report_result_name; $f = fopen($this->report_result, "w"); if ($this->include_header && count($list_data) > 0) { $row = $list_data[0]; foreach (array_keys($row->list_view_data) as $col_name) { fwrite($f, $col_name); fwrite($f, $this->col_delim); } fwrite($f, $this->row_delim); } foreach ($list_data as $list_row) { foreach (array_keys($list_row->list_view_data) as $col_name) { $field = $list_row->list_view_data[$col_name]; $pieces = explode("\n", $field); $cleaned_pieces = array(); foreach ($pieces as $piece) { $cleaned_pieces[] = trim($piece); } fwrite($f, join(" ", $cleaned_pieces)); if ($i != count($list_row->list_view_data) - 1) { fwrite($f, $this->col_delim); } } fwrite($f, $this->row_delim); } fclose($f); } } } } else { if ($format == "PROSPECTLIST") { require_once "modules/ProspectLists/ProspectList.php"; $pl = new ProspectList(); $pl->name = empty($_REQUEST["prospect_list_name"]) ? $this->name : $_REQUEST["prospect_list_name"]; $pl->save(); foreach ($rows as $row) { if ($row->object_name == "Contact") { $pl->set_relationship('prospect_lists_prospects', array("related_type" => "Contacts", "related_id" => $row->id, 'prospect_list_id' => $pl->id)); } else { if ($row->object_name == "Lead") { $pl->set_relationship('prospect_lists_prospects', array("related_type" => "Leads", "related_id" => $row->id, 'prospect_list_id' => $pl->id)); } else { if ($row->object_name == "Prospect") { $pl->set_relationship('prospect_lists_prospects', array("related_type" => "Prospects", "related_id" => $row->id, 'prospect_list_id' => $pl->id)); } } } } $this->report_result = "index.php?module=ProspectLists&action=DetailView&record=" . $pl->id; $this->report_result_type = "FORWARD"; } } $result = true; } return $result; }
} else { $check_notify = FALSE; } foreach ($focus->column_fields as $field) { if (isset($_POST[$field])) { $value = $_POST[$field]; $focus->{$field} = $value; } } foreach ($focus->additional_column_fields as $field) { if (isset($_POST[$field])) { $value = $_POST[$field]; $focus->{$field} = $value; } } $focus->save($check_notify); $return_id = $focus->id; if (isset($_POST['return_module']) && $_POST['return_module'] != "") { $return_module = $_POST['return_module']; } else { $return_module = "ProspectLists"; } if (isset($_POST['return_action']) && $_POST['return_action'] != "") { $return_action = $_POST['return_action']; } else { $return_action = "DetailView"; } if (isset($_POST['return_id']) && $_POST['return_id'] != "") { $return_id = $_POST['return_id']; } if ($return_action == "SaveCampaignProspectListRelationshipNew") {
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); } } } }