function.sugar_button.php ➔ smarty_function_sugar_button()   F
last analyzed

Complexity

Conditions 41
Paths 976

Size

Total Lines 204
Code Lines 133

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 60
CRAP Score 292.9658
Metric Value
cc 41
eloc 133
nc 976
nop 2
dl 0
loc 204
ccs 60
cts 128
cp 0.4688
crap 292.9658
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
5
Modification information for LGPL compliance
6
7
r51275 - 2011-03-15 - jpark - Author: Justin Park<[email protected]>
8
    #51275: Add appendTo on sugarbutton to keep the list of buttons to generate rendering list
9
10
r58076 - 2010-09-03 10:29:58 -0700 (Fri, 03 Sep 2010) - kjing - Author: Rob Aagaard <[email protected]>
11
    #39462: Fix the Shortcut bar quick create full form button to cancel the confirm navigation alert for that form.
12
13
r57805 - 2010-08-18 16:11:22 -0700 (Wed, 18 Aug 2010) - kjing - Author: Rob Aagaard <[email protected]>
14
    #39053: Make the full form page take away the navigation javascript warning, because the changes you are making will be saved, eventually, probably.
15
16
r57528 - 2010-07-18 18:37:50 -0700 (Sun, 18 Jul 2010) - kjing - Author: Collin Lee <[email protected]>
17
    Bug: 38576
18
19
r57526 - 2010-07-16 18:11:54 -0700 (Fri, 16 Jul 2010) - kjing - Author: Stanislav Malyshev <[email protected]>
20
    add associated contacts to the email subpanel
21
22
r57466 - 2010-07-14 17:38:01 -0700 (Wed, 14 Jul 2010) - kjing - Author: [email protected] <dwheeler@dwheeler-laptop>
23
    19329: Switched to multiselect for project, product, and quote subpanels.
24
25
r57465 - 2010-07-14 16:03:31 -0700 (Wed, 14 Jul 2010) - kjing - Author: Stanislav Malyshev <[email protected]>
26
    fix configurations & statuses
27
28
r57448 - 2010-07-13 14:34:07 -0700 (Tue, 13 Jul 2010) - kjing - Merge: bc3e0ee 7ac4a5f
29
Author: [email protected] <dwheeler@dwheeler-laptop.(none)>
30
    Merge branch 'master' of git+ssh://github.com/sugarcrm/Mango
31
32
r57317 - 2010-07-08 07:01:39 -0700 (Thu, 08 Jul 2010) - kjing - Author: Rob Aagaard <[email protected]>
33
    Bug 19355: Handle the cancel button correctly when you are editing from a list
34
35
r57069 - 2010-06-23 10:54:44 -0700 (Wed, 23 Jun 2010) - kjing - commit f24f316cc907d70c44e8add4d1b55bb692c177f5
36
Author: [email protected] <dwheeler@dwheeler-laptop.(none)>
37
    35744
