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