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 ********************************************************************************/
40 require_once('include/SubPanel/SubPanel.php');
41 require_once('include/SubPanel/SubPanelTilesTabs.php');
42 require_once('include/SubPanel/SubPanelDefinitions.php');
52 var $show_tabs = false;
54 var $subpanel_definitions;
56 var $hidden_tabs=array(); //consumer of this class can array of tabs that should be hidden. the tab name
57 //should be the array.
59 function SubPanelTiles(&$focus, $layout_def_key='', $layout_def_override = '')
61 $this->focus = $focus;
62 $this->id = $focus->id;
63 $this->module = $focus->module_dir;
64 $this->layout_def_key = $layout_def_key;
65 $this->subpanel_definitions=new SubPanelDefinitions($focus, $layout_def_key, $layout_def_override);
69 * Return the current selected or requested subpanel tab
70 * @return string The identifier for the selected subpanel tab (e.g., 'Other')
72 function getSelectedGroup()
76 if(isset($_REQUEST['subpanelTabs']))
77 $_SESSION['subpanelTabs'] = $_REQUEST['subpanelTabs'];
79 require_once 'include/tabConfig.php' ; // include/tabConfig.php in turn includes the customized file at custom/include/tabConfig.php...
81 $subpanelTabsPref = $current_user->getPreference('subpanel_tabs');
82 if(!isset($subpanelTabsPref)) $subpanelTabsPref = $GLOBALS['sugar_config']['default_subpanel_tabs'];
83 if(!empty($GLOBALS['tabStructure']) && (!empty($_SESSION['subpanelTabs']) || !empty($sugar_config['subpanelTabs']) || !empty($subpanelTabsPref)))
85 // Determine selected group
86 if(!empty($_REQUEST['subpanel']))
88 $selected_group = $_REQUEST['subpanel'];
90 elseif(!empty($_COOKIE[$this->module.'_sp_tab']))
92 $selected_group = $_COOKIE[$this->module.'_sp_tab'];
94 elseif(!empty($_SESSION['parentTab']) && !empty($GLOBALS['tabStructure'][$_SESSION['parentTab']]) && in_array($this->module, $GLOBALS['tabStructure'][$_SESSION['parentTab']]['modules']))
96 $selected_group = $_SESSION['parentTab'];
100 $selected_group = '';
101 foreach($GLOBALS['tabStructure'] as $mainTab => $group)
103 if(in_array($this->module, $group['modules']))
105 $selected_group = $mainTab;
111 $selected_group = 'All';
117 $selected_group = '';
119 return $selected_group;
123 * Determine which subpanels should be shown within the selected tab group (e.g., 'Other');
124 * @param boolean $showTabs True if we should call the code to render each visible tab
125 * @param string $selectedGroup The requested tab group
126 * @return array Visible tabs
128 function getTabs($showTabs = true, $selectedGroup='')
130 global $current_user;
132 //get all the "tabs" - this actually means all the subpanels available for display within a tab
133 $tabs = $this->subpanel_definitions->get_available_tabs();
135 if(!empty($selectedGroup))
137 return SubPanelTilesTabs::getTabs($tabs, $showTabs, $selectedGroup);
141 // see if user current user has custom subpanel layout
142 $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs);
144 /* Check if the preference is set now,
145 * because there's no point in executing this code if
146 * we aren't going to render anything.
148 $subpanelLinksPref = $current_user->getPreference('subpanel_links');
149 if(!isset($subpanelLinksPref)) $subpanelLinksPref = $GLOBALS['sugar_config']['default_subpanel_links'];
151 if($showTabs && $subpanelLinksPref){
152 require_once('include/SubPanel/SugarTab.php');
153 $sugarTab = new SugarTab();
155 $displayTabs = array();
157 foreach($tabs as $tab){
158 $displayTabs []= array('key'=>$tab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$tab]['title_key']));
159 //echo '<td nowrap="nowrap"><a class="subTabLink" href="#' . $tab . '">' . translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$tab]['title_key']) . '</a></td><td> | </td>';
161 $sugarTab->setup(array(),array(),$displayTabs);
162 $sugarTab->display();
164 //echo '<td width="100%"> </td></tr></table>';
169 function display($showContainer = true, $forceTabless = false)
171 global $layout_edit_mode, $sugar_version, $sugar_config, $current_user, $app_strings;
172 if(isset($layout_edit_mode) && $layout_edit_mode){
176 global $modListHeader;
179 echo '<script type="text/javascript" src="'. getJSPath('include/SubPanel/SubPanelTiles.js') . '"></script>';
182 if(document.DetailView != null &&
183 document.DetailView.elements != null &&
184 document.DetailView.elements.layout_def_key != null &&
185 typeof document.DetailView.elements['layout_def_key'] != 'undefined'){
186 document.DetailView.elements['layout_def_key'].value = '<?php echo $this->layout_def_key; ?>';
192 $default_div_display = 'inline';
193 if(!empty($sugar_config['hide_subpanels_on_login'])){
194 if(!isset($_SESSION['visited_details'][$this->focus->module_dir])){
195 setcookie($this->focus->module_dir . '_divs', '');
196 unset($_COOKIE[$this->focus->module_dir . '_divs']);
197 $_SESSION['visited_details'][$this->focus->module_dir] = true;
200 $default_div_display = 'none';
202 $div_cookies = get_sub_cookies($this->focus->module_dir . '_divs');
205 //Display the group header. this section is executed only if the tabbed interface is being used.
207 if (! empty($this->show_tabs))
209 require_once('include/tabs.php');
210 $tab_panel = new SugarWidgetTabs($tabs, $current_key, 'showSubPanel');
211 echo get_form_header('Related', '', false);
212 echo "<br />" . $tab_panel->display();
215 if(empty($_REQUEST['subpanels']))
217 $selected_group = $forceTabless?'':$this->getSelectedGroup();
218 $usersLayout = $current_user->getPreference('subpanelLayout', $this->focus->module_dir);
220 // we need to use some intelligence here when restoring the user's layout, as new modules with new subpanels might have been installed since the user's layout was recorded
221 // this means that we can't just restore the old layout verbatim as the new subpanels would then go walkabout
222 // so we need to do a merge while attempting as best we can to preserve the sense of the specified order
223 // this is complicated by the different ordering schemes used in the two sources for the panels: the user's layout uses an ordinal layout, the panels from getTabs have an explicit ordering driven by the 'order' parameter
224 // it's not clear how to best reconcile these two schemes; so we punt on it, and add all new panels to the end of the user's layout. At least this will give them a clue that something has changed...
225 // we also now check for tabs that have been removed since the user saved his or her preferences.
227 $tabs = $this->getTabs($showContainer, $selected_group) ;
229 if(!empty($usersLayout))
231 $availableTabs = $tabs ;
232 $tabs = array_intersect ( $usersLayout , $availableTabs ) ; // remove any tabs that have been removed since the user's layout was saved
233 foreach (array_diff ( $availableTabs , $usersLayout ) as $tab)
239 $tabs = explode(',', $_REQUEST['subpanels']);
242 $tab_names = array();
246 echo '<ul class="noBullet" id="subpanel_list">';
248 //echo "<li id='hidden_0' style='height: 5px' class='noBullet'> </li>";
249 if (empty($GLOBALS['relationships'])) {
250 if (!class_exists('Relationship')) {
251 require('modules/Relationships/Relationship.php');
253 $rel= new Relationship();
254 $rel->load_relationship_meta();
257 foreach ($tabs as $tab)
259 //load meta definition of the sub-panel.
260 $thisPanel=$this->subpanel_definitions->load_subpanel($tab);
261 if ($thisPanel === false)
263 //this if-block will try to skip over ophaned subpanels. Studio/MB are being delete unloaded modules completely.
264 //this check will ignore subpanels that are collections (activities, history, etc)
265 if (!isset($thisPanel->_instance_properties['collection_list']) and isset($thisPanel->_instance_properties['get_subpanel_data']) ) {
266 //ignore when data source is a function
268 if (!isset($this->focus->field_defs[$thisPanel->_instance_properties['get_subpanel_data']])) {
269 if (stripos($thisPanel->_instance_properties['get_subpanel_data'],'function:') === false) {
270 $GLOBALS['log']->fatal("Bad subpanel definition, it has incorrect value for get_subpanel_data property " .$tab);
275 if (isset($this->focus->field_defs[$thisPanel->_instance_properties['get_subpanel_data']]['relationship'])) {
276 $rel_name=$this->focus->field_defs[$thisPanel->_instance_properties['get_subpanel_data']]['relationship'];
279 if (empty($rel_name) or !isset($GLOBALS['relationships'][$rel_name])) {
280 $GLOBALS['log']->fatal("Missing relationship definition " .$rel_name. ". skipping " .$tab ." subpanel");
286 echo '<li class="noBullet" id="whole_subpanel_' . $tab . '">';
289 $div_display = $default_div_display;
290 $cookie_name = $tab . '_v';
292 if(isset($div_cookies[$cookie_name])){
293 $div_display = $div_cookies[$cookie_name];
295 if(!empty($sugar_config['hide_subpanels'])){
296 $div_display = 'none';
298 if($div_display == 'none'){
299 $opp_display = 'inline';
301 $opp_display = 'none';
304 if (!empty($this->layout_def_key) ) {
305 $layout_def_key = $this->layout_def_key;
307 $layout_def_key = '';
310 if (empty($this->show_tabs))
312 $show_icon_html = SugarThemeRegistry::current()->getImage( 'advanced_search', 'alt="' . translate('LBL_SHOW') . '" border="0 align="absmiddle""');
313 $hide_icon_html = SugarThemeRegistry::current()->getImage( 'basic_search', 'alt="' . translate('LBL_HIDE') . '" border="0" align="absmiddle"');
314 $max_min = "<a name=\"$tab\"> </a><span id=\"show_link_".$tab."\" style=\"display: $opp_display\"><a href='#' class='utilsLink' onclick=\"current_child_field = '".$tab."';showSubPanel('".$tab."',null,null,'".$layout_def_key."');document.getElementById('show_link_".$tab."').style.display='none';document.getElementById('hide_link_".$tab."').style.display='';return false;\">"
315 . "" . $show_icon_html . "</a></span>";
316 $max_min .= "<span id=\"hide_link_".$tab."\" style=\"display: $div_display\"><a href='#' class='utilsLink' onclick=\"hideSubPanel('".$tab."');document.getElementById('hide_link_".$tab."').style.display='none';document.getElementById('show_link_".$tab."').style.display='';return false;\">"
317 . "" . $hide_icon_html . "</a></span>";
318 echo '<div id="subpanel_title_' . $tab . '"';
319 if(empty($sugar_config['lock_subpanels']) || $sugar_config['lock_subpanels'] == false) echo ' onmouseover="this.style.cursor = \'move\';"';
320 echo '>' . get_form_header( $thisPanel->get_title(), $max_min, false) . '</div>';
324 <div cookie_name="$cookie_name" id="subpanel_$tab" style="display:$div_display">
325 <script>document.getElementById("subpanel_$tab" ).cookie_name="$cookie_name";</script>
328 if($div_display != 'none'){
329 echo "<script>markSubPanelLoaded('$tab');</script>";
330 $old_contents = ob_get_contents();
334 include_once('include/SubPanel/SubPanel.php');
335 $subpanel_object = new SubPanel($this->module, $_REQUEST['record'], $tab,$thisPanel,$layout_def_key);
336 $subpanel_object->setTemplateFile('include/SubPanel/SubPanelDynamic.html');
337 $subpanel_object->display();
338 $subpanel_data = ob_get_contents();
342 echo $this->get_buttons($thisPanel,$subpanel_object->subpanel_query);
343 $buttons = ob_get_contents();
349 $display_spd = $subpanel_data;
352 <div id="list_subpanel_$tab">$display_spd</div>
355 array_push($tab_names, $tab);
357 } // end $tabs foreach
363 if(!empty($selected_group))
365 // closing table from tpls/singletabmenu.tpl
366 echo '</td></tr></table>';
370 $tab_names = '["' . join($tab_names, '","') . '"]';
371 global $sugar_config;
373 if(empty($sugar_config['lock_subpanels']) || $sugar_config['lock_subpanels'] == false) {
376 var SubpanelInit = function() {
377 SubpanelInitTabNames({$tab_names});
379 var SubpanelInitTabNames = function(tabNames) {
380 subpanel_dd = new Array();
383 subpanel_dd[j] = new ygDDList('whole_subpanel_' + tabNames[i]);
384 subpanel_dd[j].setHandleElId('subpanel_title_' + tabNames[i]);
385 subpanel_dd[j].onMouseDown = SUGAR.subpanelUtils.onDrag;
386 subpanel_dd[j].afterEndDrag = SUGAR.subpanelUtils.onDrop;
390 YAHOO.util.DDM.mode = 1;
392 currentModule = '{$this->module}';
393 YAHOO.util.Event.addListener(window, 'load', SubpanelInit);
398 $ob_contents = ob_get_contents();
404 function getLayoutManager()
406 require_once('include/generic/LayoutManager.php');
407 if ( $this->layout_manager == null) {
408 $this->layout_manager = new LayoutManager();
410 return $this->layout_manager;
413 function get_buttons($thisPanel,$panel_query=null)
415 $subpanel_def = $thisPanel->get_buttons();
416 $layout_manager = $this->getLayoutManager();
417 $widget_contents = '<span><table cellpadding="0" cellspacing="0"><tr>';
418 foreach($subpanel_def as $widget_data)
420 $widget_data['query']=urlencode($panel_query);
421 $widget_data['action'] = $_REQUEST['action'];
422 $widget_data['module'] = $thisPanel->get_inst_prop_value('module');
423 $widget_data['focus'] = $this->focus;
424 $widget_data['subpanel_definition'] = $thisPanel;
425 $widget_contents .= '<td class="buttons">' . "\n";
427 if(empty($widget_data['widget_class']))
429 $widget_contents .= "widget_class not defined for top subpanel buttons";
433 $widget_contents .= $layout_manager->widgetDisplay($widget_data);
436 $widget_contents .= '</td>';
439 $widget_contents .= '</tr></table></span>';
440 return $widget_contents;