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