2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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 ********************************************************************************/
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 get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_NEWSLETTER'].": ".$focus->name, true);
82 echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME'].": ".$focus->name, true);
85 $GLOBALS['log']->info("Campaign detail view");
87 $xtpl=new XTemplate ('modules/Campaigns/TrackDetailView.html');
88 $xtpl->assign("MOD", $mod_strings);
89 $xtpl->assign("APP", $app_strings);
91 $xtpl->assign("GRIDLINE", $gridline);
92 $xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
93 $xtpl->assign("ID", $focus->id);
94 $xtpl->assign("ASSIGNED_TO", $focus->assigned_user_name);
95 $xtpl->assign("STATUS", $app_list_strings['campaign_status_dom'][$focus->status]);
96 $xtpl->assign("NAME", $focus->name);
97 $xtpl->assign("TYPE", $app_list_strings['campaign_type_dom'][$focus->campaign_type]);
98 $xtpl->assign("START_DATE", $focus->start_date);
99 $xtpl->assign("END_DATE", $focus->end_date);
101 $xtpl->assign("BUDGET", $focus->budget);
102 $xtpl->assign("ACTUAL_COST", $focus->actual_cost);
103 $xtpl->assign("EXPECTED_COST", $focus->expected_cost);
104 $xtpl->assign("EXPECTED_REVENUE", $focus->expected_revenue);
107 $xtpl->assign("OBJECTIVE", nl2br($focus->objective));
108 $xtpl->assign("CONTENT", nl2br($focus->content));
109 $xtpl->assign("DATE_MODIFIED", $focus->date_modified);
110 $xtpl->assign("DATE_ENTERED", $focus->date_entered);
112 $xtpl->assign("CREATED_BY", $focus->created_by_name);
113 $xtpl->assign("MODIFIED_BY", $focus->modified_by_name);
114 $xtpl->assign("TRACKER_URL", $sugar_config['site_url'] . '/campaign_tracker.php?track=' . $focus->tracker_key);
115 $xtpl->assign("TRACKER_COUNT", intval($focus->tracker_count));
116 $xtpl->assign("TRACKER_TEXT", $focus->tracker_text);
117 $xtpl->assign("REFER_URL", $focus->refer_url);
119 if(isset($focus->campaign_type) && $focus->campaign_type == "Email" || $focus->campaign_type == "NewsLetter") {
120 $xtpl->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']} \">");
123 $currency = new Currency();
124 if(isset($focus->currency_id) && !empty($focus->currency_id))
126 $currency->retrieve($focus->currency_id);
127 if( $currency->deleted != 1){
128 $xtpl->assign("CURRENCY", $currency->iso4217 .' '.$currency->symbol );
129 }else $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
132 $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
135 global $current_user;
136 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
138 $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' alt='Edit Layout' align='bottom'")."</a>");
141 $detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
142 // adding custom fields:
143 require_once('modules/DynamicFields/templates/Files/DetailView.php');
146 //if this is a newsletter, we need to build dropdown
147 $selected_marketing_id = '';
148 if(isset($focus->campaign_type)){
149 //we need to build the dropdown of related marketing values
150 $options_str = "<select onchange= \"this.form.module.value='Campaigns';this.form.action.value='TrackDetailView'; submit()\" name='mkt_id'>";
151 $latest_marketing_id = '';
152 if(isset($_REQUEST['mkt_id'])) $selected_marketing_id = $_REQUEST['mkt_id'];
154 $options_str .= '<option value="all">--None--</option>';
155 //query for all email marketing records related to this campaign
156 $latest_marketing_query = "select id, name, date_modified from email_marketing where campaign_id = '$focus->id' order by date_modified desc";
158 //build string with value(s) retrieved
159 $result =$focus->db->query($latest_marketing_query);
160 if ($row = $focus->db->fetchByAssoc($result)){
161 //first, populated the latest marketing id variable, as this
162 // variable will be used to build chart and subpanels
163 if($focus->campaign_type == 'NewsLetter') {
164 $latest_marketing_id = $row['id'];
167 //fill in first option value
168 $options_str .= '<option value="'. $row['id'] .'"';
169 // if the marketing id is same as selected marketing id, set this option to render as "selected"
170 if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
171 $options_str .=' selected>'. $row['name'] .'</option>';
172 // if the marketing id is empty then set this first option to render as "selected"
173 }elseif(empty($selected_marketing_id) && $focus->campaign_type == 'NewsLetter'){
174 $options_str .=' selected>'. $row['name'] .'</option>';
175 // if the marketing is not empty, but not same as selected marketing id, then..
176 //.. do not set this option to render as "selected"
178 $options_str .='>'. $row['name'] .'</option>';
181 //process rest of records, if they exist
182 while ($row = $focus->db->fetchByAssoc($result)){
183 //add to list of option values
184 $options_str .= '<option value="'. $row['id'] .'"';
185 //if the marketing id is same as selected marketing id, then set this option to render as "selected"
186 if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
187 $options_str .=' selected>'. $row['name'] .'</option>';
189 $options_str .=' >'. $row['name'] .'</option>';
192 $options_str .="</select>";
193 //populate the dropdown
194 $xtpl->assign("FILTER_LABEL", $mod_strings['LBL_FILTER_CHART_BY']);
195 $xtpl->assign("MKT_DROP_DOWN",$options_str);
198 $seps = array("-", "/");
199 $dates = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
200 $dateFileNameSafe = str_replace($seps, "_", $dates);
201 $cache_file_name = $current_user->getUserPrivGuid()."_campaign_response_by_activity_type_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
202 $cache_file_name_roi = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
203 $chart= new campaign_charts();
205 //if marketing id has been selected, then set "latest_marketing_id" to the selected value
206 //latest marketing id will be passed in to filter the charts and subpanels
208 if(!empty($selected_marketing_id)){$latest_marketing_id = $selected_marketing_id;}
209 if(empty($latest_marketing_id) || $latest_marketing_id === 'all'){
210 $xtpl->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));
212 $xtpl->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));
217 $xtpl->parse("main");
220 require_once('include/SubPanel/SubPanelTiles.php');
221 $subpanel = new SubPanelTiles($focus, 'Campaigns');
222 //if latest marketing id is empty, or if it is set to 'all'', then do no filtering, otherwise filter..
223 //.. out the chart and subpanels by marketing id
224 if(empty($latest_marketing_id) || $latest_marketing_id === 'all'){
225 //do nothing, no filtering is needed
227 //get array of layout defs
228 $layoutDefsArr= $subpanel->subpanel_definitions->layout_defs;
230 //iterate through layout defs for processing of subpanels. If a marketing Id is specified, then we need to...
231 //.. filter the subpanels by it so they match the chart rendered in code above.
232 foreach($layoutDefsArr as $subpanels_name => $subpanels){
234 //process each subpanel definition
235 foreach($subpanels as $subpane_key => $subpane){
237 //see if "function_parameters" key exists in subpanel properties array
238 if (isset($subpane['function_parameters'])){
239 //if a function_parameters property key exists, then process further
240 $functionParamsArr = $subpane['function_parameters'];//$panelProperty;
242 //Check the array of function parameters and see if
243 //one exists for market value id.
244 if (isset($functionParamsArr['EMAIL_MARKETING_ID_VALUE'])){
245 //We found the property, lets fill in the marketing id value...
246 //.. into the subpanel object, using the keys of the array that..
247 //.. we used to get to thi property
248 $subpanel->subpanel_definitions->layout_defs[$subpanels_name][$subpane_key]['function_parameters']['EMAIL_MARKETING_ID_VALUE'] = $latest_marketing_id;
250 }//end if (isset($subpane['function_parameters'])){
251 }//end foreach($subpanels as $subpane_key => $subpane){
253 }//_pp($subpanel->subpanel_definitions->layout_defs);
256 $alltabs=$subpanel->subpanel_definitions->get_available_tabs();
257 if (!empty($alltabs)) {
259 foreach ($alltabs as $name) {
260 if ($name == 'prospectlists' || $name=='emailmarketing' || $name == 'tracked_urls') {
261 $subpanel->subpanel_definitions->exclude_tab($name);
265 echo $subpanel->display();