38
39
r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
40
41
r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
42
43
r56510 - 2010-05-17 11:54:49 -0700 (Mon, 17 May 2010) - jenny - Merging with Windex 56356:56506.
44
45
r56459 - 2010-05-13 18:35:31 -0700 (Thu, 13 May 2010) - smalyshev - #37332
46
fix cancel button - do not submit form with all the data
47
48
r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
49
50
r55979 - 2010-04-19 13:15:20 -0700 (Mon, 19 Apr 2010) - jmertic - Bug 36062 - Fixed 'Cancel' button code for DC Menu quick creates.
51
52
r55022 - 2010-03-02 09:14:24 -0800 (Tue, 02 Mar 2010) - clee - Bug:36066
53
We are setting a new target when a form is invoked.  This opens up a new window/tab.  I've changed the full form functionality to not open a new window/tab.
54
Modified:
55
include/Smarty/plugins/function.sugar_button.php
56
57
r54870 - 2010-02-24 07:41:23 -0800 (Wed, 24 Feb 2010) - roger - bug: 35958 - make the quick create save button blue.
58
59
r54023 - 2010-01-25 21:48:12 -0800 (Mon, 25 Jan 2010) - lam - added primary button class
60
61
r53522 - 2010-01-07 10:40:50 -0800 (Thu, 07 Jan 2010) - jmertic - Bug 34868 - Make sure clicking on the 'Edit' button on a DetailView actually goes to the EditView.
62
63
r53119 - 2009-12-09 19:23:33 -0800 (Wed, 09 Dec 2009) - mitani - fixes tags for xtemplate
64
65
r53116 - 2009-12-09 17:24:37 -0800 (Wed, 09 Dec 2009) - mitani - Merge Kobe into Windex Revision 51633 to 53087
66
67
r52448 - 2009-11-13 02:21:35 -0800 (Fri, 13 Nov 2009) - mitani - Fixes issues with quick create buttons, removes buttons from the top of the quick create form for productivity bar, aligns navigation buttons with other buttons on detail and edit views fixes an issue with calls edit view still calling on leads
68
69
r52277 - 2009-11-06 12:41:42 -0800 (Fri, 06 Nov 2009) - mitani - Updates the Productivity Bar  UI and adds Spot :)
70
71
r52120 - 2009-11-02 14:45:24 -0800 (Mon, 02 Nov 2009) - clee - Fixed errors with default connector buttons/hover buttons not appearing in default install for sales edition.
72
73
r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system
74
75
r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
76
77
r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
78
79
r48227 - 2009-06-08 14:59:16 -0700 (Mon, 08 Jun 2009) - tyoung - 23828: replaced the PHP mechanism to calculate the subpanel name based on the module name, which failed as a result of the switch from module-based subpanel names to relationship-based names, which a javascript mechanism embedded in the two affected methods in SubpanelUtils - inlineSave() and cancelCreate().
80
The new mechanism works out from the save or cancel button, respectively, until it encounters a subpanel (marked by a new CSS class 'quickcreate'). It then uses that subpanel name in later operations. This mechanism is now reliable for relationship-based subpanel names. Furthermore, it does not require modifications to the method-chain. To fix this issue by passing the subpanel name along the method-chain would require changing the method signature of the smarty method, sugar_button, which would be very broad-ranging.
81
82
r45148 - 2009-03-16 07:43:29 -0700 (Mon, 16 Mar 2009) - clee - Bug:28522
83
There were several issues with the code to select teams as well as the quicksearch code.  The main issues for the teams selection was that the fields all share the same name and the elements were not being properly selected within the javascript code.
84
include/EditView/EditView2.php
85
include/generic/SugarWidgets/SugarWidgetSubpanelTopButtonQuickCreate.php
86
include/generic/SugarWidgets/SugarWidgetSubpanelTopCreateNoteButton.php
87
include/generic/SugarWidgets/SugarWidgetSubpanelTopCreateTaskButton.php
88
include/generic/SugarWidgets/SugarWidgetSubpanelTopScheduleCallButton.php
89
include/generic/SugarWidgets/SugarWidgetSubpanelTopScheduleMeetingButton.php
90
include/javascript/sugar_3.js
91
include/SearchForm/tpls/header.tpl
92
include/Smarty/plugins/function.sugar_button.php
93
include/Smarty/plugins/function.sugarvar_teamset.php
94
include/SugarFields/Fields/Collection/ViewSugarFieldCollection.php
95
include/SugarFields/Fields/Collection/CollectionEditView.tpl
96
include/SugarFields/Fields/Collection/SugarFieldCollection.js
97
include/SugarFields/Fields/Teamset/SugarFieldTeamset.php
98
include/SugarFields/Fields/Teamset/ViewSugarFieldTeamsetCollection.php
99
include/SugarFields/Fields/Teamset/Teamset.js
100
include/SugarFields/Fields/Teamset/TeamsetCollectionEditView.tpl
101
include/SugarFields/Fields/TeamsetCollectionMassupdateView.tpl
102
include/SugarFields/Fields/Teamset/TeamsetCollectionSearchView.tpl
103
include/TemplateHandler/TemplateHandler.php
104
modules/Teams/TeamSetManager.php
105
themes/default/IE7.js
106
Removed:
107
include/SugarFields/Fields/Teamset/TeamsetCollectionQuickCreateView.tpl
108
109
r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
110
111
r42645 - 2008-12-18 13:41:08 -0800 (Thu, 18 Dec 2008) - awu - merging maint_5_2_0 rev41336:HEAD to trunk
112
113
r41336 - 2008-11-04 15:00:45 -0800 (Tue, 04 Nov 2008) - awu - merging Milan code into Tokyo (trunk)
114
115
r39146 - 2008-08-26 17:16:04 -0700 (Tue, 26 Aug 2008) - awu - Merging pre_5_1_0 to trunk
116
117
r38393 - 2008-07-29 12:44:00 -0700 (Tue, 29 Jul 2008) - Collin Lee - Bug:23873
118
Spoke with Ran more about this issue. It turns out the "Select" button was not the only button that needed to have a unique id. All subpanel and subpanel quick create buttons where no unique id exists for the element are candidates for change. Modified sugar widget subpanel classes to use a unique id for "Create" and "Select" buttons. Modified function.sugar_button.php to uniquely identify subpanel buttons as well.
119
120
r37505 - 2008-07-02 10:12:55 -0700 (Wed, 02 Jul 2008) - roger - bug: 23283 - buttons in EditView were grouped together without spacing.
121
122
r32531 - 2008-03-06 19:04:15 -0800 (Thu, 06 Mar 2008) - jmertic - Bug 19305: Reverted fix in include/formbase.php. Instead check for isDuplicate being set to true and if so, clear the return_id form variable on save.
123
Touched:
124
- modules/Tasks/Save.php
125
- modules/Leads/LeadFormBase.php
126
- modules/Documents/Save.php
127
- modules/Campaigns/Save.php
128
- modules/Emails/Save.php
129
- modules/KBDocuments/Save.php
130
- modules/Accounts/AccountFormBase.php
131
- modules/Meetings/MeetingFormBase.php
132
- modules/DocumentRevisions/Save.php
133
- modules/Prospects/ProspectFormBase.php
134
- modules/Opportunities/OpportunityFormBase.php
135
- modules/Notes/NoteFormBase.php
136
- modules/Calls/CallFormBase.php
137
- modules/Holidays/Save.php
138
- modules/Quotes/Save.php
139
- modules/Quotes/QuoteFormBase.php
140
- modules/Contracts/Save.php
141
- modules/EmailTemplates/EmailTemplateFormBase.php
142
- modules/Project/Save.php
143
- modules/Contacts/ContactFormBase.php
144
- modules/ProspectLists/ProspectListFormBase.php
145
- include/formbase.php
146
- include/Smarty/plugins/function.sugar_button.php
147
- include/EditView/EditView2.php
148
149
r30452 - 2007-12-14 13:28:17 -0800 (Fri, 14 Dec 2007) - clee - Fix for 18019
150
Need to add code to set the return_id value in include/Smarty/plugins/function.sugar_button.php when clicking on the Duplicate button so that this value is passed into the EditView and a cancel operation can return the user to the previous screen correctly.
151
Modified:
152
include/Smarty/plugins/function.sugar_button.php
153
154
r29427 - 2007-11-09 09:24:11 -0800 (Fri, 09 Nov 2007) - clee - Fix for 17450
155
Need extra check for cancel from shortcut menu where action is set, but no return_id or id value exists.
156
157
r29426 - 2007-11-09 08:54:58 -0800 (Fri, 09 Nov 2007) - clee - Fix for 17450
158
The subpanel quick creates full form button generated was not setting a return_action value.  As a result, it defaulted to the previous action ("SubPanelViewer").  Upon cancel, the MVC attempted to run the action for which there was no record.
159
Modified:
160
include/Smarty/plugins/function.sugar_button.php
161
Code Review: Roger
162
163
r28804 - 2007-10-24 09:14:09 -0700 (Wed, 24 Oct 2007) - clee - Fix for 16894
164
Modified function.sugar_button.php to make extra checks to see if the return action is set to DetailView, that a valid id value is set.  Otherwise, there's no way to pull up the DetailView contents.
165
Modified:
166
include/Smarty/plugins/function.sugar_button.php
167
Code Review by Roger.
168
169
r28777 - 2007-10-23 17:33:25 -0700 (Tue, 23 Oct 2007) - bsoufflet - bug 16861
170
171
r28771 - 2007-10-23 17:23:13 -0700 (Tue, 23 Oct 2007) - clee - Fix for 16740
172
Fixed include/Smarty/plugins/function.sugar_button.php file.   The button for Audit log was being created with the $_REQUEST id.  However, this value was built for the first request so subsequent requests to view the Audit log would always go back to the id built in the cached .tpl file.  Modified to use {$fields.id.value} instead.
173
Modified:
174
Fixed include/Smarty/plugins/function.sugar_button.php
175
176
r28643 - 2007-10-22 13:58:23 -0700 (Mon, 22 Oct 2007) - majed - bug #16757
177
fixes duplicate so it returns to the detail view of the new record instead of the index page
178
179
r28573 - 2007-10-21 01:24:14 -0700 (Sun, 21 Oct 2007) - majed - adds support for metadata driven quick creates and adds the ability to create from subpanels for any module
180
bug # 16541
181
182
r28324 - 2007-10-17 16:24:57 -0700 (Wed, 17 Oct 2007) - majed - bug #13311 fixes delete button showing up when it shouldn't in most scenarios some places the button may be disabled instead of disappearing and in worst case it should display you do not have access if you don't
183
184
r28178 - 2007-10-15 16:56:47 -0700 (Mon, 15 Oct 2007) - majed - Checkin to add first side quick create for meta data driven ui.
185
186
r25427 - 2007-08-11 13:52:09 -0700 (Sat, 11 Aug 2007) - clee - Added empty id check so we do not show the audit button when creating a new record.
187
188
r25408 - 2007-08-10 18:12:47 -0700 (Fri, 10 Aug 2007) - clee - Fix for 14268.  Removed the audit link from the VCR Control row and moved to the DetailView/EdtiView header.tpl files.  The link is shown for all modules IF the SugarBean's isAuditEnabled value is set to true.
189
Updated files:
190
include/DetailView/header.tpl
191
include/EditView/EditView2.php
192
include/EditView/header.tpl
193
include/EditView/SugarVCR.php
194
include/Smarty/plugins/function.sugar_button.php
195
include/SugarFields/Parsers/MetaParser.php
196
197
r24941 - 2007-08-01 12:53:34 -0700 (Wed, 01 Aug 2007) - roger - RRS: bug 13806. Set the return_action to DetailView for the Edit button.
198
199
r24531 - 2007-07-23 01:25:31 -0700 (Mon, 23 Jul 2007) - clee - Fix for 13778.  Changed include/Smarty/plugins/function.sugar_button.php so that FIND_DUPLICATE button will set return_action to "DetailView" (used only in Contacts and Accounts DetailView Meta-data files).
200
201
r24352 - 2007-07-16 10:56:01 -0700 (Mon, 16 Jul 2007) - roger - RRS: bug 13627.
202
203
r24254 - 2007-07-12 16:17:11 -0700 (Thu, 12 Jul 2007) - clee - Fixed CANCEL button to return to DetailView always.
204
205
r24108 - 2007-07-08 01:05:03 -0700 (Sun, 08 Jul 2007) - clee - Changed to set check_form parameter to EditView if action is EditView.
206
207
r23512 - 2007-06-08 17:13:38 -0700 (Fri, 08 Jun 2007) - clee - Determine DetailView.php or index.php action based on presence of id.
208
209
r23011 - 2007-05-22 21:51:24 -0700 (Tue, 22 May 2007) - clee - Merging latest changes.
210
211
r22641 - 2007-05-10 01:38:12 -0700 (Thu, 10 May 2007) - clee - Change action to ListView for DELETE button.
212
213
r22640 - 2007-05-10 01:34:59 -0700 (Thu, 10 May 2007) - clee - For EditView's, default back to DetailView for CANCEL and SAVE buttons.
214
215
r22638 - 2007-05-10 01:22:32 -0700 (Thu, 10 May 2007) - clee - Changed FIND_DUPLICATE to FIND_DUPLICATES
216
217
r22618 - 2007-05-09 15:36:06 -0700 (Wed, 09 May 2007) - clee - Added file.
218
219
220
*/
221
222
223
/**
224
 * Smarty plugin
225
 * @package Smarty
226
 * @subpackage plugins
227
 *
228
 * This is a Smarty plugin to handle the creation of HTML form buttons under the
229
 * metat-data framework.  The buttons may be defined using either the set of built-in
230
 * buttons or custom code.
231
 *
232
 * For example, to add the 'SAVE' and 'CANCEL' buttons to the editviewdefs.php meta-data file,
233
 * you will create a key/value pair where the key is of value 'form' and value is another array
234
 * with a 'buttons' key.
235
 *
236
 * ...
237
 * $viewdefs['Accounts']['EditView'] = array(
238
 * 'templateMeta' => array(
239
 *                           'form' => array('buttons'=>array('SAVE','CANCEL')),
240
 * ...
241
 *
242
 * The supported types are: CANCEL, DELETE, DUPLICATE, EDIT, FIND_DUPLICATES and SAVE.
243
 * If you need to create a custom button or the button is very specific to the module and not
244
 * provided as a supported type, then you'll need to use custom code.  Instead of providing the
245
 * key, you'll have to create an array with a 'customCode' key.
246
 *
247
 * ...
248
 * $viewdefs['Accounts']['EditView'] = array(
249
 * 'templateMeta' => array(
250
 *	'form' => array('buttons'=>array('SAVE',
251
 *	                                 array('customCode'=>'<input title="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" ' .
252
 *	                                 		'                    accessKey="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_KEY}" ' .
253
 *	                                 		'                    class="button" ' .
254
 *	                                 		'					 onclick="alert(\'hello {$id} \')"; ' .
255
 *	                                 		'                    type="submit" ' .
256
 *	                                 		'                    name="button" ' .
257
 *	                                 		'                    value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_LABEL}">')
258
 *	                                 )),
259
 * ...
260
 *
261
 * Please note that you should ensure that your customCode is generic in the sense that there are no
262
 * instance specific values created because it will cause failures should other instances also use
263
 * the button's code.  The key to remember is that we are rendering a generic template for each
264
 * module's view and, as such, the meta-data definition should also be generic enough to support
265
 * variable instance values for the module.
266
 *
267
 * In our examples, the resulting metatdata definition is passed to EditView's header.tpl
268
 * file and the Smarty plugin (this file) is invoked as follows:
269
 * {{sugar_button module='{{$module}}' id='{{$form.buttons[$id]}}' view='EditView'}}
270
 *
271
 *
272
 * @author Collin Lee {[email protected]}
273
 */
