]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/connectors/utils/ConnectorHtmlHelper.php
Release 6.5.5
[Github/sugarcrm.git] / include / connectors / utils / ConnectorHtmlHelper.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-2012 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  * Connector's HTML helper
41  * @api
42  */
43 class ConnectorHtmlHelper
44 {
45     /**
46      * Method return the HTML code for the hover link field
47      *
48      * @param array $shown_sources
49      * @param mixed $module
50      * @param mixed $smarty
51      * @return string
52      */
53     public function getConnectorButtonCode(array $shown_sources, $module, $smarty)
54     {
55         require_once('include/connectors/formatters/FormatterFactory.php');
56
57         return $this->getButton($shown_sources, $module, $smarty);
58     }
59
60     /**
61      * Get button for source
62      *
63      * @param string $shown_source
64      * @param mixed $module
65      * @param mixed $smarty
66      * @return string
67      */
68     private function getButton(array $shown_sources, $module, $smarty)
69     {
70         $code = '';
71
72          foreach($shown_sources as $id) {
73              $formatter = FormatterFactory::getInstance($id);
74              $formatter->setModule($module);
75              $formatter->setSmarty($smarty);
76              $formatter_code = $formatter->getDetailViewFormat();
77              if (!empty($formatter_code))
78              {
79                  $iconFilePath = $formatter->getIconFilePath();
80                  $iconFilePath = empty($iconFilePath) ? 'themes/default/images/MoreDetail.png' : $iconFilePath;
81
82             $code .= '<!--not_in_theme!--><img id="dswidget_img" border="0" src="' . $iconFilePath .'" alt="'
83                          . $id .'" onclick="show_' . $id . '(event);">';
84
85             $code .= "<script type='text/javascript' src='{sugar_getjspath file='include/connectors/formatters/default/company_detail.js'}'></script>";
86                  //$code .= $formatter->getDetailViewFormat();
87                  $code .= $formatter_code;
88              }
89         }
90
91         return $code;
92     }
93
94     /**
95      * Get popup for sources
96      *
97      * @param array $shown_sources
98      * @param mixed $module
99      * @param mixed $smarty
100      * @return string
101      */
102     private function getPopup(array $shown_sources, $module, $smarty)
103     {
104         global $app_strings;
105
106         $code = '';
107         $menuParams = 'var menuParams = "';
108         $formatterCode = '';
109         $sourcesDisplayed = 0;
110         $singleIcon = '';
111         foreach($shown_sources as $id)
112         {
113             $formatter = FormatterFactory::getInstance($id);
114             $formatter->setModule($module);
115             $formatter->setSmarty($smarty);
116             $buttonCode = $formatter->getDetailViewFormat();
117             if (!empty($buttonCode))
118             {
119                 $sourcesDisplayed++;
120                 $singleIcon = $formatter->getIconFilePath();
121                 $source = SourceFactory::getSource($id);
122                 $config = $source->getConfig();
123                 $name = !empty($config['name']) ? $config['name'] : $id;
124                 //Create the menu item to call show_[source id] method in javascript
125                 $menuParams .= '<a href=\'#\' style=\'width:150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\''
126                             . ' onmouseout=\'unhiliteItem(this);\' onclick=\'show_' . $id . '(event);\'>' . $name . '</a>';
127                 $formatterCode .= $buttonCode;
128             }
129         } //for
130
131         if (!empty($formatterCode))
132         {
133             if ($sourcesDisplayed > 1)
134             {
135                 $dswidget_img = SugarThemeRegistry::current()->getImageURL('MoreDetail.png');
136                 $code = '<!--not_in_theme!--><img id="dswidget_img" src="' . $dswidget_img . '" width="11" height="7" border="0" alt="'
137                         . $app_strings['LBL_CONNECTORS_POPUPS'] . '" onclick="return showConnectorMenu2(this);">';
138             }
139             else
140             {
141                 $dswidget_img = SugarThemeRegistry::current()->getImageURL('MoreDetail.png');
142                 $singleIcon = empty($singleIcon) ? $dswidget_img : $singleIcon;
143                 $code = '<!--not_in_theme!--><img id="dswidget_img" border="0" src="' . $singleIcon . '" alt="'.$app_strings['LBL_CONNECTORS_POPUPS']
144                         . '" onclick="return showConnectorMenu2(this);">';
145
146             }
147             $code .= "<script type='text/javascript' src='{sugar_getjspath file='include/connectors/formatters/default/company_detail.js'}'></script>\n";
148             $code .= "<script type='text/javascript'>\n";
149             $code .= "function showConnectorMenu2(el) {literal} { {/literal}\n";
150
151             $menuParams .= '";';
152             $code .= $menuParams . "\n";
153             $code .= "return SUGAR.util.showHelpTips(el,menuParams);\n";
154             $code .= "{literal} } {/literal}\n";
155             $code .= "</script>\n";
156             $code .= $formatterCode;
157         }
158         return $code;
159     }
160 }