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 ********************************************************************************/
50 require_once('include/DetailView/DetailView.php');
51 require_once('modules/Campaigns/Charts.php');
56 global $app_list_strings;
57 global $sugar_version, $sugar_config;
59 $focus = new Campaign();
61 $detailView = new DetailView();
64 if (isset($_REQUEST['offset']) or isset($_REQUEST['record'])) {
65 $result = $detailView->processSugarBean("CAMPAIGN", $focus, $offset);
67 sugar_die($app_strings['ERROR_NO_RECORD']);
71 header("Location: index.php?module=Accounts&action=index");
74 // if campaign type is set to newsletter, then include newsletter detail view..
75 // ..else default to legacy detail view
77 // include ('modules/Campaigns/NewsLetterTrackDetailView.php');
79 if(isset($focus->campaign_type) && $focus->campaign_type == "NewsLetter"){
80 echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_NEWSLETTER'],$focus->name), true);
82 echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_NAME'],$focus->name), true);
85 $GLOBALS['log']->info("Campaign detail view");
86 $smarty = new Sugar_Smarty();
87 $smarty->assign("MOD", $mod_strings);
88 $smarty->assign("APP", $app_strings);
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);
118 if(isset($focus->campaign_type) && $focus->campaign_type == "Email" || $focus->campaign_type == "NewsLetter") {
119 $smarty->assign("TRACK_DELETE_BUTTON","<input title=\"{$mod_strings['LBL_TRACK_DELETE_BUTTON_TITLE']}\" class=\"button\" onclick=\"this.form.module.value='Campaigns'; this.form.action.value='Delete';this.form.return_module.value='Campaigns'; this.form.return_action.value='TrackDetailView';this.form.mode.value='Test';return confirm('{$mod_strings['LBL_TRACK_DELETE_CONFIRM']}');\" type=\"submit\" name=\"button\" value=\" {$mod_strings['LBL_TRACK_DELETE_BUTTON_LABEL']} \">");
122 $currency = new Currency();
123 if(isset($focus->currency_id) && !empty($focus->currency_id))
125 $currency->retrieve($focus->currency_id);
126 if( $currency->deleted != 1){
127 $smarty->assign("CURRENCY", $currency->iso4217 .' '.$currency->symbol );
128 }else $smarty->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
131 $smarty->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
134 global $current_user;
135 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
136 $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>");
142 $detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
143 // adding custom fields:
144 require_once('modules/DynamicFields/templates/Files/DetailView.php');
147 //if this is a newsletter, we need to build dropdown
148 $selected_marketing_id = '';
149 if(isset($focus->campaign_type)){
150 //we need to build the dropdown of related marketing values
151 $options_str = "<select onchange= \"this.form.module.value='Campaigns';this.form.action.value='TrackDetailView'; submit()\" name='mkt_id'>";
152 $latest_marketing_id = '';
153 if(isset($_REQUEST['mkt_id'])) $selected_marketing_id = $_REQUEST['mkt_id'];
155 $options_str .= '<option value="all">--None--</option>';
156 //query for all email marketing records related to this campaign
157 $latest_marketing_query = "select id, name, date_modified from email_marketing where campaign_id = '$focus->id' order by date_modified desc";
159 //build string with value(s) retrieved
160 $result =$focus->db->query($latest_marketing_query);
161 if ($row = $focus->db->fetchByAssoc($result)){
162 //first, populated the latest marketing id variable, as this
163 // variable will be used to build chart and subpanels
164 if($focus->campaign_type == 'NewsLetter') {
165 $latest_marketing_id = $row['id'];
168 //fill in first option value
169 $options_str .= '<option value="'. $row['id'] .'"';
170 // if the marketing id is same as selected marketing id, set this option to render as "selected"
171 if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
172 $options_str .=' selected>'. $row['name'] .'</option>';
173 // if the marketing id is empty then set this first option to render as "selected"
174 }elseif(empty($selected_marketing_id) && $focus->campaign_type == 'NewsLetter'){
175 $options_str .=' selected>'. $row['name'] .'</option>';
176 // if the marketing is not empty, but not same as selected marketing id, then..
177 //.. do not set this option to render as "selected"
179 $options_str .='>'. $row['name'] .'</option>';
182 //process rest of records, if they exist
183 while ($row = $focus->db->fetchByAssoc($result)){
184 //add to list of option values
185 $options_str .= '<option value="'. $row['id'] .'"';
186 //if the marketing id is same as selected marketing id, then set this option to render as "selected"
187 if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
188 $options_str .=' selected>'. $row['name'] .'</option>';
190 $options_str .=' >'. $row['name'] .'</option>';
193 $options_str .="</select>";
194 //populate the dropdown
195 $smarty->assign("FILTER_LABEL", $mod_strings['LBL_FILTER_CHART_BY']);
196 $smarty->assign("MKT_DROP_DOWN",$options_str);
199 $seps = array("-", "/");
200 $dates = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
201 $dateFileNameSafe = str_replace($seps, "_", $dates);
202 $cache_file_name = $current_user->getUserPrivGuid()."_campaign_response_by_activity_type_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
203 $cache_file_name_roi = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
204 $chart= new campaign_charts();
206 //if marketing id has been selected, then set "latest_marketing_id" to the selected value
207 //latest marketing id will be passed in to filter the charts and subpanels
209 if(!empty($selected_marketing_id)){$latest_marketing_id = $selected_marketing_id;}
210 if(empty($latest_marketing_id) || $latest_marketing_id === 'all'){
211 $smarty->assign("MY_CHART", $chart->campaign_response_by_activity_type($app_list_strings['campainglog_activity_type_dom'],$app_list_strings['campainglog_target_type_dom'],$focus->id,sugar_cached("xml/$cache_file_name"),true));
213 $smarty->assign("MY_CHART", $chart->campaign_response_by_activity_type($app_list_strings['campainglog_activity_type_dom'],$app_list_strings['campainglog_target_type_dom'],$focus->id,sugar_cached("xml/$cache_file_name"),true,$latest_marketing_id));
218 require_once('include/SugarCharts/SugarChartFactory.php');
219 $sugarChart = SugarChartFactory::getInstance();
220 $resources = $sugarChart->getChartResources();
221 $smarty->assign('chartResources', $resources);
223 echo $smarty->fetch('modules/Campaigns/TrackDetailView.tpl');
225 require_once('include/SubPanel/SubPanelTiles.php');
226 $subpanel = new SubPanelTiles($focus, 'Campaigns');
227 //if latest marketing id is empty, or if it is set to 'all'', then do no filtering, otherwise filter..
228 //.. out the chart and subpanels by marketing id
229 if(empty($latest_marketing_id) || $latest_marketing_id === 'all'){
230 //do nothing, no filtering is needed
233 // assign selected marketing ID back to request in order to let ListView use it as a part of subpanel base URL
234 $_GET['mkt_id'] = $latest_marketing_id;
236 //get array of layout defs
237 $layoutDefsArr= $subpanel->subpanel_definitions->layout_defs;
239 //iterate through layout defs for processing of subpanels. If a marketing Id is specified, then we need to...
240 //.. filter the subpanels by it so they match the chart rendered in code above.
241 foreach($layoutDefsArr as $subpanels_name => $subpanels){
243 //process each subpanel definition
244 foreach($subpanels as $subpane_key => $subpane){
246 //see if "function_parameters" key exists in subpanel properties array
247 if (isset($subpane['function_parameters'])){
248 //if a function_parameters property key exists, then process further
249 $functionParamsArr = $subpane['function_parameters'];//$panelProperty;
251 //Check the array of function parameters and see if
252 //one exists for market value id.
253 if (isset($functionParamsArr['EMAIL_MARKETING_ID_VALUE'])){
254 //We found the property, lets fill in the marketing id value...
255 //.. into the subpanel object, using the keys of the array that..
256 //.. we used to get to thi property
257 $subpanel->subpanel_definitions->layout_defs[$subpanels_name][$subpane_key]['function_parameters']['EMAIL_MARKETING_ID_VALUE'] = $latest_marketing_id;
259 }//end if (isset($subpane['function_parameters'])){
260 }//end foreach($subpanels as $subpane_key => $subpane){
262 }//_pp($subpanel->subpanel_definitions->layout_defs);
265 $deletedCampaignLogLeadsCount = $focus->getDeletedCampaignLogLeadsCount();
266 if ($deletedCampaignLogLeadsCount > 0)
268 $subpanel->subpanel_definitions->layout_defs['subpanel_setup']['lead']['top_buttons'][] = array(
269 'widget_class' => 'SubPanelTopMessage',
270 'message' => string_format($mod_strings['LBL_LEADS_DELETED_SINCE_CREATED'], array($deletedCampaignLogLeadsCount)),
274 $alltabs=$subpanel->subpanel_definitions->get_available_tabs();
275 if (!empty($alltabs)) {
277 foreach ($alltabs as $name) {
278 if ($name == 'prospectlists' || $name=='emailmarketing' || $name == 'tracked_urls') {
279 $subpanel->subpanel_definitions->exclude_tab($name);
283 echo $subpanel->display();