274
275
/**
276
 * smarty_function_sugar_button
277
 * This is the constructor for the Smarty plugin.
278
 *
279
 * @param $params The runtime Smarty key/value arguments
280
 * @param $smarty The reference to the Smarty object used in this invocation
281
 */
282 1
function smarty_function_sugar_button($params, &$smarty)
283
{
284 4
   if(empty($params['module'])) {
285 1
   	  $smarty->trigger_error("sugar_button: missing required param (module)");
286 3
   } else if(empty($params['id'])) {
287
   	  $smarty->trigger_error("sugar_button: missing required param (id)");
288 3
   } else if(empty($params['view'])) {
289
   	  $smarty->trigger_error("sugar_button: missing required param (view)");
290
   }
291
292 4
   $js_form = (empty($params['form_id'])) ? "var _form = (this.form) ? this.form : document.forms[0];" : "var _form = document.getElementById('{$params['form_id']}');";
293
294 4
   $type = $params['id'];
295 4
   $location = (empty($params['location'])) ? "" : "_".$params['location'];
296
297 4
   if(!is_array($type)) {
298 4
   	  $module = $params['module'];
299 4
   	  $view = $params['view'];
300 4
   	  switch(strtoupper($type)) {
301 4
			case "SEARCH":
302 2
                $output = '<input tabindex="2" title="{$APP.LBL_SEARCH_BUTTON_TITLE}" onclick="SUGAR.savedViews.setChooser();" class="button" type="submit" name="button" value="{$APP.LBL_SEARCH_BUTTON_LABEL}" id="search_form_submit"/>&nbsp;';
303 2
			break;
304
305 2
			case "CANCEL":
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
306
307
                //If the return action is not empty and the return action is detail view and the id is not empty
308
                $cancelButton  = '{if !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && !empty($smarty.request.return_id))}';
309
                $cancelButton .= '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="SUGAR.ajaxUI.loadContent(\'index.php?action=DetailView&module={$smarty.request.return_module|escape:"url"}&record={$smarty.request.return_id|escape:"url"}\'); return false;" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" type="button" id="'.$type.$location.'"> ';
310
311
                //If the return action is not empty and the return action is detail view and the id (from fields) is not empty
312
                $cancelButton .= '{elseif !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && !empty($fields.id.value))}';
313
                $cancelButton .= '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="SUGAR.ajaxUI.loadContent(\'index.php?action=DetailView&module={$smarty.request.return_module|escape:"url"}&record={$fields.id.value}\'); return false;" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="'.$type.$location.'"> ';
314
315
                //Bug 1057 If the return action is not empty and the return action is detail view and the id (from both locations) are empty, go to the modules listview
316
                $cancelButton .= '{elseif !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && empty($fields.id.value)) && empty($smarty.request.return_id)}';
317
                $cancelButton .= '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="SUGAR.ajaxUI.loadContent(\'index.php?action=ListView&module={$smarty.request.return_module|escape:"url"}&record={$fields.id.value}\'); return false;" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="'.$type.$location.'"> ';
318
319
320
                //Bug 893 if the return action is not empty and the return module is not empty, go back to that page
321
                $cancelButton .= '{elseif !empty($smarty.request.return_action) && !empty($smarty.request.return_module)}';
322
                $cancelButton .= '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="SUGAR.ajaxUI.loadContent(\'index.php?action={$smarty.request.return_action}&module={$smarty.request.return_module|escape:"url"}\'); return false;" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="'.$type.$location.'"> ';
323
324
                //If the return action is empty but the return id is in fields
325
                $cancelButton .= '{elseif empty($smarty.request.return_action) || empty($smarty.request.return_id) && !empty($fields.id.value)}';
326
                $cancelButton .= '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="SUGAR.ajaxUI.loadContent(\'index.php?action=index&module='.$module.'\'); return false;" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="'.$type.$location.'"> ';
327
328
329
330
                $cancelButton .= '{else}';
331
                $cancelButton .= '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="SUGAR.ajaxUI.loadContent(\'index.php?action=index&module={$smarty.request.return_module|escape:"url"}&record={$smarty.request.return_id|escape:"url"}\'); return false;" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="'.$type.$location.'"> ';
332
                $cancelButton .= '{/if}';
333
334
335
                //$cancelButton = '{$smarty.request.return_action}'.'{$smarty.request.return_module}';
336
337
338
                $output = $cancelButton;
339
			break;
340
341 2
			case "DELETE":
342
                $output = '{if $bean->aclAccess("delete")}<input title="{$APP.LBL_DELETE_BUTTON_TITLE}" accessKey="{$APP.LBL_DELETE_BUTTON_KEY}" class="button" onclick="'.$js_form.' _form.return_module.value=\'' . $module . '\'; _form.return_action.value=\'ListView\'; _form.action.value=\'Delete\'; if(confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')) SUGAR.ajaxUI.submitForm(_form);" type="submit" name="Delete" value="{$APP.LBL_DELETE_BUTTON_LABEL}" id="delete_button">{/if} ';
343
            break;
344
345 2
			case "DUPLICATE":
346
			    $output = '{if $bean->aclAccess("edit")}<input title="{$APP.LBL_DUPLICATE_BUTTON_TITLE}" accessKey="{$APP.LBL_DUPLICATE_BUTTON_KEY}" class="button" onclick="'.$js_form.' _form.return_module.value=\''. $module . '\'; _form.return_action.value=\'DetailView\'; _form.isDuplicate.value=true; _form.action.value=\'' . $view . '\'; _form.return_id.value=\'{$id}\';SUGAR.ajaxUI.submitForm(_form);" type="button" name="Duplicate" value="{$APP.LBL_DUPLICATE_BUTTON_LABEL}" id="duplicate_button">{/if} ';
347
            break;
348
349 2
			case "EDIT";
350
			    $output = '{if $bean->aclAccess("edit")}<input title="{$APP.LBL_EDIT_BUTTON_TITLE}" accessKey="{$APP.LBL_EDIT_BUTTON_KEY}" class="button primary" onclick="'.$js_form.' _form.return_module.value=\'' . $module . '\'; _form.return_action.value=\'DetailView\'; _form.return_id.value=\'{$id}\'; _form.action.value=\'EditView\';SUGAR.ajaxUI.submitForm(_form);" type="button" name="Edit" id="edit_button" value="{$APP.LBL_EDIT_BUTTON_LABEL}">{/if} ';
351
            break;
352
353 2
			case "FIND_DUPLICATES":
354
			    $output = '{if $bean->aclAccess("edit") && $bean->aclAccess("delete")}<input title="{$APP.LBL_DUP_MERGE}" class="button" onclick="'.$js_form.' _form.return_module.value=\'' . $module . '\'; _form.return_action.value=\'DetailView\'; _form.return_id.value=\'{$id}\'; _form.action.value=\'Step1\'; _form.module.value=\'MergeRecords\';SUGAR.ajaxUI.submitForm(_form);" type="button" name="Merge" value="{$APP.LBL_DUP_MERGE}" id="merge_duplicate_button">{/if} ';
355
            break;
356
357 2
			case "SAVE":
358
				$view = ($_REQUEST['action'] == 'EditView') ? 'EditView' : (($view == 'EditView') ? 'EditView' : $view);
359
				$output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" class="button primary" onclick="'.$js_form.' {if $isDuplicate}_form.return_id.value=\'\'; {/if}_form.action.value=\'Save\'; if(check_form(\'' . $view . '\'))SUGAR.ajaxUI.submitForm(_form);return false;" type="submit" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}" id="'.$type.$location.'">{/if} ';
360
			break;
361
362 2
			case "SUBPANELSAVE":
363
                if($view == 'QuickCreate' || (isset($_REQUEST['target_action']) && strtolower($_REQUEST['target_action']) == 'quickcreate')) $view =  "form_SubpanelQuickCreate_{$module}";
364
365
                /* BEGIN - SECURITY GROUPS - redirect a subpanel save to the detail view if select popup and user in more than 1 group*/ 
366
                /**
367
                global $current_user, $sugar_config;
368
                if(isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true) {     
369
                    require_once('modules/SecurityGroups/SecurityGroup.php');
370
                    $groupFocus = new SecurityGroup();
371
372
                    if($groupFocus->getMembershipCount($current_user->id) > 1) {
373
                        $output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" class="button" onclick="'.$js_form.' disableOnUnloadEditView(); _form.action.value=\'Save\';_form.module.value=\'{$module}\';_form.return_module.value=\'{$module}\';_form.return_action.value=\'DetailView\';_form.return_id.value=\'\';" type="submit" name="' . $params['module'] . '_subpanel_save_button" id="' . $params['module'] . '_subpanel_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
374
                    }
375
                }
376
                //if different here then change the group return right above
377
                $output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}"  class="button" onclick="'.$js_form.' disableOnUnloadEditView(); _form.action.value=\'Save\';if(check_form(\''.$view.'\'))return SUGAR.subpanelUtils.inlineSave(_form.id, \'' . $params['module'] . '_subpanel_save_button\');return false;" type="submit" name="' . $params['module'] . '_subpanel_save_button" id="' . $params['module'] . '_subpanel_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
378
                
379
                */
380
                $output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}"  class="button" onclick="'.$js_form.' disableOnUnloadEditView(); _form.action.value=\'Save\';if(check_form(\''.$view.'\'))return SUGAR.subpanelUtils.inlineSave(_form.id, \'' . $params['module'] . '_subpanel_save_button\');return false;" type="submit" name="' . $params['module'] . '_subpanel_save_button" id="' . $params['module'] . '_subpanel_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
