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-2013 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
53 * 'flat' => controls the display of the menu as a dropdown or flat buttons (if the value is assigned, it will be not affected by enable_action_menu setting.)
56 * @return string - compatible sugarActionMenu structure, such as
60 * <li>html_element2</li>
62 * </li>html_element_n</li>
66 * ,which is generated by @see function smarty_function_sugar_menu
69 * 1. SugarButton on smarty
71 * add appendTo to generate button lists
72 * {{sugar_button ... appendTo='buttons'}}
74 * ,and then create menu
75 * {{sugar_action_menu ... buttons=$buttons ...}}
77 * 2. Code generate in PHP
86 * require_once('include/Smarty/plugins/function.sugar_action_menu.php');
87 * $action_button = smarty_function_sugar_action_menu(array(
89 * 'buttons' => $buttons,
92 * $template->assign("ACTION_BUTTON", $action_button);
94 * 3. Passing array to smarty in PHP
95 * $action_button = array(
104 * $tpl->assign('action_button', $action_button);
105 * in the template file
106 * {sugar_action_menu params=$action_button}
108 * 4. Append button element in the Smarty
110 * $this->append('buttons', "<a ...");
111 * $this->append('buttons', "<input ...");
113 * {{sugar_action_menu ... buttons=$buttons ...}}
116 * @author Justin Park (jpark@sugarcrm.com)
118 function smarty_function_sugar_action_menu($params, &$smarty)
120 global $sugar_config;
122 if( !empty($params['params']) ) {
123 $addition_params = $params['params'];
124 unset($params['params']);
125 $params = array_merge_recursive($params, $addition_params);
127 $flat = isset($params['flat']) ? $params['flat'] : (isset($sugar_config['enable_action_menu']) ? !$sugar_config['enable_action_menu'] : false);
128 //if buttons have not implemented, it returns empty string;
129 if(empty($params['buttons']))
132 if(is_array($params['buttons']) && !$flat) {
135 'html' => array_shift($params['buttons']),
139 foreach($params['buttons'] as $item) {
140 if(is_array($item)) {
142 $sub_first = array_shift($item);
143 foreach($item as $subitem) {
148 array_push($menus['items'],array(
149 'html' => $sub_first,
151 'submenuHtmlOptions' => array(
152 'class' => 'subnav-sub'
155 } else if(strlen($item)) {
156 array_push($menus['items'],array(
161 $action_menu = array(
162 'id' => !empty($params['id']) ? (is_array($params['id']) ? $params['id'][0] : $params['id']) : '',
163 'htmlOptions' => array(
164 'class' => !empty($params['class']) && strpos($params['class'], 'clickMenu') !== false ? $params['class'] : 'clickMenu '. (!empty($params['class']) ? $params['class'] : ''),
166 'itemOptions' => array(
167 'class' => (count($menus['items']) == 0) ? 'single' : 'sugar_action_button'
169 'submenuHtmlOptions' => array(
177 if (!empty($params['name'])) {
178 $action_menu['htmlOptions']['name'] = $params['name'];
181 require_once('function.sugar_menu.php');
182 return smarty_function_sugar_menu($action_menu, $smarty);
186 if (is_array($params['buttons'])) {
187 return '<div class="action_buttons">' . implode_r(' ', $params['buttons'], true).'<div class="clear"></div></div>';
188 } else if(is_array($params)) {
189 return '<div class="action_buttons">' . implode_r(' ', $params, true).'<div class="clear"></div></div>';
192 return $params['buttons'];
195 function implode_r($glue, $pieces, $extract_first_item = false) {
196 $result = array_shift($pieces);
197 if(is_array($result)) {
198 $result = implode_r($glue, $result);
200 foreach($pieces as $item) {
201 if(is_array($item)) {
202 $result .= empty($extract_first_item) ? implode_r($glue, $item) : $glue.$item[0];
204 $result .= $glue.$item;