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