381
                /* END - SECURITY GROUPS */
382
383
            break;
384 2
			case "SUBPANELCANCEL":
385
                $output = '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" class="button" onclick="return SUGAR.subpanelUtils.cancelCreate($(this).attr(\'id\'));return false;" type="submit" name="' . $params['module'] . '_subpanel_cancel_button" id="' . $params['module'] . '_subpanel_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
386
387
            break;
388 2
		    case "SUBPANELFULLFORM":
389
                $output = '<input title="{$APP.LBL_FULL_FORM_BUTTON_TITLE}" class="button" onclick="'.$js_form.' disableOnUnloadEditView(_form); _form.return_action.value=\'DetailView\'; _form.action.value=\'EditView\'; if(typeof(_form.to_pdf)!=\'undefined\') _form.to_pdf.value=\'0\';" type="submit" name="' . $params['module'] . '_subpanel_full_form_button" id="' . $params['module'] . '_subpanel_full_form_button" value="{$APP.LBL_FULL_FORM_BUTTON_LABEL}"> ';
390
                $output .= '<input type="hidden" name="full_form" value="full_form">';
391
            break;
392 2
			case "DCMENUCANCEL":
393 1
                $output = '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="javascript:lastLoadedMenu=undefined;DCMenu.closeOverlay();return false;" type="submit" name="' . $params['module'] . '_dcmenu_cancel_button" id="' . $params['module'] . '_dcmenu_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
