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.
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 ********************************************************************************/
46 * This is a Smarty plugin to handle the creation of HTML List elements for Sugar Action Menus.
47 * Based on the theme, the plugin generates a proper group of button lists.
49 * @param $params array - its structure is
50 * 'buttons' => list of button htmls, such as ( html_element1, html_element2, ..., html_element_n),
51 * 'id' => id property for ul element
52 * 'class' => class property for ul element
55 * @return string - compatible sugarActionMenu structure, such as
59 * <li>html_element2</li>
61 * </li>html_element_n</li>
65 * ,which is generated by @see function smarty_function_sugar_menu
68 * 1. SugarButton on smarty
70 * add appendTo to generate button lists
71 * {{sugar_button ... appendTo='buttons'}}
73 * ,and then create menu
74 * {{sugar_action_menu ... buttons=$buttons ...}}
76 * 2. Code generate in PHP
85 * require_once('include/Smarty/plugins/function.sugar_action_menu.php');
86 * $action_button = smarty_function_sugar_action_menu(array(
88 * 'buttons' => $buttons,
91 * $template->assign("ACTION_BUTTON", $action_button);
93 * 3. Passing array to smarty in PHP
94 * $action_button = array(
103 * $tpl->assign('action_button', $action_button);
104 * in the template file
105 * {sugar_action_menu params=$action_button}
107 * 4. Append button element in the Smarty
109 * $this->append('buttons', "<a ...");
110 * $this->append('buttons', "<input ...");
112 * {{sugar_action_menu ... buttons=$buttons ...}}
115 * @author Justin Park (jpark@sugarcrm.com)
117 function smarty_function_sugar_action_menu($params, &$smarty)
119 $theme = !empty($params['theme']) ? $params['theme'] : SugarThemeRegistry::current()->name;
121 if( !empty($params['params']) ) {
122 $addition_params = $params['params'];
123 unset($params['params']);
124 $params = array_merge_recursive($params, $addition_params);
126 //if buttons have not implemented, it returns empty string;
127 if(empty($params['buttons']))
130 if(is_array($params['buttons']) && $theme != 'Classic') {
133 'html' => array_shift($params['buttons']),
137 foreach($params['buttons'] as $item) {
139 array_push($menus['items'],array(
144 $action_menu = array(
145 'id' => !empty($params['id']) ? (is_array($params['id']) ? $params['id'][0] : $params['id']) : '',
146 'htmlOptions' => array(
147 'class' => !empty($params['class']) && strpos($params['class'], 'clickMenu') !== false ? $params['class'] : 'clickMenu '. (!empty($params['class']) ? $params['class'] : ''),
148 'name' => !empty($params['name']) ? $params['name'] : '',
150 'itemOptions' => array(
151 'class' => (count($menus['items']) == 0) ? 'single' : 'sugar_action_button'
153 'submenuHtmlOptions' => array(
160 require_once('function.sugar_menu.php');
161 return smarty_function_sugar_menu($action_menu, $smarty);
165 if (is_array($params['buttons'])) {
166 return '<div class="action_buttons">' . implode(' ', $params['buttons']).'</div>';
167 } else if(is_array($params)) {
168 return '<div class="action_buttons">' . implode(' ', $params).'</div>';
171 return $params['buttons'];