]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Smarty/plugins/function.sugar_action_menu.php
Release 6.5.0
[Github/sugarcrm.git] / include / Smarty / plugins / function.sugar_action_menu.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  * Smarty plugin
40  * @package Smarty
41  * @subpackage plugins
42  */
43
44 /**
45  * Smarty plugin:
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.
48  *
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
54  * @param $smarty
55  *
56  * @return string - compatible sugarActionMenu structure, such as
57  * <ul>
58  *     <li>html_element1
59  *         <ul>
60  *              <li>html_element2</li>
61  *                  ...
62  *              </li>html_element_n</li>
63  *         </ul>
64  *     </li>
65  * </ul>
66  * ,which is generated by @see function smarty_function_sugar_menu
67  *
68  * <pre>
69  * 1. SugarButton on smarty
70  *
71  * add appendTo to generate button lists
72  * {{sugar_button ... appendTo='buttons'}}
73  *
74  * ,and then create menu
75  * {{sugar_action_menu ... buttons=$buttons ...}}
76  *
77  * 2. Code generate in PHP
78  * <?php
79  * ...
80  *
81  * $buttons = array(
82  *      '<input ...',
83  *      '<a href ...',
84  *      ...
85  * );
86  * require_once('include/Smarty/plugins/function.sugar_action_menu.php');
87  * $action_button = smarty_function_sugar_action_menu(array(
88  *     'id' => ...,
89  *     'buttons' => $buttons,
90  *     ...
91  * ),$xtpl);
92  * $template->assign("ACTION_BUTTON", $action_button);
93  * ?>
94  * 3. Passing array to smarty in PHP
95  * $action_button = array(
96  *      'id' => 'id',
97  *      'buttons' => array(
98  *          '<input ...',
99  *          '<a href ...',
100  *          ...
101  *      ),
102  *      ...
103  * );
104  * $tpl->assign('action_button', $action_button);
105  * in the template file
106  * {sugar_action_menu params=$action_button}
107  *
108  * 4. Append button element in the Smarty
109  * {php}
110  * $this->append('buttons', "<a ...");
111  * $this->append('buttons', "<input ...");
112  * {/php}
113  * {{sugar_action_menu ... buttons=$buttons ...}}
114  * </pre>
115  *
116  * @author Justin Park (jpark@sugarcrm.com)
117  */
118 function smarty_function_sugar_action_menu($params, &$smarty)
119 {
120     $flat = !empty($params['flat']) ? $params['flat'] : false;
121
122     if( !empty($params['params']) ) {
123         $addition_params = $params['params'];
124         unset($params['params']);
125         $params = array_merge_recursive($params, $addition_params);
126     }
127     //if buttons have not implemented, it returns empty string;
128     if(empty($params['buttons']))
129         return '';
130
131     if(is_array($params['buttons']) && !$flat) {
132
133         $menus = array(
134             'html' => array_shift($params['buttons']),
135             'items' => array()
136         );
137
138         foreach($params['buttons'] as $item) {
139             if(strlen($item)) {
140                 array_push($menus['items'],array(
141                    'html' => $item
142                ));
143             }
144         }
145         $action_menu = array(
146             'id' => !empty($params['id']) ? (is_array($params['id']) ? $params['id'][0] : $params['id']) : '',
147             'htmlOptions' => array(
148                 'class' => !empty($params['class']) && strpos($params['class'], 'clickMenu') !== false  ? $params['class'] : 'clickMenu '. (!empty($params['class']) ? $params['class'] : ''),
149                 'name' => !empty($params['name']) ? $params['name'] : '',
150             ),
151             'itemOptions' => array(
152                 'class' => (count($menus['items']) == 0) ? 'single' : 'sugar_action_button'
153             ),
154             'submenuHtmlOptions' => array(
155                 'class' => 'subnav'
156             ),
157             'items' => array(
158                 $menus
159             )
160         );
161         require_once('function.sugar_menu.php');
162         return smarty_function_sugar_menu($action_menu, $smarty);
163
164     }
165
166     if (is_array($params['buttons'])) {
167         return '<div class="action_buttons">' . implode(' ', $params['buttons']).'</div>';
168     } else if(is_array($params)) {
169         return '<div class="action_buttons">' . implode(' ', $params).'</div>';
170     }
171
172     return $params['buttons'];
173 }
174
175 ?>