394 1
            break;
395 2
			case "DCMENUSAVE":
396 1
                            if ($view == 'QuickCreate') {
397 1
                                $view = "form_DCQuickCreate_{$module}";
398
                            } else if ($view == 'EditView') {
399
                                $view = "form_DCEditView_{$module}";
400
                            }
401 1
				$output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" class="button primary" onclick="'.$js_form.' _form.action.value=\'Save\';if(check_form(\''.$view.'\'))return DCMenu.save(_form.id, \'' . $params['module'] . '_subpanel_save_button\');return false;" type="submit" name="' . $params['module'] . '_dcmenu_save_button" id="' . $params['module'] . '_dcmenu_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
402 1
            break;
403 2
			case "DCMENUFULLFORM":
404 1
                $output = '<input title="{$APP.LBL_FULL_FORM_BUTTON_TITLE}" accessKey="{$APP.LBL_FULL_FORM_BUTTON_KEY}" class="button" onclick="'.$js_form.' disableOnUnloadEditView(_form); _form.return_action.value=\'DetailView\'; _form.action.value=\'EditView\'; _form.return_module.value=\'' . $params['module'] . '\';_form.return_id.value=_form.record.value;if(typeof(_form.to_pdf)!=\'undefined\') _form.to_pdf.value=\'0\';SUGAR.ajaxUI.submitForm(_form,null,true);DCMenu.closeOverlay();" type="button" name="' . $params['module'] . '_subpanel_full_form_button" id="' . $params['module'] . '_subpanel_full_form_button" value="{$APP.LBL_FULL_FORM_BUTTON_LABEL}"> ';
