]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/TrackDetailView.php
Release 6.4.0
[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         $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>");
137     }
138
139     global $xtpl;
140     $xtpl = $smarty;
141
142     $detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
143     // adding custom fields:
144     require_once('modules/DynamicFields/templates/Files/DetailView.php');
145
146
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'];
154
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";
158
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'];
166             }
167
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"
178             }else{
179                 $options_str .='>'. $row['name'] .'</option>';
180             }
181         }
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>';
189             }else{
190                 $options_str .=' >'. $row['name'] .'</option>';
191             }
192          }
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);
197     }
198 //add chart
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();
205
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
208
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));
212     }else{
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));
214     }
215
216 //end chart
217 //custom chart code
218     require_once('include/SugarCharts/SugarChartFactory.php');
219     $sugarChart = SugarChartFactory::getInstance();
220         $resources = $sugarChart->getChartResources();
221         $smarty->assign('chartResources', $resources);
222
223 echo $smarty->fetch('modules/Campaigns/TrackDetailView.tpl');
224
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
231     }else{
232         //get array of layout defs
233         $layoutDefsArr= $subpanel->subpanel_definitions->layout_defs;
234
235         //iterate through layout defs for processing of subpanels.  If a marketing Id is specified, then we need to...
236         //.. filter the subpanels by it so they match the chart rendered in code above.
237         foreach($layoutDefsArr as $subpanels_name => $subpanels){
238
239             //process each subpanel definition
240              foreach($subpanels as $subpane_key => $subpane){
241
242                     //see if "function_parameters" key exists in subpanel properties array
243                       if (isset($subpane['function_parameters'])){
244                           //if a function_parameters property key exists, then process further
245                           $functionParamsArr = $subpane['function_parameters'];//$panelProperty;
246
247                             //Check the array of function parameters and see if
248                             //one exists for market value id.
249                             if (isset($functionParamsArr['EMAIL_MARKETING_ID_VALUE'])){
250                                 //We found the property, lets fill in the marketing id value...
251                                 //.. into the subpanel object, using the keys of the array that..
252                                 //.. we used to get to thi property
253                                 $subpanel->subpanel_definitions->layout_defs[$subpanels_name][$subpane_key]['function_parameters']['EMAIL_MARKETING_ID_VALUE'] = $latest_marketing_id;
254                             }
255                         }//end if (isset($subpane['function_parameters'])){
256             }//end foreach($subpanels as $subpane_key => $subpane){
257
258         }//_pp($subpanel->subpanel_definitions->layout_defs);
259     }//end else
260
261 $alltabs=$subpanel->subpanel_definitions->get_available_tabs();
262 if (!empty($alltabs)) {
263
264     foreach ($alltabs as $name) {
265         if ($name == 'prospectlists' || $name=='emailmarketing' || $name == 'tracked_urls') {
266             $subpanel->subpanel_definitions->exclude_tab($name);
267         }
268     }
269 }
270 echo $subpanel->display();
271 ?>