2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 class InsideViewLogicHook {
42 const urlBase = 'https://my.insideview.com/iv/crm/';
44 protected function handleFieldMap($bean, $mapping) {
46 foreach ( $mapping as $dest => $src ) {
47 // Initialize it to an empty string, so it is always set
48 $outArray[$dest] = '';
50 if ( is_array($src) ) {
51 // The source can be any one of a number of fields
53 foreach ( $src as $src2 ) {
54 if ( isset($bean->$src2) ) {
55 $outArray[$dest] = $bean->$src2;
60 if ( isset($bean->$src) ) {
61 $outArray[$dest] = $bean->$src;
67 foreach ( $outArray as $k => $v ) {
68 $outStr .= $k.'='.rawurlencode(html_entity_decode($v,ENT_QUOTES)).'&';
71 $outStr = rtrim($outStr,'&');
76 protected function getAccountFrameUrl($bean, $extraUrl) {
77 $url = self::urlBase.'analyseAccount.do?crm_context=account&';
78 $fieldMap = array('crm_account_name'=>'name',
79 'crm_account_id'=>'id',
80 'crm_account_website'=>'website',
81 'crm_account_ticker'=>'ticker_symbol',
82 'crm_account_city'=>array('primary_address_city', 'secondary_address_city', 'billing_address_city', 'shipping_address_city'),
83 'crm_account_state'=>array('primary_address_state', 'secondary_address_state', 'billing_address_state', 'shipping_address_state'),
84 'crm_account_country'=>array('primary_address_country', 'secondary_address_country', 'billing_address_country', 'shipping_address_country'),
85 'crm_account_postalcode'=>array('primary_address_postalcode', 'secondary_address_postalcode', 'billing_address_postalcode', 'shipping_address_postalcode')
88 $url .= $this->handleFieldMap($bean,$fieldMap).'&'.$extraUrl;
94 protected function getOpportunityFrameUrl($bean, $extraUrl) {
95 $url = self::urlBase.'analyseAccount.do?crm_context=opportunity&';
96 $fieldMap = array('crm_account_name'=>'account_name',
97 'crm_account_id'=>'account_id',
98 'crm_opportunity_id'=>'id',
101 $url .= $this->handleFieldMap($bean,$fieldMap).'&'.$extraUrl;
106 protected function getLeadFrameUrl($bean, $extraUrl) {
107 $url = self::urlBase.'analyseAccount.do?crm_context=lead&';
108 $fieldMap = array('crm_lead_id'=>'id',
109 'crm_lead_firstname'=>'first_name',
110 'crm_lead_lastname'=>'last_name',
111 'crm_lead_title'=>'title',
112 'crm_account_id'=>'id',
113 'crm_account_name'=>'account_name',
114 'crm_account_website'=>'website',
117 $url .= $this->handleFieldMap($bean,$fieldMap).'&'.$extraUrl;
122 protected function getContactFrameUrl($bean, $extraUrl) {
123 $url = self::urlBase.'analyseExecutive.do?crm_context=contact&';
124 $fieldMap = array('crm_object_id'=>'id',
125 'crm_fn'=>'first_name',
126 'crm_ln'=>'last_name',
127 'crm_email'=>'email',
128 'crm_account_id'=>'account_id',
129 'crm_account_name'=>'account_name',
132 $url .= $this->handleFieldMap($bean,$fieldMap).'&'.$extraUrl;
139 public function showFrame($event, $args) {
140 if ( $GLOBALS['app']->controller->action != 'DetailView' ) {
143 require_once('include/connectors/utils/ConnectorUtils.php');
145 $bean = $GLOBALS['app']->controller->bean;
147 // Build the base arguments
148 static $userFieldMap = array('crm_user_id' => 'id',
149 'crm_user_fn' => 'first_name',
150 'crm_user_ln' => 'last_name',
151 'crm_user_email' => 'email1',
155 if ( $GLOBALS['current_user']->id != '1' ) {
156 $extraUrl = $this->handleFieldMap($GLOBALS['current_user'],$userFieldMap);
158 // Need some extra code here for the '1' admin user
159 $myUserFieldMap = $userFieldMap;
160 unset($myUserFieldMap['crm_user_id']);
161 $extraUrl = 'crm_user_id='.urlencode($GLOBALS['sugar_config']['unique_key']).'&'.$this->handleFieldMap($GLOBALS['current_user'],$myUserFieldMap);
163 $extraUrl .= '&crm_org_id='.urlencode($GLOBALS['sugar_config']['unique_key'])
164 .'&crm_org_name='.urlencode($GLOBALS['system_config']->settings['system_name'])
165 .'&crm_server_url='.urlencode($GLOBALS['sugar_config']['site_url'])
166 .'&crm_session_id=&crm_version=v62&crm_deploy_id=3&crm_size=400&is_embed_version=true';
168 // Use the per-module functions to build the frame
169 if ( is_a($bean,'Account') ) {
170 $url = $this->getAccountFrameUrl($bean, $extraUrl);
171 } else if ( is_a($bean,'Contact') ) {
172 $url = $this->getContactFrameUrl($bean, $extraUrl);
173 } else if ( is_a($bean,'Lead') ) {
174 $url = $this->getLeadFrameUrl($bean, $extraUrl);
175 } else if ( is_a($bean, 'Opportunity') ) {
176 $url = $this->getOpportunityFrameUrl($bean, $extraUrl);
182 // Check if the user should be shown the frame or not
183 $smarty = new Sugar_Smarty();
184 $tplName = 'modules/Connectors/connectors/sources/ext/rest/insideview/tpls/InsideView.tpl';
185 require_once('include/connectors/utils/ConnectorUtils.php');
186 $connector_language = ConnectorUtils::getConnectorStrings('ext_rest_insideview');
187 $smarty->assign('connector_language', $connector_language);
188 $smarty->assign('logo',getWebPath('modules/Connectors/connectors/sources/ext/rest/insideview/images/insideview.png'));
189 $smarty->assign('video',getWebPath('modules/Connectors/connectors/sources/ext/rest/insideview/images/video.png'));
191 $smarty->assign('close',getWebPath('modules/Connectors/connectors/sources/ext/rest/insideview/images/close.png'));
192 $smarty->assign('logo_expanded',getWebPath('modules/Connectors/connectors/sources/ext/rest/insideview/images/insideview_expanded.png'));
193 $smarty->assign('logo_collapsed',getWebPath('modules/Connectors/connectors/sources/ext/rest/insideview/images/insideview_collapsed.png'));
195 $smarty->assign('AJAX_URL',$url);
196 $smarty->assign('APP', $GLOBALS['app_strings']);
198 if ( $GLOBALS['current_user']->getPreference('allowInsideView','Connectors') != 1 )
200 $smarty->assign('showInsideView',false);
203 $smarty->assign('showInsideView',true);
204 $smarty->assign('URL',$url);
205 //echo "<div id='insideViewDiv' style='width:100%;height:400px;overflow:hidden'><iframe id='insideViewFrame' src='$url' style='border:0px; width:100%;height:480px;overflow:hidden'></iframe></div>";
207 echo $smarty->fetch($tplName);