405 1
                $output .= '<input type="hidden" name="full_form" value="full_form">';
406 1
                $output .= '<input type="hidden" name="is_admin" value="">';
407 1
            break;
408 2
			case "POPUPSAVE":
409 1
				$view = ($view == 'QuickCreate') ? "form_QuickCreate_{$module}" : $view;
410
				$output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" '
411 1
					 . 'class="button primary" onclick="'.$js_form.' _form.action.value=\'Popup\';'
412 1
					 . 'return check_form(\''.$view.'\')" type="submit" name="' . $params['module']
413 1
					 . '_popupcreate_save_button" id="' . $params['module']
414 1
					 . '_popupcreate_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
415 1
            break;
416 2
			case "POPUPCANCEL":
417
                $output = '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" '
418
					 . 'class="button" onclick="toggleDisplay(\'addform\');return false;" '
419 1
					 . 'name="' . $params['module'] . '_popup_cancel_button" type="submit"'
420 1
					 . 'id="' . $params['module'] . '_popup_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
421 1
            break;
422 2
			case "AUDIT":
423
	            $popup_request_data = array(
424 2
			        'call_back_function' => 'set_return',
425
			        'form_name' => 'EditView',
426
			        'field_to_name_array' => array(),
427
			    );
428 2
	            $json = getJSONobj();
