2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
49 require_once('include/DetailView/DetailView.php');
50 require_once('modules/Campaigns/Charts.php');
55 global $app_list_strings;
56 global $sugar_version, $sugar_config;
58 $focus = new Campaign();
60 $detailView = new DetailView();
63 if (isset($_REQUEST['offset']) or isset($_REQUEST['record'])) {
64 $result = $detailView->processSugarBean("CAMPAIGN", $focus, $offset);
66 sugar_die($app_strings['ERROR_NO_RECORD']);
70 header("Location: index.php?module=Accounts&action=index");
73 // For all campaigns show the same ROI interface
74 // ..else default to legacy detail view
76 if(!$focus->campaign_type == "NewsLetter"){
77 include ('modules/Campaigns/NewsLetterTrackDetailView.php');
81 echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_NAME'],$focus->name), true);
83 $GLOBALS['log']->info("Campaign detail view");
85 $smarty = new Sugar_Smarty();
86 $smarty->assign("MOD", $mod_strings);
87 $smarty->assign("APP", $app_strings);
89 $smarty->assign("THEME", $theme);
90 $smarty->assign("GRIDLINE", $gridline);
91 $smarty->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
92 $smarty->assign("ID", $focus->id);
93 $smarty->assign("ASSIGNED_TO", $focus->assigned_user_name);
94 $smarty->assign("STATUS", $app_list_strings['campaign_status_dom'][$focus->status]);
95 $smarty->assign("NAME", $focus->name);
96 $smarty->assign("TYPE", $app_list_strings['campaign_type_dom'][$focus->campaign_type]);
97 $smarty->assign("START_DATE", $focus->start_date);
98 $smarty->assign("END_DATE", $focus->end_date);
100 $smarty->assign("BUDGET", $focus->budget);
101 $smarty->assign("ACTUAL_COST", $focus->actual_cost);
102 $smarty->assign("EXPECTED_COST", $focus->expected_cost);
103 $smarty->assign("EXPECTED_REVENUE", $focus->expected_revenue);
106 $smarty->assign("OBJECTIVE", nl2br($focus->objective));
107 $smarty->assign("CONTENT", nl2br($focus->content));
108 $smarty->assign("DATE_MODIFIED", $focus->date_modified);
109 $smarty->assign("DATE_ENTERED", $focus->date_entered);
111 $smarty->assign("CREATED_BY", $focus->created_by_name);
112 $smarty->assign("MODIFIED_BY", $focus->modified_by_name);
113 $smarty->assign("TRACKER_URL", $sugar_config['site_url'] . '/campaign_tracker.php?track=' . $focus->tracker_key);
114 $smarty->assign("TRACKER_COUNT", intval($focus->tracker_count));
115 $smarty->assign("TRACKER_TEXT", $focus->tracker_text);
116 $smarty->assign("REFER_URL", $focus->refer_url);
117 $smarty->assign("IMPRESSIONS", $focus->impressions);
119 $roi_vals['budget']= $focus->budget;
120 $roi_vals['actual_cost']= $focus->actual_cost;
121 $roi_vals['Expected_Revenue']= $focus->expected_revenue;
122 $roi_vals['Expected_Cost']= $focus->expected_cost;
124 //Query for opportunities won, clickthroughs
125 $campaign_id = $focus->id;
126 $opp_query1 = "select camp.name, count(*) opp_count,SUM(opp.amount) as Revenue, SUM(camp.actual_cost) as Investment,
127 ROUND((SUM(opp.amount) - SUM(camp.actual_cost))/(SUM(camp.actual_cost)), 2)*100 as ROI";
128 $opp_query1 .= " from opportunities opp";
129 $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id";
130 $opp_query1 .= " where opp.sales_stage = 'Closed Won' and camp.id='$campaign_id'";
131 $opp_query1 .= " and opp.deleted=0";
132 $opp_query1 .= " group by camp.name";
133 $opp_result1=$focus->db->query($opp_query1);
134 $opp_data1=$focus->db->fetchByAssoc($opp_result1);
135 if(empty($opp_data1['opp_count'])) $opp_data1['opp_count']=0;
137 $smarty->assign("OPPORTUNITIES_WON",$opp_data1['opp_count']);
139 $camp_query1 = "select camp.name, count(*) click_thru_link";
140 $camp_query1 .= " from campaign_log camp_log";
141 $camp_query1 .= " right join campaigns camp on camp.id = camp_log.campaign_id";
142 $camp_query1 .= " where camp_log.activity_type = 'link' and camp.id='$campaign_id'";
143 $camp_query1 .= " group by camp.name";
144 $opp_query1 .= " and deleted=0";
145 $camp_result1=$focus->db->query($camp_query1);
146 $camp_data1=$focus->db->fetchByAssoc($camp_result1);
148 if(unformat_number($focus->impressions) > 0){
149 $cost_per_impression= unformat_number($focus->actual_cost)/unformat_number($focus->impressions);
152 $cost_per_impression = format_number(0);
154 $smarty->assign("COST_PER_IMPRESSION",currency_format_number($cost_per_impression));
155 if(empty($camp_data1['click_thru_link'])) $camp_data1['click_thru_link']=0;
156 $click_thru_links = $camp_data1['click_thru_link'];
158 if($click_thru_links >0){
159 $cost_per_click_thru= unformat_number($focus->actual_cost)/unformat_number($click_thru_links);
162 $cost_per_click_thru = format_number(0);
164 $smarty->assign("COST_PER_CLICK_THROUGH",currency_format_number($cost_per_click_thru));
167 $currency = new Currency();
168 if(isset($focus->currency_id) && !empty($focus->currency_id))
170 $currency->retrieve($focus->currency_id);
171 if( $currency->deleted != 1){
172 $smarty->assign("CURRENCY", $currency->iso4217 .' '.$currency->symbol );
173 }else $smarty->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
176 $smarty->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
179 global $current_user;
180 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
182 $smarty->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$_REQUEST['record']. "'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' align='bottom'", null,null,'.gif',$mod_strings['LBL_EDIT_LAYOUT'])."</a>");
186 $detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
187 // adding custom fields:
190 require_once('modules/DynamicFields/templates/Files/DetailView.php');
197 $seps = array("-", "/");
198 $dates = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
199 $dateFileNameSafe = str_replace($seps, "_", $dates);
200 //$cache_file_name = $current_user->getUserPrivGuid()."_campaign_response_by_activity_type_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
201 $cache_file_name_roi = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
202 $chart= new campaign_charts();
204 $smarty->assign("MY_CHART_ROI", $chart->campaign_response_roi($app_list_strings['roi_type_dom'],$app_list_strings['roi_type_dom'],$focus->id,true,true));
207 require_once('include/SugarCharts/SugarChartFactory.php');
208 $sugarChart = SugarChartFactory::getInstance();
209 $resources = $sugarChart->getChartResources();
210 $smarty->assign('chartResources', $resources);
212 echo $smarty->fetch('modules/Campaigns/RoiDetailView.tpl');