]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/TrackDetailView.php
Release 6.2.1
[Github/sugarcrm.git] / modules / Campaigns / TrackDetailView.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48
49
50 require_once('include/DetailView/DetailView.php');
51 require_once('modules/Campaigns/Charts.php');
52
53
54 global $mod_strings;
55 global $app_strings;
56 global $app_list_strings;
57 global $sugar_version, $sugar_config;
58
59 $focus = new Campaign();
60
61 $detailView = new DetailView();
62 $offset = 0;
63 $offset=0;
64 if (isset($_REQUEST['offset']) or isset($_REQUEST['record'])) {
65         $result = $detailView->processSugarBean("CAMPAIGN", $focus, $offset);
66         if($result == null) {
67             sugar_die($app_strings['ERROR_NO_RECORD']);
68         }
69         $focus=$result;
70 } else {
71         header("Location: index.php?module=Accounts&action=index");
72 }
73
74 // if campaign type is set to newsletter, then include newsletter detail view..
75 // ..else default to legacy detail view
76
77 //    include ('modules/Campaigns/NewsLetterTrackDetailView.php');
78
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);
81 } else{
82     echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_NAME'],$focus->name), true);
83 }    
84     
85     $GLOBALS['log']->info("Campaign detail view");
86     $smarty = new Sugar_Smarty();
87     $smarty->assign("MOD", $mod_strings);
88     $smarty->assign("APP", $app_strings);
89     
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);
99     
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);
104     
105     
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);
110     
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     
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']}\" accessKey=\"{$mod_strings['LBL_TRACK_DELETE_BUTTON_KEY']}\" 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']}  \">");
120     }
121     
122         $currency  = new Currency();
123     if(isset($focus->currency_id) && !empty($focus->currency_id))
124     {
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() );
129     }else{
130     
131         $smarty->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
132     
133     }
134     global $current_user;
135     if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
136     
137         $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' alt='Edit Layout' align='bottom'")."</a>");
138     }
139
140     global $xtpl;
141     $xtpl = $smarty;
142
143     $detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
144     // adding custom fields:
145     require_once('modules/DynamicFields/templates/Files/DetailView.php');
146     
147
148     //if this is a newsletter, we need to build dropdown
149     $selected_marketing_id = '';
150     if(isset($focus->campaign_type)){
151         //we need to build the dropdown of related marketing values
152         $options_str = "<select onchange= \"this.form.module.value='Campaigns';this.form.action.value='TrackDetailView'; submit()\" name='mkt_id'>";        
153         $latest_marketing_id = '';
154         if(isset($_REQUEST['mkt_id'])) $selected_marketing_id = $_REQUEST['mkt_id'];
155         
156         $options_str .= '<option value="all">--None--</option>';
157         //query for all email marketing records related to this campaign
158         $latest_marketing_query = "select id, name, date_modified from email_marketing where campaign_id = '$focus->id' order by date_modified desc";
159         
160         //build string with value(s) retrieved
161         $result =$focus->db->query($latest_marketing_query);
162         if ($row = $focus->db->fetchByAssoc($result)){
163             //first, populated the latest marketing id variable, as this
164             // variable will be used to build chart and subpanels
165             if($focus->campaign_type == 'NewsLetter') {
166                 $latest_marketing_id = $row['id'];
167             }
168             
169             //fill in first option value
170             $options_str .= '<option value="'. $row['id'] .'"';
171             // if the marketing id is same as selected marketing id, set this option to render as "selected"
172             if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
173                 $options_str .=' selected>'. $row['name'] .'</option>';
174             // if the marketing id is empty then set this first option to render as "selected"
175             }elseif(empty($selected_marketing_id) && $focus->campaign_type == 'NewsLetter'){
176                 $options_str .=' selected>'. $row['name'] .'</option>';
177             // if the marketing is not empty, but not same as selected marketing id, then..
178             //.. do not set this option to render as "selected"            
179             }else{
180                 $options_str .='>'. $row['name'] .'</option>';
181             }
182         }
183         //process rest of records, if they exist
184         while ($row = $focus->db->fetchByAssoc($result)){
185             //add to list of option values
186             $options_str .= '<option value="'. $row['id'] .'"';
187             //if the marketing id is same as selected marketing id, then set this option to render as "selected"
188             if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
189                 $options_str .=' selected>'. $row['name'] .'</option>';
190             }else{
191                 $options_str .=' >'. $row['name'] .'</option>';
192             }    
193          }
194          $options_str .="</select>";
195         //populate the dropdown    
196         $smarty->assign("FILTER_LABEL", $mod_strings['LBL_FILTER_CHART_BY']);
197         $smarty->assign("MKT_DROP_DOWN",$options_str);
198     }
199 //add chart
200 $seps               = array("-", "/");
201 $dates              = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
202 $dateFileNameSafe   = str_replace($seps, "_", $dates);
203 $cache_file_name    = $current_user->getUserPrivGuid()."_campaign_response_by_activity_type_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
204 $cache_file_name_roi    = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
205 $chart= new campaign_charts();
206
207     //if marketing id has been selected, then set "latest_marketing_id" to the selected value
208     //latest marketing id will be passed in to filter the charts and subpanels 
209  
210     if(!empty($selected_marketing_id)){$latest_marketing_id = $selected_marketing_id;}
211     if(empty($latest_marketing_id) ||  $latest_marketing_id === 'all'){
212         $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_config['tmp_dir'].$cache_file_name,true));        
213     }else{         
214         $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_config['tmp_dir'].$cache_file_name,true,$latest_marketing_id));        
215     }
216
217 //end chart
218 //custom chart code
219     require_once('include/SugarCharts/SugarChartFactory.php');
220     $sugarChart = SugarChartFactory::getInstance();
221         $resources = $sugarChart->getChartResources();
222         $smarty->assign('chartResources', $resources);
223
224 echo $smarty->fetch('modules/Campaigns/TrackDetailView.tpl');
225
226 require_once('include/SubPanel/SubPanelTiles.php');
227 $subpanel = new SubPanelTiles($focus, 'Campaigns');
228     //if latest marketing id is empty, or if it is set to 'all'', then do no filtering, otherwise filter..
229     //.. out the chart and subpanels by marketing id
230     if(empty($latest_marketing_id) || $latest_marketing_id === 'all'){
231         //do nothing, no filtering is needed
232     }else{
233         //get array of layout defs
234         $layoutDefsArr= $subpanel->subpanel_definitions->layout_defs;
235
236         //iterate through layout defs for processing of subpanels.  If a marketing Id is specified, then we need to... 
237         //.. filter the subpanels by it so they match the chart rendered in code above.
238         foreach($layoutDefsArr as $subpanels_name => $subpanels){
239
240             //process each subpanel definition 
241              foreach($subpanels as $subpane_key => $subpane){
242     
243                     //see if "function_parameters" key exists in subpanel properties array 
244                       if (isset($subpane['function_parameters'])){        
245                           //if a function_parameters property key exists, then process further
246                           $functionParamsArr = $subpane['function_parameters'];//$panelProperty;
247
248                             //Check the array of function parameters and see if 
249                             //one exists for market value id.
250                             if (isset($functionParamsArr['EMAIL_MARKETING_ID_VALUE'])){
251                                 //We found the property, lets fill in the marketing id value...
252                                 //.. into the subpanel object, using the keys of the array that..
253                                 //.. we used to get to thi property
254                                 $subpanel->subpanel_definitions->layout_defs[$subpanels_name][$subpane_key]['function_parameters']['EMAIL_MARKETING_ID_VALUE'] = $latest_marketing_id;                                
255                             }
256                         }//end if (isset($subpane['function_parameters'])){
257             }//end foreach($subpanels as $subpane_key => $subpane){
258          
259         }//_pp($subpanel->subpanel_definitions->layout_defs);
260     }//end else
261
262 $alltabs=$subpanel->subpanel_definitions->get_available_tabs();
263 if (!empty($alltabs)) {
264         
265     foreach ($alltabs as $name) {
266         if ($name == 'prospectlists' || $name=='emailmarketing' || $name == 'tracked_urls') {
267             $subpanel->subpanel_definitions->exclude_tab($name);            
268         }   
269     }
270 }
271 echo $subpanel->display();
272 ?>