429
430 2
	            require_once('include/SugarFields/Parsers/MetaParser.php');
431 2
	            $encoded_popup_request_data = MetaParser::parseDelimiters($json->encode($popup_request_data));
432 2
	 			$audit_link = '<input id="btn_view_change_log" title="{$APP.LNK_VIEW_CHANGE_LOG}" class="button" onclick=\'open_popup("Audit", "600", "400", "&record={$fields.id.value}&module_name=' . $params['module'] . '", true, false, ' . $encoded_popup_request_data . '); return false;\' type="button" value="{$APP.LNK_VIEW_CHANGE_LOG}">';
433 2
                $output = '{if $bean->aclAccess("detail")}{if !empty($fields.id.value) && $isAuditEnabled}'.$audit_link.'{/if}{/if}';
434 2
            break;
435
436
437
   	  } //switch
438 4
      if(isset($params['appendTo'])) {
439 2
          $smarty->append($params['appendTo'], $output);
440 2
          return;
441
      }
442 2
      return $output;
443
   } else if(is_array($type) && isset($type['sugar_html'])) {
444
       require_once('include/SugarHtml/SugarHtml.php');
445
446
       $dom_tree = SugarHtml::parseSugarHtml($type['sugar_html']);
447
       replaceFormClick($dom_tree, $js_form);
448
       $output = SugarHtml::createHtml($dom_tree);
449
450
       if(isset($params['appendTo'])) {
451
           $smarty->append($params['appendTo'], $output);
452
           return;
453
       }
454
       return $output;
455
   } else if(is_array($type) && isset($type['customCode'])) {
456
       require_once('include/SugarHtml/SugarHtml.php');
457
458
       $dom_tree = SugarHtml::parseHtmlTag($type['customCode']);
459
       $hidden_exists = false;
460
461
       replaceFormClick($dom_tree, $js_form, $hidden_exists);
462
       if($hidden_exists) {
463
           //If the customCode contains hidden fields, the extracted hidden fields need to append in the original form
464
           $form = $smarty->get_template_vars('form');
465
           $hidden_fields = $dom_tree;
466
           extractHiddenInputs($hidden_fields);
467
           if(!isset($form)) {
468
               $form = array();
469
           }
470
           if(!isset($form['hidden'])) {
471
               $form['hidden'] = array();
472
           }
473
           $form['hidden'][] = SugarHtml::createHtml($hidden_fields);
474
           $smarty->assign('form', $form);
475
       }
476
       $output = SugarHtml::createHtml($dom_tree);
477
478
       if(isset($params['appendTo'])) {
479
           $smarty->append($params['appendTo'], $output);
480
           return;
481
       }
482
       return $output;
483
   }
