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-2013 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;
63 $GLOBALS['log']->info("Campaign detail view");
65 $xtpl=new XTemplate ('modules/Campaigns/PopupCampaignRoi.html');
67 //_pp($_REQUEST['id']);
68 $campaign_id=$_REQUEST['id'];
69 $campaign = new Campaign();
70 $opp_query1 = "select camp.name, camp.actual_cost,camp.budget,camp.expected_revenue,count(*) opp_count,SUM(opp.amount) as Revenue, SUM(camp.actual_cost) as Investment,
71 ROUND((SUM(opp.amount) - SUM(camp.actual_cost))/(SUM(camp.actual_cost)), 2)*100 as ROI";
72 $opp_query1 .= " from opportunities opp";
73 $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id";
74 $opp_query1 .= " where opp.sales_stage = 'Closed Won' and camp.id='$campaign_id'";
75 $opp_query1 .= " group by camp.name";
76 //$opp_query1 .= " and deleted=0";
77 $opp_result1=$campaign->db->query($opp_query1);
78 $opp_data1=$campaign->db->fetchByAssoc($opp_result1);
79 //get the click-throughs
80 $query_click = "SELECT count(*) hits ";
81 $query_click.= " FROM campaign_log ";
82 $query_click.= " WHERE campaign_id = '$campaign_id' AND activity_type='link' AND related_type='CampaignTrackers' AND archived=0 AND deleted=0";
84 //if $marketing id is specified, then lets filter the chart by the value
85 if (!empty($marketing_id)){
86 $query_click.= " AND marketing_id ='$marketing_id'";
89 $query_click.= " GROUP BY activity_type, target_type";
90 $query_click.= " ORDER BY activity_type, target_type";
91 $result = $campaign->db->query($query_click);
94 $xtpl->assign("OPP_COUNT", $opp_data1['opp_count']);
95 $xtpl->assign("ACTUAL_COST",$opp_data1['actual_cost']);
96 $xtpl->assign("PLANNED_BUDGET",$opp_data1['budget']);
97 $xtpl->assign("EXPECTED_REVENUE",$opp_data1['expected_revenue']);
102 $currency = new Currency();
103 if(isset($focus->currency_id) && !empty($focus->currency_id))
105 $currency->retrieve($focus->currency_id);
106 if( $currency->deleted != 1){
107 $xtpl->assign("CURRENCY", $currency->iso4217 .' '.$currency->symbol );
108 }else $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
111 $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
115 global $current_user;
116 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
118 $xtpl->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>");
122 //$detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
123 // adding custom fields:
124 //require_once('modules/DynamicFields/templates/Files/DetailView.php');
126 /* we need to build the dropdown of related marketing values
127 $latest_marketing_id = '';
128 $selected_marketing_id = '';
129 if(isset($_REQUEST['mkt_id'])) $selected_marketing_id = $_REQUEST['mkt_id'];
130 $options_str = '<option value="all">--None--</option>';
131 //query for all email marketing records related to this campaign
132 $latest_marketing_query = "select id, name, date_modified from email_marketing where campaign_id = '$focus->id' order by date_modified desc";
134 //build string with value(s) retrieved
135 $result =$campaign->db->query($latest_marketing_query);
136 if ($row = $campaign->db->fetchByAssoc($result)){
137 //first, populated the latest marketing id variable, as this
138 // variable will be used to build chart and subpanels
139 $latest_marketing_id = $row['id'];
140 //fill in first option value
141 $options_str .= '<option value="'. $row['id'] .'"';
142 // if the marketing id is same as selected marketing id, set this option to render as "selected"
143 if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
144 $options_str .=' selected>'. $row['name'] .'</option>';
145 // if the marketing id is empty then set this first option to render as "selected"
146 }elseif(empty($selected_marketing_id)){
147 $options_str .=' selected>'. $row['name'] .'</option>';
148 // if the marketing is not empty, but not same as selected marketing id, then..
149 //.. do not set this option to render as "selected"
151 $options_str .='>'. $row['name'] .'</option>';
154 //process rest of records, if they exist
155 while ($row = $campaign->db->fetchByAssoc($result)){
156 //add to list of option values
157 $options_str .= '<option value="'. $row['id'] .'"';
158 //if the marketing id is same as selected marketing id, then set this option to render as "selected"
159 if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
160 $options_str .=' selected>'. $row['name'] .'</option>';
162 $options_str .=' >'. $row['name'] .'</option>';
165 //populate the dropdown
166 $xtpl->assign("MKT_DROP_DOWN",$options_str);
171 $seps = array("-", "/");
172 $dates = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
173 $dateFileNameSafe = str_replace($seps, "_", $dates);
174 $cache_file_name_roi = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
175 $chart= new campaign_charts();
179 //if marketing id has been selected, then set "latest_marketing_id" to the selected value
180 //latest marketing id will be passed in to filter the charts and subpanels
182 if(!empty($selected_marketing_id)){$latest_marketing_id = $selected_marketing_id;}
183 if(empty($latest_marketing_id) || $latest_marketing_id === 'all'){
184 $xtpl->assign("MY_CHART_ROI", $chart->campaign_response_roi_popup($app_list_strings['roi_type_dom'],$app_list_strings['roi_type_dom'],$campaign_id,sugar_cached("xml/") . $cache_file_name_roi,true));
187 $xtpl->assign("MY_CHART_ROI", $chart->campaign_response_roi_popup($app_list_strings['roi_type_dom'],$app_list_strings['roi_type_dom'],$campaign_id,sugar_cached("xml/") .$cache_file_name_roi,true));
190 //$output_html .= ob_get_contents();
197 $xtpl->parse("main");