484
485
}
486
/**
487
 * Bug#51862: Reproduce the JS onclick for upgraded instances
488
 *
489
 * @param array $dom_tree - Cascade array form generated by SugarHtml::parseHtmlTag
490
 * @param string $js_form - JS getter to assign _form object by ID
491
 * @param bool $hidden_field_exists - whether the selected element contains hidden fields or not
492
 * @return array - two boolean variables.
493
 *                 $set_submit - whether the replace operation is excuted or not
494
 *                 $is_hidden_field - where current attributes contains the key "hidden" or not
495
 */
496 1
function replaceFormClick(&$dom_tree = array(), $js_form = '', &$hidden_field_exists = false) {
497
    $set_submit = false;
498
    $is_hidden_field = false;
499
    //if the code is wrapped with the form element, it will escape the operation for JS replacement
500
    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'form')
501
        return false;
502
503
    if(isset($dom_tree['type']) && $dom_tree['type'] == 'hidden') {
504
        $is_hidden_field = true;
505
    }
506
507
    //Replace the JS syntax where the sugar_button contains the event handler for this.form
508
    if(isset($dom_tree['onclick'])) {
509
        if(strpos($dom_tree['onclick'], "this.form") !== false) {
510
            $dom_tree['onclick'] = str_replace("this.form", "_form", $dom_tree['onclick']);
511
            if(substr($dom_tree['onclick'], -1) != ';')
512
                $dom_tree['onclick'] .= ";";
513
            //Onclick handler contains returning a variable, for example it prompts a confirm message.
514
            if(strpos($dom_tree['onclick'], "return ") !== false ) {
515
                $dom_tree['onclick'] = $js_form.' var _onclick=(function(){ldelim}'.$dom_tree['onclick']."{rdelim}()); if(_onclick!==false) _form.submit();";
516
            } else {
517
                $dom_tree['onclick'] = $js_form.$dom_tree['onclick']."_form.submit();";
518
            }
519
520
            $set_submit = true;
521
        }
522
    }
523
    foreach($dom_tree as $key => $sub_tree) {
524
        if(is_array($sub_tree)) {
525
            list($_submit, $_hidden) = replaceFormClick($dom_tree[$key], $js_form, $hidden_field_exists);
526
            $set_submit = ($set_submit) ? $set_submit : $_submit;
527
            $is_hidden_field = ($is_hidden_field) ? $is_hidden_field : $_hidden;
528
        }
529
    }
530
531
    if($set_submit && isset($dom_tree['type'])) {
532
        $dom_tree['type'] = "button";
533
        $set_submit = false;
534
    }
535
    if($is_hidden_field && isset($dom_tree['tag']) && $dom_tree['tag'] == 'input' ) {
536
        $hidden_field_exists = true;
537
        $is_hidden_field = false;
538
    }
539
540
    return array($set_submit, $is_hidden_field);
541
}
542
543
/**
544
 * Bug#51862: Extract hidden field form the original dom structure
545
 * @param array $dom_tree - Cascade array form generated by SugarHtml::parseHtmlTag
546
 */
547 1
function extractHiddenInputs(&$dom_tree = array()) {
548
    $allow_types = array(
549
        'hidden'
550
    );
551
    //all hidden fields in the form elements must NOT attach in the original form
552
    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'form') {
553
        $dom_tree = array();
554
    }
555
    foreach($dom_tree as $key => $sub_tree) {
556
        if(is_numeric($key) && isset($sub_tree['tag']) && $sub_tree['tag'] == 'input') {
557
            if( !isset($sub_tree['type']) || in_array($sub_tree['type'], $allow_types) === false ) {
558
                unset($dom_tree[$key]);
559
            }
560
        } else if(is_array($sub_tree)) {
561
            extractHiddenInputs($dom_tree[$key]);
562
        }
563
    }
564
    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'input') {
565
        if( !isset($dom_tree['type']) || in_array($dom_tree['type'], $allow_types) === false ) {
566
            $dom_tree = array();
567
        }
568
    }
569 1
}
570
571
572