Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created
include/Smarty/plugins/function.sugar_button.php 3 patches
Indentation   +109 added lines, -110 removed lines patch added patch discarded remove patch
@@ -281,28 +281,28 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function smarty_function_sugar_button($params, &$smarty)
283 283
 {
284
-   if(empty($params['module'])) {
285
-   	  $smarty->trigger_error("sugar_button: missing required param (module)");
286
-   } else if(empty($params['id'])) {
287
-   	  $smarty->trigger_error("sugar_button: missing required param (id)");
288
-   } else if(empty($params['view'])) {
289
-   	  $smarty->trigger_error("sugar_button: missing required param (view)");
290
-   }
291
-
292
-   $js_form = (empty($params['form_id'])) ? "var _form = (this.form) ? this.form : document.forms[0];" : "var _form = document.getElementById('{$params['form_id']}');";
293
-
294
-   $type = $params['id'];
295
-   $location = (empty($params['location'])) ? "" : "_".$params['location'];
296
-
297
-   if(!is_array($type)) {
298
-   	  $module = $params['module'];
299
-   	  $view = $params['view'];
300
-   	  switch(strtoupper($type)) {
301
-			case "SEARCH":
284
+    if(empty($params['module'])) {
285
+            $smarty->trigger_error("sugar_button: missing required param (module)");
286
+    } else if(empty($params['id'])) {
287
+            $smarty->trigger_error("sugar_button: missing required param (id)");
288
+    } else if(empty($params['view'])) {
289
+            $smarty->trigger_error("sugar_button: missing required param (view)");
290
+    }
291
+
292
+    $js_form = (empty($params['form_id'])) ? "var _form = (this.form) ? this.form : document.forms[0];" : "var _form = document.getElementById('{$params['form_id']}');";
293
+
294
+    $type = $params['id'];
295
+    $location = (empty($params['location'])) ? "" : "_".$params['location'];
296
+
297
+    if(!is_array($type)) {
298
+            $module = $params['module'];
299
+            $view = $params['view'];
300
+            switch(strtoupper($type)) {
301
+            case "SEARCH":
302 302
                 $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
-			break;
303
+            break;
304 304
 
305
-			case "CANCEL":
305
+            case "CANCEL":
306 306
                 $cancelButton  = '{if !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && !empty($smarty.request.return_id))}';
307 307
                 $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.'"> ';
308 308
                 $cancelButton .= '{elseif !empty($smarty.request.return_action) && ($smarty.request.return_action == "DetailView" && !empty($fields.id.value))}';
@@ -314,30 +314,30 @@  discard block
 block discarded – undo
314 314
                 $cancelButton .= '{/if}';
315 315
 
316 316
                 $output = $cancelButton;
317
-			break;
317
+            break;
318 318
 
319
-			case "DELETE":
319
+            case "DELETE":
320 320
                 $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} ';
321 321
             break;
322 322
 
323
-			case "DUPLICATE":
324
-			    $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} ';
323
+            case "DUPLICATE":
324
+                $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} ';
325 325
             break;
326 326
 
327
-			case "EDIT";
328
-			    $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} ';
327
+            case "EDIT";
328
+                $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} ';
329 329
             break;
330 330
 
331
-			case "FIND_DUPLICATES":
332
-			    $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} ';
331
+            case "FIND_DUPLICATES":
332
+                $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} ';
333 333
             break;
334 334
 
335
-			case "SAVE":
336
-				$view = ($_REQUEST['action'] == 'EditView') ? 'EditView' : (($view == 'EditView') ? 'EditView' : $view);
337
-				$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} ';
338
-			break;
335
+            case "SAVE":
336
+                $view = ($_REQUEST['action'] == 'EditView') ? 'EditView' : (($view == 'EditView') ? 'EditView' : $view);
337
+                $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} ';
338
+            break;
339 339
 
340
-			case "SUBPANELSAVE":
340
+            case "SUBPANELSAVE":
341 341
                 if($view == 'QuickCreate' || (isset($_REQUEST['target_action']) && strtolower($_REQUEST['target_action']) == 'quickcreate')) $view =  "form_SubpanelQuickCreate_{$module}";
342 342
 
343 343
                 /* BEGIN - SECURITY GROUPS - redirect a subpanel save to the detail view if select popup and user in more than 1 group*/ 
@@ -353,112 +353,111 @@  discard block
 block discarded – undo
353 353
                 }
354 354
                 //if different here then change the group return right above
355 355
                 $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} ';
356
-                
357
-                */
356
+                 */
358 357
                 $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} ';
359 358
                 /* END - SECURITY GROUPS */
360 359
 
361 360
             break;
362
-			case "SUBPANELCANCEL":
361
+            case "SUBPANELCANCEL":
363 362
                 $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}"> ';
364 363
 
365 364
             break;
366
-		    case "SUBPANELFULLFORM":
365
+            case "SUBPANELFULLFORM":
367 366
                 $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}"> ';
368 367
                 $output .= '<input type="hidden" name="full_form" value="full_form">';
369 368
             break;
370
-			case "DCMENUCANCEL":
369
+            case "DCMENUCANCEL":
371 370
                 $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}"> ';
372 371
             break;
373
-			case "DCMENUSAVE":
372
+            case "DCMENUSAVE":
374 373
                             if ($view == 'QuickCreate') {
375 374
                                 $view = "form_DCQuickCreate_{$module}";
376 375
                             } else if ($view == 'EditView') {
377 376
                                 $view = "form_DCEditView_{$module}";
378 377
                             }
379
-				$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} ';
378
+                $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} ';
380 379
             break;
381
-			case "DCMENUFULLFORM":
380
+            case "DCMENUFULLFORM":
382 381
                 $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}"> ';
383 382
                 $output .= '<input type="hidden" name="full_form" value="full_form">';
384 383
                 $output .= '<input type="hidden" name="is_admin" value="">';
385 384
             break;
386
-			case "POPUPSAVE":
387
-				$view = ($view == 'QuickCreate') ? "form_QuickCreate_{$module}" : $view;
388
-				$output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" '
389
-					 . 'class="button primary" onclick="'.$js_form.' _form.action.value=\'Popup\';'
390
-					 . 'return check_form(\''.$view.'\')" type="submit" name="' . $params['module']
391
-					 . '_popupcreate_save_button" id="' . $params['module']
392
-					 . '_popupcreate_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
385
+            case "POPUPSAVE":
386
+                $view = ($view == 'QuickCreate') ? "form_QuickCreate_{$module}" : $view;
387
+                $output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" '
388
+                        . 'class="button primary" onclick="'.$js_form.' _form.action.value=\'Popup\';'
389
+                        . 'return check_form(\''.$view.'\')" type="submit" name="' . $params['module']
390
+                        . '_popupcreate_save_button" id="' . $params['module']
391
+                        . '_popupcreate_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
393 392
             break;
394
-			case "POPUPCANCEL":
393
+            case "POPUPCANCEL":
395 394
                 $output = '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" '
396
-					 . 'class="button" onclick="toggleDisplay(\'addform\');return false;" '
397
-					 . 'name="' . $params['module'] . '_popup_cancel_button" type="submit"'
398
-					 . 'id="' . $params['module'] . '_popup_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
395
+                        . 'class="button" onclick="toggleDisplay(\'addform\');return false;" '
396
+                        . 'name="' . $params['module'] . '_popup_cancel_button" type="submit"'
397
+                        . 'id="' . $params['module'] . '_popup_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
399 398
             break;
400
-			case "AUDIT":
401
-	            $popup_request_data = array(
402
-			        'call_back_function' => 'set_return',
403
-			        'form_name' => 'EditView',
404
-			        'field_to_name_array' => array(),
405
-			    );
406
-	            $json = getJSONobj();
407
-
408
-	            require_once('include/SugarFields/Parsers/MetaParser.php');
409
-	            $encoded_popup_request_data = MetaParser::parseDelimiters($json->encode($popup_request_data));
410
-	 			$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}">';
399
+            case "AUDIT":
400
+                $popup_request_data = array(
401
+                    'call_back_function' => 'set_return',
402
+                    'form_name' => 'EditView',
403
+                    'field_to_name_array' => array(),
404
+                );
405
+                $json = getJSONobj();
406
+
407
+                require_once('include/SugarFields/Parsers/MetaParser.php');
408
+                $encoded_popup_request_data = MetaParser::parseDelimiters($json->encode($popup_request_data));
409
+                    $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}">';
411 410
                 $output = '{if $bean->aclAccess("detail")}{if !empty($fields.id.value) && $isAuditEnabled}'.$audit_link.'{/if}{/if}';
412 411
             break;
413 412
 
414 413
 
415
-   	  } //switch
416
-      if(isset($params['appendTo'])) {
417
-          $smarty->append($params['appendTo'], $output);
418
-          return;
419
-      }
420
-      return $output;
421
-   } else if(is_array($type) && isset($type['sugar_html'])) {
422
-       require_once('include/SugarHtml/SugarHtml.php');
423
-
424
-       $dom_tree = SugarHtml::parseSugarHtml($type['sugar_html']);
425
-       replaceFormClick($dom_tree, $js_form);
426
-       $output = SugarHtml::createHtml($dom_tree);
427
-
428
-       if(isset($params['appendTo'])) {
429
-           $smarty->append($params['appendTo'], $output);
430
-           return;
431
-       }
432
-       return $output;
433
-   } else if(is_array($type) && isset($type['customCode'])) {
434
-       require_once('include/SugarHtml/SugarHtml.php');
435
-
436
-       $dom_tree = SugarHtml::parseHtmlTag($type['customCode']);
437
-       $hidden_exists = false;
438
-
439
-       replaceFormClick($dom_tree, $js_form, $hidden_exists);
440
-       if($hidden_exists) {
441
-           //If the customCode contains hidden fields, the extracted hidden fields need to append in the original form
442
-           $form = $smarty->get_template_vars('form');
443
-           $hidden_fields = $dom_tree;
444
-           extractHiddenInputs($hidden_fields);
445
-           if(!isset($form)) {
446
-               $form = array();
447
-           }
448
-           if(!isset($form['hidden'])) {
449
-               $form['hidden'] = array();
450
-           }
451
-           $form['hidden'][] = SugarHtml::createHtml($hidden_fields);
452
-           $smarty->assign('form', $form);
453
-       }
454
-       $output = SugarHtml::createHtml($dom_tree);
455
-
456
-       if(isset($params['appendTo'])) {
457
-           $smarty->append($params['appendTo'], $output);
458
-           return;
459
-       }
460
-       return $output;
461
-   }
414
+            } //switch
415
+        if(isset($params['appendTo'])) {
416
+            $smarty->append($params['appendTo'], $output);
417
+            return;
418
+        }
419
+        return $output;
420
+    } else if(is_array($type) && isset($type['sugar_html'])) {
421
+        require_once('include/SugarHtml/SugarHtml.php');
422
+
423
+        $dom_tree = SugarHtml::parseSugarHtml($type['sugar_html']);
424
+        replaceFormClick($dom_tree, $js_form);
425
+        $output = SugarHtml::createHtml($dom_tree);
426
+
427
+        if(isset($params['appendTo'])) {
428
+            $smarty->append($params['appendTo'], $output);
429
+            return;
430
+        }
431
+        return $output;
432
+    } else if(is_array($type) && isset($type['customCode'])) {
433
+        require_once('include/SugarHtml/SugarHtml.php');
434
+
435
+        $dom_tree = SugarHtml::parseHtmlTag($type['customCode']);
436
+        $hidden_exists = false;
437
+
438
+        replaceFormClick($dom_tree, $js_form, $hidden_exists);
439
+        if($hidden_exists) {
440
+            //If the customCode contains hidden fields, the extracted hidden fields need to append in the original form
441
+            $form = $smarty->get_template_vars('form');
442
+            $hidden_fields = $dom_tree;
443
+            extractHiddenInputs($hidden_fields);
444
+            if(!isset($form)) {
445
+                $form = array();
446
+            }
447
+            if(!isset($form['hidden'])) {
448
+                $form['hidden'] = array();
449
+            }
450
+            $form['hidden'][] = SugarHtml::createHtml($hidden_fields);
451
+            $smarty->assign('form', $form);
452
+        }
453
+        $output = SugarHtml::createHtml($dom_tree);
454
+
455
+        if(isset($params['appendTo'])) {
456
+            $smarty->append($params['appendTo'], $output);
457
+            return;
458
+        }
459
+        return $output;
460
+    }
462 461
 
463 462
 }
464 463
 /**
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function smarty_function_sugar_button($params, &$smarty)
283 283
 {
284
-   if(empty($params['module'])) {
284
+   if (empty($params['module'])) {
285 285
    	  $smarty->trigger_error("sugar_button: missing required param (module)");
286
-   } else if(empty($params['id'])) {
286
+   } else if (empty($params['id'])) {
287 287
    	  $smarty->trigger_error("sugar_button: missing required param (id)");
288
-   } else if(empty($params['view'])) {
288
+   } else if (empty($params['view'])) {
289 289
    	  $smarty->trigger_error("sugar_button: missing required param (view)");
290 290
    }
291 291
 
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
    $type = $params['id'];
295 295
    $location = (empty($params['location'])) ? "" : "_".$params['location'];
296 296
 
297
-   if(!is_array($type)) {
297
+   if (!is_array($type)) {
298 298
    	  $module = $params['module'];
299 299
    	  $view = $params['view'];
300
-   	  switch(strtoupper($type)) {
300
+   	  switch (strtoupper($type)) {
301 301
 			case "SEARCH":
302 302
                 $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 303
 			break;
@@ -317,28 +317,28 @@  discard block
 block discarded – undo
317 317
 			break;
318 318
 
319 319
 			case "DELETE":
320
-                $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} ';
320
+                $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} ';
321 321
             break;
322 322
 
323 323
 			case "DUPLICATE":
324
-			    $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} ';
324
+			    $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} ';
325 325
             break;
326 326
 
327 327
 			case "EDIT";
328
-			    $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} ';
328
+			    $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} ';
329 329
             break;
330 330
 
331 331
 			case "FIND_DUPLICATES":
332
-			    $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} ';
332
+			    $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} ';
333 333
             break;
334 334
 
335 335
 			case "SAVE":
336 336
 				$view = ($_REQUEST['action'] == 'EditView') ? 'EditView' : (($view == 'EditView') ? 'EditView' : $view);
337
-				$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} ';
337
+				$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} ';
338 338
 			break;
339 339
 
340 340
 			case "SUBPANELSAVE":
341
-                if($view == 'QuickCreate' || (isset($_REQUEST['target_action']) && strtolower($_REQUEST['target_action']) == 'quickcreate')) $view =  "form_SubpanelQuickCreate_{$module}";
341
+                if ($view == 'QuickCreate' || (isset($_REQUEST['target_action']) && strtolower($_REQUEST['target_action']) == 'quickcreate')) $view = "form_SubpanelQuickCreate_{$module}";
342 342
 
343 343
                 /* BEGIN - SECURITY GROUPS - redirect a subpanel save to the detail view if select popup and user in more than 1 group*/ 
344 344
                 /**
@@ -355,20 +355,20 @@  discard block
 block discarded – undo
355 355
                 $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} ';
356 356
                 
357 357
                 */
358
-                $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} ';
358
+                $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} ';
359 359
                 /* END - SECURITY GROUPS */
360 360
 
361 361
             break;
362 362
 			case "SUBPANELCANCEL":
363
-                $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}"> ';
363
+                $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}"> ';
364 364
 
365 365
             break;
366 366
 		    case "SUBPANELFULLFORM":
367
-                $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}"> ';
367
+                $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}"> ';
368 368
                 $output .= '<input type="hidden" name="full_form" value="full_form">';
369 369
             break;
370 370
 			case "DCMENUCANCEL":
371
-                $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}"> ';
371
+                $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}"> ';
372 372
             break;
373 373
 			case "DCMENUSAVE":
374 374
                             if ($view == 'QuickCreate') {
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
                             } else if ($view == 'EditView') {
377 377
                                 $view = "form_DCEditView_{$module}";
378 378
                             }
379
-				$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} ';
379
+				$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} ';
380 380
             break;
381 381
 			case "DCMENUFULLFORM":
382
-                $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}"> ';
382
+                $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}"> ';
383 383
                 $output .= '<input type="hidden" name="full_form" value="full_form">';
384 384
                 $output .= '<input type="hidden" name="is_admin" value="">';
385 385
             break;
@@ -387,15 +387,15 @@  discard block
 block discarded – undo
387 387
 				$view = ($view == 'QuickCreate') ? "form_QuickCreate_{$module}" : $view;
388 388
 				$output = '{if $bean->aclAccess("save")}<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" '
389 389
 					 . 'class="button primary" onclick="'.$js_form.' _form.action.value=\'Popup\';'
390
-					 . 'return check_form(\''.$view.'\')" type="submit" name="' . $params['module']
391
-					 . '_popupcreate_save_button" id="' . $params['module']
390
+					 . 'return check_form(\''.$view.'\')" type="submit" name="'.$params['module']
391
+					 . '_popupcreate_save_button" id="'.$params['module']
392 392
 					 . '_popupcreate_save_button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">{/if} ';
393 393
             break;
394 394
 			case "POPUPCANCEL":
395 395
                 $output = '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" '
396 396
 					 . 'class="button" onclick="toggleDisplay(\'addform\');return false;" '
397
-					 . 'name="' . $params['module'] . '_popup_cancel_button" type="submit"'
398
-					 . 'id="' . $params['module'] . '_popup_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
397
+					 . 'name="'.$params['module'].'_popup_cancel_button" type="submit"'
398
+					 . 'id="'.$params['module'].'_popup_cancel_button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}"> ';
399 399
             break;
400 400
 			case "AUDIT":
401 401
 	            $popup_request_data = array(
@@ -407,45 +407,45 @@  discard block
 block discarded – undo
407 407
 
408 408
 	            require_once('include/SugarFields/Parsers/MetaParser.php');
409 409
 	            $encoded_popup_request_data = MetaParser::parseDelimiters($json->encode($popup_request_data));
410
-	 			$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}">';
410
+	 			$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}">';
411 411
                 $output = '{if $bean->aclAccess("detail")}{if !empty($fields.id.value) && $isAuditEnabled}'.$audit_link.'{/if}{/if}';
412 412
             break;
413 413
 
414 414
 
415 415
    	  } //switch
416
-      if(isset($params['appendTo'])) {
416
+      if (isset($params['appendTo'])) {
417 417
           $smarty->append($params['appendTo'], $output);
418 418
           return;
419 419
       }
420 420
       return $output;
421
-   } else if(is_array($type) && isset($type['sugar_html'])) {
421
+   } else if (is_array($type) && isset($type['sugar_html'])) {
422 422
        require_once('include/SugarHtml/SugarHtml.php');
423 423
 
424 424
        $dom_tree = SugarHtml::parseSugarHtml($type['sugar_html']);
425 425
        replaceFormClick($dom_tree, $js_form);
426 426
        $output = SugarHtml::createHtml($dom_tree);
427 427
 
428
-       if(isset($params['appendTo'])) {
428
+       if (isset($params['appendTo'])) {
429 429
            $smarty->append($params['appendTo'], $output);
430 430
            return;
431 431
        }
432 432
        return $output;
433
-   } else if(is_array($type) && isset($type['customCode'])) {
433
+   } else if (is_array($type) && isset($type['customCode'])) {
434 434
        require_once('include/SugarHtml/SugarHtml.php');
435 435
 
436 436
        $dom_tree = SugarHtml::parseHtmlTag($type['customCode']);
437 437
        $hidden_exists = false;
438 438
 
439 439
        replaceFormClick($dom_tree, $js_form, $hidden_exists);
440
-       if($hidden_exists) {
440
+       if ($hidden_exists) {
441 441
            //If the customCode contains hidden fields, the extracted hidden fields need to append in the original form
442 442
            $form = $smarty->get_template_vars('form');
443 443
            $hidden_fields = $dom_tree;
444 444
            extractHiddenInputs($hidden_fields);
445
-           if(!isset($form)) {
445
+           if (!isset($form)) {
446 446
                $form = array();
447 447
            }
448
-           if(!isset($form['hidden'])) {
448
+           if (!isset($form['hidden'])) {
449 449
                $form['hidden'] = array();
450 450
            }
451 451
            $form['hidden'][] = SugarHtml::createHtml($hidden_fields);
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
        }
454 454
        $output = SugarHtml::createHtml($dom_tree);
455 455
 
456
-       if(isset($params['appendTo'])) {
456
+       if (isset($params['appendTo'])) {
457 457
            $smarty->append($params['appendTo'], $output);
458 458
            return;
459 459
        }
@@ -475,21 +475,21 @@  discard block
 block discarded – undo
475 475
     $set_submit = false;
476 476
     $is_hidden_field = false;
477 477
     //if the code is wrapped with the form element, it will escape the operation for JS replacement
478
-    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'form')
478
+    if (isset($dom_tree['tag']) && $dom_tree['tag'] == 'form')
479 479
         return false;
480 480
 
481
-    if(isset($dom_tree['type']) && $dom_tree['type'] == 'hidden') {
481
+    if (isset($dom_tree['type']) && $dom_tree['type'] == 'hidden') {
482 482
         $is_hidden_field = true;
483 483
     }
484 484
 
485 485
     //Replace the JS syntax where the sugar_button contains the event handler for this.form
486
-    if(isset($dom_tree['onclick'])) {
487
-        if(strpos($dom_tree['onclick'], "this.form") !== false) {
486
+    if (isset($dom_tree['onclick'])) {
487
+        if (strpos($dom_tree['onclick'], "this.form") !== false) {
488 488
             $dom_tree['onclick'] = str_replace("this.form", "_form", $dom_tree['onclick']);
489
-            if(substr($dom_tree['onclick'], -1) != ';')
489
+            if (substr($dom_tree['onclick'], -1) != ';')
490 490
                 $dom_tree['onclick'] .= ";";
491 491
             //Onclick handler contains returning a variable, for example it prompts a confirm message.
492
-            if(strpos($dom_tree['onclick'], "return ") !== false ) {
492
+            if (strpos($dom_tree['onclick'], "return ") !== false) {
493 493
                 $dom_tree['onclick'] = $js_form.' var _onclick=(function(){ldelim}'.$dom_tree['onclick']."{rdelim}()); if(_onclick!==false) _form.submit();";
494 494
             } else {
495 495
                 $dom_tree['onclick'] = $js_form.$dom_tree['onclick']."_form.submit();";
@@ -498,19 +498,19 @@  discard block
 block discarded – undo
498 498
             $set_submit = true;
499 499
         }
500 500
     }
501
-    foreach($dom_tree as $key => $sub_tree) {
502
-        if(is_array($sub_tree)) {
501
+    foreach ($dom_tree as $key => $sub_tree) {
502
+        if (is_array($sub_tree)) {
503 503
             list($_submit, $_hidden) = replaceFormClick($dom_tree[$key], $js_form, $hidden_field_exists);
504 504
             $set_submit = ($set_submit) ? $set_submit : $_submit;
505 505
             $is_hidden_field = ($is_hidden_field) ? $is_hidden_field : $_hidden;
506 506
         }
507 507
     }
508 508
 
509
-    if($set_submit && isset($dom_tree['type'])) {
509
+    if ($set_submit && isset($dom_tree['type'])) {
510 510
         $dom_tree['type'] = "button";
511 511
         $set_submit = false;
512 512
     }
513
-    if($is_hidden_field && isset($dom_tree['tag']) && $dom_tree['tag'] == 'input' ) {
513
+    if ($is_hidden_field && isset($dom_tree['tag']) && $dom_tree['tag'] == 'input') {
514 514
         $hidden_field_exists = true;
515 515
         $is_hidden_field = false;
516 516
     }
@@ -527,20 +527,20 @@  discard block
 block discarded – undo
527 527
         'hidden'
528 528
     );
529 529
     //all hidden fields in the form elements must NOT attach in the original form
530
-    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'form') {
530
+    if (isset($dom_tree['tag']) && $dom_tree['tag'] == 'form') {
531 531
         $dom_tree = array();
532 532
     }
533
-    foreach($dom_tree as $key => $sub_tree) {
534
-        if(is_numeric($key) && isset($sub_tree['tag']) && $sub_tree['tag'] == 'input') {
535
-            if( !isset($sub_tree['type']) || in_array($sub_tree['type'], $allow_types) === false ) {
533
+    foreach ($dom_tree as $key => $sub_tree) {
534
+        if (is_numeric($key) && isset($sub_tree['tag']) && $sub_tree['tag'] == 'input') {
535
+            if (!isset($sub_tree['type']) || in_array($sub_tree['type'], $allow_types) === false) {
536 536
                 unset($dom_tree[$key]);
537 537
             }
538
-        } else if(is_array($sub_tree)) {
538
+        } else if (is_array($sub_tree)) {
539 539
             extractHiddenInputs($dom_tree[$key]);
540 540
         }
541 541
     }
542
-    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'input') {
543
-        if( !isset($dom_tree['type']) || in_array($dom_tree['type'], $allow_types) === false ) {
542
+    if (isset($dom_tree['tag']) && $dom_tree['tag'] == 'input') {
543
+        if (!isset($dom_tree['type']) || in_array($dom_tree['type'], $allow_types) === false) {
544 544
             $dom_tree = array();
545 545
         }
546 546
     }
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -338,7 +338,9 @@  discard block
 block discarded – undo
338 338
 			break;
339 339
 
340 340
 			case "SUBPANELSAVE":
341
-                if($view == 'QuickCreate' || (isset($_REQUEST['target_action']) && strtolower($_REQUEST['target_action']) == 'quickcreate')) $view =  "form_SubpanelQuickCreate_{$module}";
341
+                if($view == 'QuickCreate' || (isset($_REQUEST['target_action']) && strtolower($_REQUEST['target_action']) == 'quickcreate')) {
342
+                    $view =  "form_SubpanelQuickCreate_{$module}";
343
+                }
342 344
 
343 345
                 /* BEGIN - SECURITY GROUPS - redirect a subpanel save to the detail view if select popup and user in more than 1 group*/ 
344 346
                 /**
@@ -475,8 +477,9 @@  discard block
 block discarded – undo
475 477
     $set_submit = false;
476 478
     $is_hidden_field = false;
477 479
     //if the code is wrapped with the form element, it will escape the operation for JS replacement
478
-    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'form')
479
-        return false;
480
+    if(isset($dom_tree['tag']) && $dom_tree['tag'] == 'form') {
481
+            return false;
482
+    }
480 483
 
481 484
     if(isset($dom_tree['type']) && $dom_tree['type'] == 'hidden') {
482 485
         $is_hidden_field = true;
@@ -486,8 +489,9 @@  discard block
 block discarded – undo
486 489
     if(isset($dom_tree['onclick'])) {
487 490
         if(strpos($dom_tree['onclick'], "this.form") !== false) {
488 491
             $dom_tree['onclick'] = str_replace("this.form", "_form", $dom_tree['onclick']);
489
-            if(substr($dom_tree['onclick'], -1) != ';')
490
-                $dom_tree['onclick'] .= ";";
492
+            if(substr($dom_tree['onclick'], -1) != ';') {
493
+                            $dom_tree['onclick'] .= ";";
494
+            }
491 495
             //Onclick handler contains returning a variable, for example it prompts a confirm message.
492 496
             if(strpos($dom_tree['onclick'], "return ") !== false ) {
493 497
                 $dom_tree['onclick'] = $js_form.' var _onclick=(function(){ldelim}'.$dom_tree['onclick']."{rdelim}()); if(_onclick!==false) _form.submit();";
Please login to merge, or discard this patch.
include/Smarty/plugins/shared.make_timestamp.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
  */
17 17
 function smarty_make_timestamp($string)
18 18
 {
19
-    if(empty($string)) {
19
+    if (empty($string)) {
20 20
         // use "now":
21 21
         $time = time();
22 22
 
23 23
     } elseif (preg_match('/^\d{14}$/', $string)) {
24 24
         // it is mysql timestamp format of YYYYMMDDHHMMSS?            
25
-        $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
26
-                       substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
25
+        $time = mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2),
26
+                       substr($string, 4, 2), substr($string, 6, 2), substr($string, 0, 4));
27 27
         
28 28
     } elseif (is_numeric($string)) {
29 29
         // it is a numeric string, we handle it as timestamp
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Smarty shared plugin
4
- * @package Smarty
5
- * @subpackage plugins
6
- */
3
+         * Smarty shared plugin
4
+         * @package Smarty
5
+         * @subpackage plugins
6
+         */
7 7
 
8 8
 
9 9
 /**
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     } elseif (preg_match('/^\d{14}$/', $string)) {
24 24
         // it is mysql timestamp format of YYYYMMDDHHMMSS?            
25 25
         $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
26
-                       substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
26
+                        substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
27 27
         
28 28
     } elseif (is_numeric($string)) {
29 29
         // it is a numeric string, we handle it as timestamp
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
  *           from a string.
13 13
  * @author   Monte Ohrt <monte at ohrt dot com>
14 14
  * @param string
15
- * @return string
15
+ * @return integer
16 16
  */
17 17
 function smarty_make_timestamp($string)
18 18
 {
Please login to merge, or discard this patch.
include/Smarty/plugins/modifier.in_array.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@
 block discarded – undo
44 44
  */
45 45
 function smarty_modifier_in_array($needle = null, $haystack = null)
46 46
 {
47
-	//Smarty barfs if Array is empty
47
+    //Smarty barfs if Array is empty
48 48
     if($haystack == null || empty($haystack)) {
49
-       return false;	
49
+        return false;	
50 50
     }
51 51
     return in_array($needle, $haystack);
52 52
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
 function smarty_modifier_in_array($needle = null, $haystack = null)
46 46
 {
47 47
 	//Smarty barfs if Array is empty
48
-    if($haystack == null || empty($haystack)) {
48
+    if ($haystack == null || empty($haystack)) {
49 49
        return false;	
50 50
     }
51 51
     return in_array($needle, $haystack);
Please login to merge, or discard this patch.
include/Smarty/plugins/function.sugar_email_btn.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -39,24 +39,24 @@
 block discarded – undo
39 39
 
40 40
 
41 41
 
42
- /**
43
- * smarty_function_sugar_email_btn
44
- * This is the constructor for the Smarty plugin.
45
- * This function exists so that the proper email button based on user prefs is loaded into the quotes module.
46
- * 
47
- * @param $params The runtime Smarty key/value arguments
48
- * @param $smarty The reference to the Smarty object used in this invocation
49
- */
42
+    /**
43
+     * smarty_function_sugar_email_btn
44
+     * This is the constructor for the Smarty plugin.
45
+     * This function exists so that the proper email button based on user prefs is loaded into the quotes module.
46
+     * 
47
+     * @param $params The runtime Smarty key/value arguments
48
+     * @param $smarty The reference to the Smarty object used in this invocation
49
+     */
50 50
 function smarty_function_sugar_email_btn($params, &$smarty)
51 51
 {
52
-	global $app_strings, $current_user;
53
-	$pdfButtons = '';
54
-	$client = $current_user->getPreference('email_link_type');
55
-	if ($client != 'sugar') {
56
-		$pdfButtons = '<input title="'. $app_strings["LBL_EMAIL_COMPOSE"] . '" class="button" type="submit" name="button" value="'. $app_strings["LBL_EMAIL_COMPOSE"] . '" onclick="location.href=\'mailto:\';return false;"> ';
57
-	} else {
58
-		$pdfButtons = '<input id="email_as_pdf_button" title="'. $app_strings["LBL_EMAIL_PDF_BUTTON_TITLE"] . '" class="button" type="submit" name="button" value="'. $app_strings["LBL_EMAIL_PDF_BUTTON_LABEL"] . '" onclick="this.form.email_action.value=\'EmailLayout\';"> ';
59
-	}
60
-	return $pdfButtons;
52
+    global $app_strings, $current_user;
53
+    $pdfButtons = '';
54
+    $client = $current_user->getPreference('email_link_type');
55
+    if ($client != 'sugar') {
56
+        $pdfButtons = '<input title="'. $app_strings["LBL_EMAIL_COMPOSE"] . '" class="button" type="submit" name="button" value="'. $app_strings["LBL_EMAIL_COMPOSE"] . '" onclick="location.href=\'mailto:\';return false;"> ';
57
+    } else {
58
+        $pdfButtons = '<input id="email_as_pdf_button" title="'. $app_strings["LBL_EMAIL_PDF_BUTTON_TITLE"] . '" class="button" type="submit" name="button" value="'. $app_strings["LBL_EMAIL_PDF_BUTTON_LABEL"] . '" onclick="this.form.email_action.value=\'EmailLayout\';"> ';
59
+    }
60
+    return $pdfButtons;
61 61
 }
62 62
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,9 +53,9 @@
 block discarded – undo
53 53
 	$pdfButtons = '';
54 54
 	$client = $current_user->getPreference('email_link_type');
55 55
 	if ($client != 'sugar') {
56
-		$pdfButtons = '<input title="'. $app_strings["LBL_EMAIL_COMPOSE"] . '" class="button" type="submit" name="button" value="'. $app_strings["LBL_EMAIL_COMPOSE"] . '" onclick="location.href=\'mailto:\';return false;"> ';
56
+		$pdfButtons = '<input title="'.$app_strings["LBL_EMAIL_COMPOSE"].'" class="button" type="submit" name="button" value="'.$app_strings["LBL_EMAIL_COMPOSE"].'" onclick="location.href=\'mailto:\';return false;"> ';
57 57
 	} else {
58
-		$pdfButtons = '<input id="email_as_pdf_button" title="'. $app_strings["LBL_EMAIL_PDF_BUTTON_TITLE"] . '" class="button" type="submit" name="button" value="'. $app_strings["LBL_EMAIL_PDF_BUTTON_LABEL"] . '" onclick="this.form.email_action.value=\'EmailLayout\';"> ';
58
+		$pdfButtons = '<input id="email_as_pdf_button" title="'.$app_strings["LBL_EMAIL_PDF_BUTTON_TITLE"].'" class="button" type="submit" name="button" value="'.$app_strings["LBL_EMAIL_PDF_BUTTON_LABEL"].'" onclick="this.form.email_action.value=\'EmailLayout\';"> ';
59 59
 	}
60 60
 	return $pdfButtons;
61 61
 }
Please login to merge, or discard this patch.
include/Smarty/plugins/modifier.lookup.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@
 block discarded – undo
42 42
 
43 43
 
44 44
 function smarty_modifier_lookup($value='', $from=array()){
45
-	$value = trim($value);
46
-	if (array_key_exists($value, $from)) { 
47
-		return $from[$value]; 
48
-	} 
49
-	return ''; 
45
+    $value = trim($value);
46
+    if (array_key_exists($value, $from)) { 
47
+        return $from[$value]; 
48
+    } 
49
+    return ''; 
50 50
 } 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
+if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 4
 /*********************************************************************************
5 5
  * SugarCRM Community Edition is a customer relationship management program developed by
6 6
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
 
43 43
 
44
-function smarty_modifier_lookup($value='', $from=array()){
44
+function smarty_modifier_lookup($value = '', $from = array()) {
45 45
 	$value = trim($value);
46 46
 	if (array_key_exists($value, $from)) { 
47 47
 		return $from[$value]; 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@
 block discarded – undo
1 1
 <?php
2
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
2
+if(!defined('sugarEntry') || !sugarEntry) {
3
+    die('Not A Valid Entry Point');
4
+}
3 5
 /*********************************************************************************
4 6
  * SugarCRM Community Edition is a customer relationship management program developed by
5 7
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
Please login to merge, or discard this patch.
include/Smarty/plugins/function.sugarvar_connector.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -74,14 +74,14 @@
 block discarded – undo
74 74
 
75 75
 function smarty_function_sugarvar_connector($params, &$smarty) {
76 76
       
77
-      $displayParams = $smarty->get_template_vars('displayParams');
78
-      if(!isset($displayParams['module'])) {
79
-         $smarty->trigger_error("sugarvar_connector: missing 'module' parameter");
80
-         $GLOBALS['log']->error("sugarvar_connector: missing 'module' parameter");
81
-         return;     	
82
-      }
77
+        $displayParams = $smarty->get_template_vars('displayParams');
78
+        if(!isset($displayParams['module'])) {
79
+            $smarty->trigger_error("sugarvar_connector: missing 'module' parameter");
80
+            $GLOBALS['log']->error("sugarvar_connector: missing 'module' parameter");
81
+            return;     	
82
+        }
83 83
       
84
-      require_once('include/connectors/utils/ConnectorUtils.php');
85
-      echo ConnectorUtils::getConnectorButtonScript($displayParams, $smarty);
84
+        require_once('include/connectors/utils/ConnectorUtils.php');
85
+        echo ConnectorUtils::getConnectorButtonScript($displayParams, $smarty);
86 86
 }
87 87
 ?>
88 88
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 */
33 33
 
34 34
 
35
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
35
+if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
36 36
 /*********************************************************************************
37 37
  * SugarCRM Community Edition is a customer relationship management program developed by
38 38
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 function smarty_function_sugarvar_connector($params, &$smarty) {
76 76
       
77 77
       $displayParams = $smarty->get_template_vars('displayParams');
78
-      if(!isset($displayParams['module'])) {
78
+      if (!isset($displayParams['module'])) {
79 79
          $smarty->trigger_error("sugarvar_connector: missing 'module' parameter");
80 80
          $GLOBALS['log']->error("sugarvar_connector: missing 'module' parameter");
81 81
          return;     	
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@
 block discarded – undo
1 1
 <?php
2
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
2
+if(!defined('sugarEntry') || !sugarEntry) {
3
+    die('Not A Valid Entry Point');
4
+}
3 5
 /*********************************************************************************
4 6
  * SugarCRM Community Edition is a customer relationship management program developed by
5 7
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
Please login to merge, or discard this patch.
include/Smarty/plugins/function.sugar_include.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -57,33 +57,33 @@
 block discarded – undo
57 57
     global $app_strings;
58 58
 
59 59
     if(isset($params['type']) && $params['type'] == 'php') {
60
-		if(!isset($params['file'])) {
61
-		   $smarty->trigger_error($app_strings['ERR_MISSING_REQUIRED_FIELDS'] . 'include');
62
-		} 
60
+        if(!isset($params['file'])) {
61
+            $smarty->trigger_error($app_strings['ERR_MISSING_REQUIRED_FIELDS'] . 'include');
62
+        } 
63 63
 		
64
-		$includeFile = $params['file'];
65
-		if(!file_exists($includeFile)) {
66
-		   $smarty->trigger_error($app_strings['ERR_NO_SUCH_FILE'] . ': ' . $includeFile);
67
-		}
64
+        $includeFile = $params['file'];
65
+        if(!file_exists($includeFile)) {
66
+            $smarty->trigger_error($app_strings['ERR_NO_SUCH_FILE'] . ': ' . $includeFile);
67
+        }
68 68
 		
69
-	    ob_start();
70
-	    require($includeFile);
71
-	    $output_html = ob_get_contents();
72
-	    ob_end_clean();
73
-	    echo $output_html; 
69
+        ob_start();
70
+        require($includeFile);
71
+        $output_html = ob_get_contents();
72
+        ob_end_clean();
73
+        echo $output_html; 
74 74
     } else if(is_array($params['include'])) {
75
-	   	  $code = '';
76
-	   	  foreach($params['include'] as $include) {
77
-	   	  	      if(isset($include['file'])) {
78
-	   	  	         $file = $include['file'];
79
-	   	  	         if(preg_match('/[\.]js$/si',$file)) {
80
-	   	  	            $code .= "<script src=\"". getJSPath($include['file']) ."\"></script>";
81
-	   	  	         } else if(preg_match('/[\.]php$/si', $file)) {
82
-	   	  	            require_once($file);	
83
-	   	  	         }
84
-	   	  	      } 
85
-	   	  } //foreach
86
-	      return $code;
87
-   	} //if
75
+                $code = '';
76
+                foreach($params['include'] as $include) {
77
+                        if(isset($include['file'])) {
78
+                            $file = $include['file'];
79
+                            if(preg_match('/[\.]js$/si',$file)) {
80
+                                $code .= "<script src=\"". getJSPath($include['file']) ."\"></script>";
81
+                            } else if(preg_match('/[\.]php$/si', $file)) {
82
+                                require_once($file);	
83
+                            }
84
+                        } 
85
+                } //foreach
86
+            return $code;
87
+        } //if
88 88
 }
89 89
 ?>
90 90
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
 {
57 57
     global $app_strings;
58 58
 
59
-    if(isset($params['type']) && $params['type'] == 'php') {
60
-		if(!isset($params['file'])) {
61
-		   $smarty->trigger_error($app_strings['ERR_MISSING_REQUIRED_FIELDS'] . 'include');
59
+    if (isset($params['type']) && $params['type'] == 'php') {
60
+		if (!isset($params['file'])) {
61
+		   $smarty->trigger_error($app_strings['ERR_MISSING_REQUIRED_FIELDS'].'include');
62 62
 		} 
63 63
 		
64 64
 		$includeFile = $params['file'];
65
-		if(!file_exists($includeFile)) {
66
-		   $smarty->trigger_error($app_strings['ERR_NO_SUCH_FILE'] . ': ' . $includeFile);
65
+		if (!file_exists($includeFile)) {
66
+		   $smarty->trigger_error($app_strings['ERR_NO_SUCH_FILE'].': '.$includeFile);
67 67
 		}
68 68
 		
69 69
 	    ob_start();
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	    $output_html = ob_get_contents();
72 72
 	    ob_end_clean();
73 73
 	    echo $output_html; 
74
-    } else if(is_array($params['include'])) {
74
+    } else if (is_array($params['include'])) {
75 75
 	   	  $code = '';
76
-	   	  foreach($params['include'] as $include) {
77
-	   	  	      if(isset($include['file'])) {
76
+	   	  foreach ($params['include'] as $include) {
77
+	   	  	      if (isset($include['file'])) {
78 78
 	   	  	         $file = $include['file'];
79
-	   	  	         if(preg_match('/[\.]js$/si',$file)) {
80
-	   	  	            $code .= "<script src=\"". getJSPath($include['file']) ."\"></script>";
81
-	   	  	         } else if(preg_match('/[\.]php$/si', $file)) {
79
+	   	  	         if (preg_match('/[\.]js$/si', $file)) {
80
+	   	  	            $code .= "<script src=\"".getJSPath($include['file'])."\"></script>";
81
+	   	  	         } else if (preg_match('/[\.]php$/si', $file)) {
82 82
 	   	  	            require_once($file);	
83 83
 	   	  	         }
84 84
 	   	  	      } 
Please login to merge, or discard this patch.
include/Smarty/Smarty_Compiler.class.php 4 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
         // matches all valid variables (no quotes, no modifiers)
132 132
         $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|'
133
-           . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')';
133
+            . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')';
134 134
 
135 135
         // matches valid variable syntax:
136 136
         // $foo
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
         // |foo|bar
173 173
         // |foo:$foo->bar
174 174
         $this->_mod_regexp = '(?:\|@?\w+(?::(?:\w+|' . $this->_num_const_regexp . '|'
175
-           . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)';
175
+            . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)';
176 176
 
177 177
         // matches valid function name:
178 178
         // foo123
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         // "text"|bar
194 194
         // $foo->bar
195 195
         $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|'
196
-           . $this->_var_regexp . '|' . $this->_num_const_regexp  . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)';
196
+            . $this->_var_regexp . '|' . $this->_num_const_regexp  . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)';
197 197
 
198 198
         // matches valid parenthesised function parameters:
199 199
         //
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         // _foo_bar($foo,"bar")
211 211
         // foo123($foo,$foo->bar(),"foo")
212 212
         $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:'
213
-           . $this->_parenth_param_regexp . '))';
213
+            . $this->_parenth_param_regexp . '))';
214 214
     }
215 215
 
216 216
     /**
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
 
264 264
         /* replace special blocks by "{php}" */
265 265
         $source_content = preg_replace_callback($search, create_function ('$matches', "return '"
266
-                                       . $this->_quote_replace($this->left_delimiter) . 'php'
267
-                                       . "' . str_repeat(\"\n\", substr_count('\$matches[1]', \"\n\")) .'"
268
-                                       . $this->_quote_replace($this->right_delimiter)
269
-                                       . "';")
270
-                                       , $source_content);
266
+                                        . $this->_quote_replace($this->left_delimiter) . 'php'
267
+                                        . "' . str_repeat(\"\n\", substr_count('\$matches[1]', \"\n\")) .'"
268
+                                        . $this->_quote_replace($this->right_delimiter)
269
+                                        . "';")
270
+                                        , $source_content);
271 271
 
272 272
         /* Gather all template tags. */
273 273
         preg_match_all("~{$ldq}\s*(.*?)\s*{$rdq}~s", $source_content, $_match);
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
                 if ($postfilter === false) continue;
389 389
                 if ($postfilter[3] || is_callable($postfilter[0])) {
390 390
                     $compiled_content = call_user_func_array($postfilter[0],
391
-                                                              array($compiled_content, &$this));
391
+                                                                array($compiled_content, &$this));
392 392
                     $this->_plugins['postfilter'][$filter_name][3] = true;
393 393
                 } else {
394 394
                     $this->_trigger_fatal_error("Smarty plugin error: postfilter '$filter_name' is not implemented");
@@ -649,8 +649,8 @@  discard block
 block discarded – undo
649 649
                 $output = call_user_func_array($plugin_func, array($tag_args, &$this));
650 650
                 if($output != '') {
651 651
                 $output = '<?php ' . $this->_push_cacheable_state('compiler', $tag_command)
652
-                                   . $output
653
-                                   . $this->_pop_cacheable_state('compiler', $tag_command) . ' ?>';
652
+                                    . $output
653
+                                    . $this->_pop_cacheable_state('compiler', $tag_command) . ' ?>';
654 654
                 }
655 655
             } else {
656 656
                 $this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__);
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
             $output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
1116 1116
         else
1117 1117
             $output .= "if ({$section_props}['max'] < 0)\n" .
1118
-                       "    {$section_props}['max'] = {$section_props}['loop'];\n";
1118
+                        "    {$section_props}['max'] = {$section_props}['loop'];\n";
1119 1119
 
1120 1120
         if (!isset($attrs['step']))
1121 1121
             $output .= "{$section_props}['step'] = 1;\n";
@@ -1124,9 +1124,9 @@  discard block
 block discarded – undo
1124 1124
             $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
1125 1125
         else {
1126 1126
             $output .= "if ({$section_props}['start'] < 0)\n" .
1127
-                       "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" .
1128
-                       "else\n" .
1129
-                       "    {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
1127
+                        "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" .
1128
+                        "else\n" .
1129
+                        "    {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
1130 1130
         }
1131 1131
 
1132 1132
         $output .= "if ({$section_props}['show']) {\n";
@@ -1136,9 +1136,9 @@  discard block
 block discarded – undo
1136 1136
             $output .= "    {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
1137 1137
         }
1138 1138
         $output .= "    if ({$section_props}['total'] == 0)\n" .
1139
-                   "        {$section_props}['show'] = false;\n" .
1140
-                   "} else\n" .
1141
-                   "    {$section_props}['total'] = 0;\n";
1139
+                    "        {$section_props}['show'] = false;\n" .
1140
+                    "} else\n" .
1141
+                    "    {$section_props}['total'] = 0;\n";
1142 1142
 
1143 1143
         $output .= "if ({$section_props}['show']):\n";
1144 1144
         $output .= "
@@ -1987,8 +1987,8 @@  discard block
 block discarded – undo
1987 1987
         }
1988 1988
         if (!isset($this->_plugin_info[$type][$name])) {
1989 1989
             $this->_plugin_info[$type][$name] = array($this->_current_file,
1990
-                                                      $this->_current_line_no,
1991
-                                                      $delayed_loading);
1990
+                                                        $this->_current_line_no,
1991
+                                                        $delayed_loading);
1992 1992
         }
1993 1993
     }
1994 1994
 
@@ -2056,7 +2056,7 @@  discard block
 block discarded – undo
2056 2056
             case 'get':
2057 2057
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2058 2058
                     $this->_syntax_error("(secure mode) super global access not permitted",
2059
-                                         E_USER_WARNING, __FILE__, __LINE__);
2059
+                                            E_USER_WARNING, __FILE__, __LINE__);
2060 2060
                     return;
2061 2061
                 }
2062 2062
                 $compiled_ref = "\$_GET";
@@ -2065,7 +2065,7 @@  discard block
 block discarded – undo
2065 2065
             case 'post':
2066 2066
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2067 2067
                     $this->_syntax_error("(secure mode) super global access not permitted",
2068
-                                         E_USER_WARNING, __FILE__, __LINE__);
2068
+                                            E_USER_WARNING, __FILE__, __LINE__);
2069 2069
                     return;
2070 2070
                 }
2071 2071
                 $compiled_ref = "\$_POST";
@@ -2074,7 +2074,7 @@  discard block
 block discarded – undo
2074 2074
             case 'cookies':
2075 2075
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2076 2076
                     $this->_syntax_error("(secure mode) super global access not permitted",
2077
-                                         E_USER_WARNING, __FILE__, __LINE__);
2077
+                                            E_USER_WARNING, __FILE__, __LINE__);
2078 2078
                     return;
2079 2079
                 }
2080 2080
                 $compiled_ref = "\$_COOKIE";
@@ -2083,7 +2083,7 @@  discard block
 block discarded – undo
2083 2083
             case 'env':
2084 2084
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2085 2085
                     $this->_syntax_error("(secure mode) super global access not permitted",
2086
-                                         E_USER_WARNING, __FILE__, __LINE__);
2086
+                                            E_USER_WARNING, __FILE__, __LINE__);
2087 2087
                     return;
2088 2088
                 }
2089 2089
                 $compiled_ref = "\$_ENV";
@@ -2092,7 +2092,7 @@  discard block
 block discarded – undo
2092 2092
             case 'server':
2093 2093
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2094 2094
                     $this->_syntax_error("(secure mode) super global access not permitted",
2095
-                                         E_USER_WARNING, __FILE__, __LINE__);
2095
+                                            E_USER_WARNING, __FILE__, __LINE__);
2096 2096
                     return;
2097 2097
                 }
2098 2098
                 $compiled_ref = "\$_SERVER";
@@ -2101,7 +2101,7 @@  discard block
 block discarded – undo
2101 2101
             case 'session':
2102 2102
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2103 2103
                     $this->_syntax_error("(secure mode) super global access not permitted",
2104
-                                         E_USER_WARNING, __FILE__, __LINE__);
2104
+                                            E_USER_WARNING, __FILE__, __LINE__);
2105 2105
                     return;
2106 2106
                 }
2107 2107
                 $compiled_ref = "\$_SESSION";
@@ -2114,7 +2114,7 @@  discard block
 block discarded – undo
2114 2114
             case 'request':
2115 2115
                 if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) {
2116 2116
                     $this->_syntax_error("(secure mode) super global access not permitted",
2117
-                                         E_USER_WARNING, __FILE__, __LINE__);
2117
+                                            E_USER_WARNING, __FILE__, __LINE__);
2118 2118
                     return;
2119 2119
                 }
2120 2120
                 if ($this->request_use_auto_globals) {
@@ -2141,7 +2141,7 @@  discard block
 block discarded – undo
2141 2141
             case 'const':
2142 2142
                 if ($this->security && !$this->security_settings['ALLOW_CONSTANTS']) {
2143 2143
                     $this->_syntax_error("(secure mode) constants not permitted",
2144
-                                         E_USER_WARNING, __FILE__, __LINE__);
2144
+                                            E_USER_WARNING, __FILE__, __LINE__);
2145 2145
                     return;
2146 2146
                 }
2147 2147
                 array_shift($indexes);
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
                 return ((is_object($this->_plugins[$type][$name][0][0])) ?
2198 2198
                         "\$this->_plugins['$type']['$name'][0][0]->"    /* method callback */
2199 2199
                         : (string)($this->_plugins[$type][$name][0][0]).'::'    /* class callback */
2200
-                       ). $this->_plugins[$type][$name][0][1];
2200
+                        ). $this->_plugins[$type][$name][0][1];
2201 2201
 
2202 2202
             } else {
2203 2203
                 /* function callback */
@@ -2342,7 +2342,7 @@  discard block
 block discarded – undo
2342 2342
             $message = " expected {/$_open_tag} (opened line $_line_no).";
2343 2343
         }
2344 2344
         $this->_syntax_error("mismatched tag {/$close_tag}.$message",
2345
-                             E_USER_ERROR, __FILE__, __LINE__);
2345
+                                E_USER_ERROR, __FILE__, __LINE__);
2346 2346
     }
2347 2347
 
2348 2348
 }
Please login to merge, or discard this patch.
Spacing   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -38,41 +38,41 @@  discard block
 block discarded – undo
38 38
     /**#@+
39 39
      * @access private
40 40
      */
41
-    var $_folded_blocks         =   array();    // keeps folded template blocks
42
-    var $_current_file          =   null;       // the current template being compiled
43
-    var $_current_line_no       =   1;          // line number for error messages
44
-    var $_capture_stack         =   array();    // keeps track of nested capture buffers
45
-    var $_plugin_info           =   array();    // keeps track of plugins to load
46
-    var $_init_smarty_vars      =   false;
47
-    var $_permitted_tokens      =   array('true','false','yes','no','on','off','null');
48
-    var $_db_qstr_regexp        =   null;        // regexps are setup in the constructor
49
-    var $_si_qstr_regexp        =   null;
50
-    var $_qstr_regexp           =   null;
51
-    var $_func_regexp           =   null;
52
-    var $_reg_obj_regexp        =   null;
53
-    var $_var_bracket_regexp    =   null;
54
-    var $_num_const_regexp      =   null;
55
-    var $_dvar_guts_regexp      =   null;
56
-    var $_dvar_regexp           =   null;
57
-    var $_cvar_regexp           =   null;
58
-    var $_svar_regexp           =   null;
59
-    var $_avar_regexp           =   null;
60
-    var $_mod_regexp            =   null;
61
-    var $_var_regexp            =   null;
62
-    var $_parenth_param_regexp  =   null;
63
-    var $_func_call_regexp      =   null;
64
-    var $_obj_ext_regexp        =   null;
65
-    var $_obj_start_regexp      =   null;
66
-    var $_obj_params_regexp     =   null;
67
-    var $_obj_call_regexp       =   null;
68
-    var $_cacheable_state       =   0;
69
-    var $_cache_attrs_count     =   0;
70
-    var $_nocache_count         =   0;
71
-    var $_cache_serial          =   null;
72
-    var $_cache_include         =   null;
73
-
74
-    var $_strip_depth           =   0;
75
-    var $_additional_newline    =   "\n";
41
+    var $_folded_blocks         = array(); // keeps folded template blocks
42
+    var $_current_file          = null; // the current template being compiled
43
+    var $_current_line_no       = 1; // line number for error messages
44
+    var $_capture_stack         = array(); // keeps track of nested capture buffers
45
+    var $_plugin_info           = array(); // keeps track of plugins to load
46
+    var $_init_smarty_vars      = false;
47
+    var $_permitted_tokens      = array('true', 'false', 'yes', 'no', 'on', 'off', 'null');
48
+    var $_db_qstr_regexp        = null; // regexps are setup in the constructor
49
+    var $_si_qstr_regexp        = null;
50
+    var $_qstr_regexp           = null;
51
+    var $_func_regexp           = null;
52
+    var $_reg_obj_regexp        = null;
53
+    var $_var_bracket_regexp    = null;
54
+    var $_num_const_regexp      = null;
55
+    var $_dvar_guts_regexp      = null;
56
+    var $_dvar_regexp           = null;
57
+    var $_cvar_regexp           = null;
58
+    var $_svar_regexp           = null;
59
+    var $_avar_regexp           = null;
60
+    var $_mod_regexp            = null;
61
+    var $_var_regexp            = null;
62
+    var $_parenth_param_regexp  = null;
63
+    var $_func_call_regexp      = null;
64
+    var $_obj_ext_regexp        = null;
65
+    var $_obj_start_regexp      = null;
66
+    var $_obj_params_regexp     = null;
67
+    var $_obj_call_regexp       = null;
68
+    var $_cacheable_state       = 0;
69
+    var $_cache_attrs_count     = 0;
70
+    var $_nocache_count         = 0;
71
+    var $_cache_serial          = null;
72
+    var $_cache_include         = null;
73
+
74
+    var $_strip_depth           = 0;
75
+    var $_additional_newline    = "\n";
76 76
 
77 77
     /**#@-*/
78 78
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $this->_si_qstr_regexp = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
92 92
 
93 93
         // matches single or double quoted strings
94
-        $this->_qstr_regexp = '(?:' . $this->_db_qstr_regexp . '|' . $this->_si_qstr_regexp . ')';
94
+        $this->_qstr_regexp = '(?:'.$this->_db_qstr_regexp.'|'.$this->_si_qstr_regexp.')';
95 95
 
96 96
         // matches bracket portion of vars
97 97
         // [0]
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
         // $foo[5].bar[$foobar][4]
116 116
         $this->_dvar_math_regexp = '(?:[\+\*\/\%]|(?:-(?!>)))';
117 117
         $this->_dvar_math_var_regexp = '[\$\w\.\+\-\*\/\%\d\>\[\]]';
118
-        $this->_dvar_guts_regexp = '\w+(?:' . $this->_var_bracket_regexp
119
-                . ')*(?:\.\$?\w+(?:' . $this->_var_bracket_regexp . ')*)*(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?';
120
-        $this->_dvar_regexp = '\$' . $this->_dvar_guts_regexp;
118
+        $this->_dvar_guts_regexp = '\w+(?:'.$this->_var_bracket_regexp
119
+                . ')*(?:\.\$?\w+(?:'.$this->_var_bracket_regexp.')*)*(?:'.$this->_dvar_math_regexp.'(?:'.$this->_num_const_regexp.'|'.$this->_dvar_math_var_regexp.')*)?';
120
+        $this->_dvar_regexp = '\$'.$this->_dvar_guts_regexp;
121 121
 
122 122
         // matches config vars:
123 123
         // #foo#
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
         $this->_svar_regexp = '\%\w+\.\w+\%';
130 130
 
131 131
         // matches all valid variables (no quotes, no modifiers)
132
-        $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|'
133
-           . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')';
132
+        $this->_avar_regexp = '(?:'.$this->_dvar_regexp.'|'
133
+           . $this->_cvar_regexp.'|'.$this->_svar_regexp.')';
134 134
 
135 135
         // matches valid variable syntax:
136 136
         // $foo
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         // #foo#
140 140
         // "text"
141 141
         // "text"
142
-        $this->_var_regexp = '(?:' . $this->_avar_regexp . '|' . $this->_qstr_regexp . ')';
142
+        $this->_var_regexp = '(?:'.$this->_avar_regexp.'|'.$this->_qstr_regexp.')';
143 143
 
144 144
         // matches valid object call (one level of object nesting allowed in parameters):
145 145
         // $foo->bar
@@ -152,16 +152,16 @@  discard block
 block discarded – undo
152 152
         // $foo->bar($foo->bar)
153 153
         // $foo->bar($foo->bar())
154 154
         // $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
155
-        $this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
155
+        $this->_obj_ext_regexp = '\->(?:\$?'.$this->_dvar_guts_regexp.')';
156 156
         $this->_obj_restricted_param_regexp = '(?:'
157
-                . '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')'
158
-                . '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)';
159
-        $this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
160
-                . $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
161
-        $this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
162
-                . '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
163
-        $this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
164
-        $this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)';
157
+                . '(?:'.$this->_var_regexp.'|'.$this->_num_const_regexp.')(?:'.$this->_obj_ext_regexp.'(?:\((?:(?:'.$this->_var_regexp.'|'.$this->_num_const_regexp.')'
158
+                . '(?:\s*,\s*(?:'.$this->_var_regexp.'|'.$this->_num_const_regexp.'))*)?\))?)*)';
159
+        $this->_obj_single_param_regexp = '(?:\w+|'.$this->_obj_restricted_param_regexp.'(?:\s*,\s*(?:(?:\w+|'
160
+                . $this->_var_regexp.$this->_obj_restricted_param_regexp.')))*)';
161
+        $this->_obj_params_regexp = '\((?:'.$this->_obj_single_param_regexp
162
+                . '(?:\s*,\s*'.$this->_obj_single_param_regexp.')*)?\)';
163
+        $this->_obj_start_regexp = '(?:'.$this->_dvar_regexp.'(?:'.$this->_obj_ext_regexp.')+)';
164
+        $this->_obj_call_regexp = '(?:'.$this->_obj_start_regexp.'(?:'.$this->_obj_params_regexp.')?(?:'.$this->_dvar_math_regexp.'(?:'.$this->_num_const_regexp.'|'.$this->_dvar_math_var_regexp.')*)?)';
165 165
         
166 166
         // matches valid modifier syntax:
167 167
         // |foo
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
         // |foo:"bar":$foobar
172 172
         // |foo|bar
173 173
         // |foo:$foo->bar
174
-        $this->_mod_regexp = '(?:\|@?\w+(?::(?:\w+|' . $this->_num_const_regexp . '|'
175
-           . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)';
174
+        $this->_mod_regexp = '(?:\|@?\w+(?::(?:\w+|'.$this->_num_const_regexp.'|'
175
+           . $this->_obj_call_regexp.'|'.$this->_avar_regexp.'|'.$this->_qstr_regexp.'))*)';
176 176
 
177 177
         // matches valid function name:
178 178
         // foo123
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
         // "text"
193 193
         // "text"|bar
194 194
         // $foo->bar
195
-        $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|'
196
-           . $this->_var_regexp . '|' . $this->_num_const_regexp  . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)';
195
+        $this->_param_regexp = '(?:\s*(?:'.$this->_obj_call_regexp.'|'
196
+           . $this->_var_regexp.'|'.$this->_num_const_regexp.'|\w+)(?>'.$this->_mod_regexp.'*)\s*)';
197 197
 
198 198
         // matches valid parenthesised function parameters:
199 199
         //
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
         //    $foo, $bar, "text"
202 202
         // $foo|bar, "foo"|bar, $foo->bar($foo)|bar
203 203
         $this->_parenth_param_regexp = '(?:\((?:\w+|'
204
-                . $this->_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
205
-                . $this->_param_regexp . ')))*)?\))';
204
+                . $this->_param_regexp.'(?:\s*,\s*(?:(?:\w+|'
205
+                . $this->_param_regexp.')))*)?\))';
206 206
 
207 207
         // matches valid function call:
208 208
         // foo()
209 209
         // foo_bar($foo)
210 210
         // _foo_bar($foo,"bar")
211 211
         // foo123($foo,$foo->bar(),"foo")
212
-        $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:'
213
-           . $this->_parenth_param_regexp . '))';
212
+        $this->_func_call_regexp = '(?:'.$this->_func_regexp.'\s*(?:'
213
+           . $this->_parenth_param_regexp.'))';
214 214
     }
215 215
 
216 216
     /**
@@ -257,13 +257,13 @@  discard block
 block discarded – undo
257 257
         /* fetch all special blocks */
258 258
         $search = "~{$ldq}\*(.*?)\*{$rdq}|{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}|{$ldq}\s*php\s*{$rdq}(.*?){$ldq}\s*/php\s*{$rdq}~s";
259 259
 
260
-        preg_match_all($search, $source_content, $match,  PREG_SET_ORDER);
260
+        preg_match_all($search, $source_content, $match, PREG_SET_ORDER);
261 261
         $this->_folded_blocks = $match;
262 262
         reset($this->_folded_blocks);
263 263
 
264 264
         /* replace special blocks by "{php}" */
265
-        $source_content = preg_replace_callback($search, create_function ('$matches', "return '"
266
-                                       . $this->_quote_replace($this->left_delimiter) . 'php'
265
+        $source_content = preg_replace_callback($search, create_function('$matches', "return '"
266
+                                       . $this->_quote_replace($this->left_delimiter).'php'
267 267
                                        . "' . str_repeat(\"\n\", substr_count('\$matches[1]', \"\n\")) .'"
268 268
                                        . $this->_quote_replace($this->right_delimiter)
269 269
                                        . "';")
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $sp_match[1] = array_unique($sp_match[1]);
284 284
                 usort($sp_match[1], '_smarty_sort_length');
285 285
                 for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++) {
286
-                    $text_blocks[$curr_tb] = str_replace($sp_match[1][$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$text_blocks[$curr_tb]);
286
+                    $text_blocks[$curr_tb] = str_replace($sp_match[1][$curr_sp], '%%%SMARTYSP'.$curr_sp.'%%%', $text_blocks[$curr_tb]);
287 287
                 }
288 288
                 /* process each one */
289 289
                 for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++) {
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
             $compiled_tags[] = $this->_compile_tag($template_tags[$i]);
313 313
             $this->_current_line_no += substr_count($template_tags[$i], "\n");
314 314
         }
315
-        if (count($this->_tag_stack)>0) {
315
+        if (count($this->_tag_stack) > 0) {
316 316
             list($_open_tag, $_line_no) = end($this->_tag_stack);
317 317
             $this->_syntax_error("unclosed tag \{$_open_tag} (opened line $_line_no).", E_USER_ERROR, __FILE__, __LINE__);
318 318
             return;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                         /* remove trailing whitespaces from the last text_block */
338 338
                         $text_blocks[$j] = rtrim($text_blocks[$j]);
339 339
                     }
340
-                    $text_blocks[$j] = "<?php echo '" . strtr($text_blocks[$j], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>";
340
+                    $text_blocks[$j] = "<?php echo '".strtr($text_blocks[$j], array("'"=>"\'", "\\"=>"\\\\"))."'; ?>";
341 341
                     if ($compiled_tags[$j] == '{/strip}') {
342 342
                         $compiled_tags[$j] = "\n"; /* slurped by php, but necessary
343 343
                                     if a newline is following the closing strip-tag */
@@ -350,19 +350,19 @@  discard block
 block discarded – undo
350 350
         }
351 351
         $compiled_content = '';
352 352
         
353
-        $tag_guard = '%%%SMARTYOTG' . md5(uniqid(rand(), true)) . '%%%';
353
+        $tag_guard = '%%%SMARTYOTG'.md5(uniqid(rand(), true)).'%%%';
354 354
         
355 355
         /* Interleave the compiled contents and text blocks to get the final result. */
356 356
         for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
357 357
             if ($compiled_tags[$i] == '') {
358 358
                 // tag result empty, remove first newline from following text block
359
-                $text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]);
359
+                $text_blocks[$i + 1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i + 1]);
360 360
             }
361 361
             // replace legit PHP tags with placeholder
362 362
             $text_blocks[$i] = str_replace('<?', $tag_guard, $text_blocks[$i]);
363 363
             $compiled_tags[$i] = str_replace('<?', $tag_guard, $compiled_tags[$i]);
364 364
             
365
-            $compiled_content .= $text_blocks[$i] . $compiled_tags[$i];
365
+            $compiled_content .= $text_blocks[$i].$compiled_tags[$i];
366 366
         }
367 367
         $compiled_content .= str_replace('<?', $tag_guard, $text_blocks[$i]);
368 368
 
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
         $compiled_content = str_replace($tag_guard, '<?', $compiled_content); 
375 375
         
376 376
         // remove \n from the end of the file, if any
377
-        if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) {
377
+        if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n")) {
378 378
             $compiled_content = substr($compiled_content, 0, -1);
379 379
         }
380 380
 
381 381
         if (!empty($this->_cache_serial)) {
382
-            $compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content;
382
+            $compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>".$compiled_content;
383 383
         }
384 384
 
385 385
         // run compiled template through postfilter functions
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
             $_plugins_params = "array('plugins' => array(";
407 407
             foreach ($this->_plugin_info as $plugin_type => $plugins) {
408 408
                 foreach ($plugins as $plugin_name => $plugin_info) {
409
-                    $_plugins_params .= "array('$plugin_type', '$plugin_name', '" . strtr($plugin_info[0], array("'" => "\\'", "\\" => "\\\\")) . "', $plugin_info[1], ";
409
+                    $_plugins_params .= "array('$plugin_type', '$plugin_name', '".strtr($plugin_info[0], array("'" => "\\'", "\\" => "\\\\"))."', $plugin_info[1], ";
410 410
                     $_plugins_params .= $plugin_info[2] ? 'true),' : 'false),';
411 411
                 }
412 412
             }
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
             $this->_init_smarty_vars = false;
423 423
         }
424 424
 
425
-        $compiled_content = $template_header . $compiled_content;
425
+        $compiled_content = $template_header.$compiled_content;
426 426
         return true;
427 427
     }
428 428
 
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
             return '';
440 440
         
441 441
         /* Split tag into two three parts: command, command modifiers and the arguments. */
442
-        if(! preg_match('~^(?:(' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp
443
-                . '|\/?' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*))
442
+        if (!preg_match('~^(?:('.$this->_num_const_regexp.'|'.$this->_obj_call_regexp.'|'.$this->_var_regexp
443
+                . '|\/?'.$this->_reg_obj_regexp.'|\/?'.$this->_func_regexp.')('.$this->_mod_regexp.'*))
444 444
                       (?:\s+(.*))?$
445 445
                     ~xs', $template_tag, $match)) {
446 446
             $this->_syntax_error("unrecognized tag: $template_tag", E_USER_ERROR, __FILE__, __LINE__);
@@ -450,14 +450,14 @@  discard block
 block discarded – undo
450 450
         $tag_modifier = isset($match[2]) ? $match[2] : null;
451 451
         $tag_args = isset($match[3]) ? $match[3] : null;
452 452
 
453
-        if (preg_match('~^' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '$~', $tag_command)) {
453
+        if (preg_match('~^'.$this->_num_const_regexp.'|'.$this->_obj_call_regexp.'|'.$this->_var_regexp.'$~', $tag_command)) {
454 454
             /* tag name is a variable or object */
455
-            $_return = $this->_parse_var_props($tag_command . $tag_modifier);
456
-            return "<?php echo $_return; ?>" . $this->_additional_newline;
455
+            $_return = $this->_parse_var_props($tag_command.$tag_modifier);
456
+            return "<?php echo $_return; ?>".$this->_additional_newline;
457 457
         }
458 458
 
459 459
         /* If the tag name is a registered object, we process it. */
460
-        if (preg_match('~^\/?' . $this->_reg_obj_regexp . '$~', $tag_command)) {
460
+        if (preg_match('~^\/?'.$this->_reg_obj_regexp.'$~', $tag_command)) {
461 461
             return $this->_compile_registered_object_tag($tag_command, $this->_parse_attrs($tag_args), $tag_modifier);
462 462
         }
463 463
 
@@ -539,17 +539,17 @@  discard block
 block discarded – undo
539 539
 
540 540
             case 'strip':
541 541
             case '/strip':
542
-                if (substr($tag_command, 0, 1)=='/') {
542
+                if (substr($tag_command, 0, 1) == '/') {
543 543
                     $this->_pop_tag('strip');
544
-                    if (--$this->_strip_depth==0) { /* outermost closing {/strip} */
544
+                    if (--$this->_strip_depth == 0) { /* outermost closing {/strip} */
545 545
                         $this->_additional_newline = "\n";
546
-                        return '{' . $tag_command . '}';
546
+                        return '{'.$tag_command.'}';
547 547
                     }
548 548
                 } else {
549 549
                     $this->_push_tag('strip');
550
-                    if ($this->_strip_depth++==0) { /* outermost opening {strip} */
550
+                    if ($this->_strip_depth++ == 0) { /* outermost opening {strip} */
551 551
                         $this->_additional_newline = "";
552
-                        return '{' . $tag_command . '}';
552
+                        return '{'.$tag_command.'}';
553 553
                     }
554 554
                 }
555 555
                 return '';
@@ -565,14 +565,14 @@  discard block
 block discarded – undo
565 565
                         return '';
566 566
 
567 567
                     case 3: /* literal */
568
-                        return "<?php echo '" . strtr($block[2], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>" . $this->_additional_newline;
568
+                        return "<?php echo '".strtr($block[2], array("'"=>"\'", "\\"=>"\\\\"))."'; ?>".$this->_additional_newline;
569 569
 
570 570
                     case 4: /* php */
571 571
                         if ($this->security && !$this->security_settings['PHP_TAGS']) {
572 572
                             $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);
573 573
                             return;
574 574
                         }
575
-                        return '<?php ' . $block[3] .' ?>';
575
+                        return '<?php '.$block[3].' ?>';
576 576
                 }
577 577
                 break;
578 578
 
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 
630 630
             include_once $plugin_file;
631 631
 
632
-            $plugin_func = 'smarty_compiler_' . $tag_command;
632
+            $plugin_func = 'smarty_compiler_'.$tag_command;
633 633
             if (!is_callable($plugin_func)) {
634 634
                 $message = "plugin function $plugin_func() not found in $plugin_file\n";
635 635
                 $have_function = false;
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
         if ($found) {
648 648
             if ($have_function) {
649 649
                 $output = call_user_func_array($plugin_func, array($tag_args, &$this));
650
-                if($output != '') {
651
-                $output = '<?php ' . $this->_push_cacheable_state('compiler', $tag_command)
650
+                if ($output != '') {
651
+                $output = '<?php '.$this->_push_cacheable_state('compiler', $tag_command)
652 652
                                    . $output
653
-                                   . $this->_pop_cacheable_state('compiler', $tag_command) . ' ?>';
653
+                                   . $this->_pop_cacheable_state('compiler', $tag_command).' ?>';
654 654
                 }
655 655
             } else {
656 656
                 $this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__);
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 
705 705
             include_once $plugin_file;
706 706
 
707
-            $plugin_func = 'smarty_block_' . $tag_command;
707
+            $plugin_func = 'smarty_block_'.$tag_command;
708 708
             if (!function_exists($plugin_func)) {
709 709
                 $message = "plugin function $plugin_func() not found in $plugin_file\n";
710 710
                 $have_function = false;
@@ -734,12 +734,12 @@  discard block
 block discarded – undo
734 734
             $this->_pop_tag($tag_command);
735 735
 
736 736
         if ($start_tag) {
737
-            $output = '<?php ' . $this->_push_cacheable_state('block', $tag_command);
737
+            $output = '<?php '.$this->_push_cacheable_state('block', $tag_command);
738 738
             $attrs = $this->_parse_attrs($tag_args);
739
-            $_cache_attrs='';
739
+            $_cache_attrs = '';
740 740
             $arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs);
741 741
             $output .= "$_cache_attrs\$this->_tag_stack[] = array('$tag_command', array(".implode(',', $arg_list).')); ';
742
-            $output .= '$_block_repeat=true;' . $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat);';
742
+            $output .= '$_block_repeat=true;'.$this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat);';
743 743
             $output .= 'while ($_block_repeat) { ob_start(); ?>';
744 744
         } else {
745 745
             $output = '<?php $_block_content = ob_get_contents(); ob_end_clean(); ';
@@ -747,8 +747,8 @@  discard block
 block discarded – undo
747 747
             if ($tag_modifier != '') {
748 748
                 $this->_parse_modifiers($_out_tag_text, $tag_modifier);
749 749
             }
750
-            $output .= '$_block_repeat=false;echo ' . $_out_tag_text . '; } ';
751
-            $output .= " array_pop(\$this->_tag_stack); " . $this->_pop_cacheable_state('block', $tag_command) . '?>';
750
+            $output .= '$_block_repeat=false;echo '.$_out_tag_text.'; } ';
751
+            $output .= " array_pop(\$this->_tag_stack); ".$this->_pop_cacheable_state('block', $tag_command).'?>';
752 752
         }
753 753
 
754 754
         return true;
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 
790 790
             include_once $plugin_file;
791 791
 
792
-            $plugin_func = 'smarty_function_' . $tag_command;
792
+            $plugin_func = 'smarty_function_'.$tag_command;
793 793
             if (!function_exists($plugin_func)) {
794 794
                 $message = "plugin function $plugin_func() not found in $plugin_file\n";
795 795
                 $have_function = false;
@@ -816,13 +816,13 @@  discard block
 block discarded – undo
816 816
         $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs);
817 817
 
818 818
         $output = $this->_compile_plugin_call('function', $tag_command).'(array('.implode(',', $arg_list)."), \$this)";
819
-        if($tag_modifier != '') {
819
+        if ($tag_modifier != '') {
820 820
             $this->_parse_modifiers($output, $tag_modifier);
821 821
         }
822 822
 
823
-        if($output != '') {
824
-            $output =  '<?php ' . $_cacheable_state . $_cache_attrs . 'echo ' . $output . ';'
825
-                . $this->_pop_cacheable_state('function', $tag_command) . "?>" . $this->_additional_newline;
823
+        if ($output != '') {
824
+            $output = '<?php '.$_cacheable_state.$_cache_attrs.'echo '.$output.';'
825
+                . $this->_pop_cacheable_state('function', $tag_command)."?>".$this->_additional_newline;
826 826
         }
827 827
 
828 828
         return true;
@@ -848,10 +848,10 @@  discard block
 block discarded – undo
848 848
         list($object, $obj_comp) = explode('->', $tag_command);
849 849
 
850 850
         $arg_list = array();
851
-        if(count($attrs)) {
851
+        if (count($attrs)) {
852 852
             $_assign_var = false;
853 853
             foreach ($attrs as $arg_name => $arg_value) {
854
-                if($arg_name == 'assign') {
854
+                if ($arg_name == 'assign') {
855 855
                     $_assign_var = $arg_value;
856 856
                     unset($attrs['assign']);
857 857
                     continue;
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
             }
863 863
         }
864 864
 
865
-        if($this->_reg_objects[$object][2]) {
865
+        if ($this->_reg_objects[$object][2]) {
866 866
             // smarty object argument format
867 867
             $args = "array(".implode(',', (array)$arg_list)."), \$this";
868 868
         } else {
@@ -876,13 +876,13 @@  discard block
 block discarded – undo
876 876
         $prefix = '';
877 877
         $postfix = '';
878 878
         $newline = '';
879
-        if(!is_object($this->_reg_objects[$object][0])) {
880
-            $this->_trigger_fatal_error("registered '$object' is not an object" , $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
881
-        } elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) {
879
+        if (!is_object($this->_reg_objects[$object][0])) {
880
+            $this->_trigger_fatal_error("registered '$object' is not an object", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
881
+        } elseif (!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) {
882 882
             $this->_trigger_fatal_error("'$obj_comp' is not a registered component of object '$object'", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
883
-        } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
883
+        } elseif (method_exists($this->_reg_objects[$object][0], $obj_comp)) {
884 884
             // method
885
-            if(in_array($obj_comp, $this->_reg_objects[$object][3])) {
885
+            if (in_array($obj_comp, $this->_reg_objects[$object][3])) {
886 886
                 // block method
887 887
                 if ($start_tag) {
888 888
                     $prefix = "\$this->_tag_stack[] = array('$obj_comp', $args); ";
@@ -904,22 +904,22 @@  discard block
 block discarded – undo
904 904
             $return = "\$this->_reg_objects['$object'][0]->$obj_comp";
905 905
         }
906 906
 
907
-        if($return != null) {
908
-            if($tag_modifier != '') {
907
+        if ($return != null) {
908
+            if ($tag_modifier != '') {
909 909
                 $this->_parse_modifiers($return, $tag_modifier);
910 910
             }
911 911
 
912
-            if(!empty($_assign_var)) {
913
-                $output = "\$this->assign('" . $this->_dequote($_assign_var) ."',  $return);";
912
+            if (!empty($_assign_var)) {
913
+                $output = "\$this->assign('".$this->_dequote($_assign_var)."',  $return);";
914 914
             } else {
915
-                $output = 'echo ' . $return . ';';
915
+                $output = 'echo '.$return.';';
916 916
                 $newline = $this->_additional_newline;
917 917
             }
918 918
         } else {
919 919
             $output = '';
920 920
         }
921 921
 
922
-        return '<?php ' . $prefix . $output . $postfix . "?>" . $newline;
922
+        return '<?php '.$prefix.$output.$postfix."?>".$newline;
923 923
     }
924 924
 
925 925
     /**
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 
958 958
         $_params = "array('args' => array(".implode(', ', (array)$arg_list)."))";
959 959
 
960
-        return "<?php require_once(SMARTY_CORE_DIR . 'core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>" . $this->_additional_newline;
960
+        return "<?php require_once(SMARTY_CORE_DIR . 'core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>".$this->_additional_newline;
961 961
     }
962 962
 
963 963
     /**
@@ -992,8 +992,8 @@  discard block
 block discarded – undo
992 992
             $arg_list[] = "'$arg_name' => $arg_value";
993 993
         }
994 994
 
995
-        if ( $theme_template == 'true' )
996
-            $include_file = '"'.SugarThemeRegistry::current()->getTemplate(str_replace(array('"',"'"),'',$include_file)).'"';
995
+        if ($theme_template == 'true')
996
+            $include_file = '"'.SugarThemeRegistry::current()->getTemplate(str_replace(array('"', "'"), '', $include_file)).'"';
997 997
 
998 998
         $output = '<?php ';
999 999
 
@@ -1005,13 +1005,13 @@  discard block
 block discarded – undo
1005 1005
             "\$_smarty_tpl_vars = \$this->_tpl_vars;\n";
1006 1006
 
1007 1007
 
1008
-        $_params = "array('smarty_include_tpl_file' => " . $include_file . ", 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))";
1009
-        $output .= "\$this->_smarty_include($_params);\n" .
1010
-        "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
1008
+        $_params = "array('smarty_include_tpl_file' => ".$include_file.", 'smarty_include_vars' => array(".implode(',', (array)$arg_list)."))";
1009
+        $output .= "\$this->_smarty_include($_params);\n".
1010
+        "\$this->_tpl_vars = \$_smarty_tpl_vars;\n".
1011 1011
         "unset(\$_smarty_tpl_vars);\n";
1012 1012
 
1013 1013
         if (isset($assign_var)) {
1014
-            $output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n";
1014
+            $output .= "\$this->assign(".$assign_var.", ob_get_contents()); ob_end_clean();\n";
1015 1015
         }
1016 1016
 
1017 1017
         $output .= ' ?>';
@@ -1035,20 +1035,20 @@  discard block
 block discarded – undo
1035 1035
         }
1036 1036
 
1037 1037
         $assign_var = (empty($attrs['assign'])) ? '' : $this->_dequote($attrs['assign']);
1038
-        $once_var = (empty($attrs['once']) || $attrs['once']=='false') ? 'false' : 'true';
1038
+        $once_var = (empty($attrs['once']) || $attrs['once'] == 'false') ? 'false' : 'true';
1039 1039
 
1040 1040
         $arg_list = array();
1041
-        foreach($attrs as $arg_name => $arg_value) {
1042
-            if($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') {
1043
-                if(is_bool($arg_value))
1041
+        foreach ($attrs as $arg_name => $arg_value) {
1042
+            if ($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') {
1043
+                if (is_bool($arg_value))
1044 1044
                     $arg_value = $arg_value ? 'true' : 'false';
1045 1045
                 $arg_list[] = "'$arg_name' => $arg_value";
1046 1046
             }
1047 1047
         }
1048 1048
 
1049
-        $_params = "array('smarty_file' => " . $attrs['file'] . ", 'smarty_assign' => '$assign_var', 'smarty_once' => $once_var, 'smarty_include_vars' => array(".implode(',', $arg_list)."))";
1049
+        $_params = "array('smarty_file' => ".$attrs['file'].", 'smarty_assign' => '$assign_var', 'smarty_once' => $once_var, 'smarty_include_vars' => array(".implode(',', $arg_list)."))";
1050 1050
 
1051
-        return "<?php require_once(SMARTY_CORE_DIR . 'core.smarty_include_php.php');\nsmarty_core_smarty_include_php($_params, \$this); ?>" . $this->_additional_newline;
1051
+        return "<?php require_once(SMARTY_CORE_DIR . 'core.smarty_include_php.php');\nsmarty_core_smarty_include_php($_params, \$this); ?>".$this->_additional_newline;
1052 1052
     }
1053 1053
 
1054 1054
 
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
         if (!isset($attrs['max']))
1115 1115
             $output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
1116 1116
         else
1117
-            $output .= "if ({$section_props}['max'] < 0)\n" .
1117
+            $output .= "if ({$section_props}['max'] < 0)\n".
1118 1118
                        "    {$section_props}['max'] = {$section_props}['loop'];\n";
1119 1119
 
1120 1120
         if (!isset($attrs['step']))
@@ -1123,9 +1123,9 @@  discard block
 block discarded – undo
1123 1123
         if (!isset($attrs['start']))
1124 1124
             $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
1125 1125
         else {
1126
-            $output .= "if ({$section_props}['start'] < 0)\n" .
1127
-                       "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" .
1128
-                       "else\n" .
1126
+            $output .= "if ({$section_props}['start'] < 0)\n".
1127
+                       "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n".
1128
+                       "else\n".
1129 1129
                        "    {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
1130 1130
         }
1131 1131
 
@@ -1135,9 +1135,9 @@  discard block
 block discarded – undo
1135 1135
         } else {
1136 1136
             $output .= "    {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
1137 1137
         }
1138
-        $output .= "    if ({$section_props}['total'] == 0)\n" .
1139
-                   "        {$section_props}['show'] = false;\n" .
1140
-                   "} else\n" .
1138
+        $output .= "    if ({$section_props}['total'] == 0)\n".
1139
+                   "        {$section_props}['show'] = false;\n".
1140
+                   "} else\n".
1141 1141
                    "    {$section_props}['total'] = 0;\n";
1142 1142
 
1143 1143
         $output .= "if ({$section_props}['show']):\n";
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
         }
1183 1183
 
1184 1184
         if (isset($attrs['key'])) {
1185
-            $key  = $this->_dequote($attrs['key']);
1185
+            $key = $this->_dequote($attrs['key']);
1186 1186
             if (!preg_match('~^\w+$~', $key)) {
1187 1187
                 return $this->_syntax_error("foreach: 'key' must to be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__);
1188 1188
             }
@@ -1262,8 +1262,8 @@  discard block
 block discarded – undo
1262 1262
 
1263 1263
         /* Tokenize args for 'if' tag. */
1264 1264
         preg_match_all('~(?>
1265
-                ' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)? | # valid object call
1266
-                ' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)?    | # var or quoted string
1265
+                ' . $this->_obj_call_regexp.'(?:'.$this->_mod_regexp.'*)? | # valid object call
1266
+                ' . $this->_var_regexp.'(?:'.$this->_mod_regexp.'*)?    | # var or quoted string
1267 1267
                 \-?0[xX][0-9a-fA-F]+|\-?\d+(?:\.\d+)?|\.\d+|!==|===|==|!=|<>|<<|>>|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@    | # valid non-word token
1268 1268
                 \b\w+\b                                                        | # valid word token
1269 1269
                 \S+                                                           # anything else
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
 
1272 1272
         $tokens = $match[0];
1273 1273
 
1274
-        if(empty($tokens)) {
1274
+        if (empty($tokens)) {
1275 1275
             $_error_msg = $elseif ? "'elseif'" : "'if'";
1276 1276
             $_error_msg .= ' statement requires arguments'; 
1277 1277
             $this->_syntax_error($_error_msg, E_USER_ERROR, __FILE__, __LINE__);
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
                 
1281 1281
         // make sure we have balanced parenthesis
1282 1282
         $token_count = array_count_values($tokens);
1283
-        if(isset($token_count['(']) && $token_count['('] != $token_count[')']) {
1283
+        if (isset($token_count['(']) && $token_count['('] != $token_count[')']) {
1284 1284
             $this->_syntax_error("unbalanced parenthesis in if statement", E_USER_ERROR, __FILE__, __LINE__);
1285 1285
         }
1286 1286
 
@@ -1370,15 +1370,15 @@  discard block
 block discarded – undo
1370 1370
                     /* If last token was a ')', we operate on the parenthesized
1371 1371
                        expression. The start of the expression is on the stack.
1372 1372
                        Otherwise, we operate on the last encountered token. */
1373
-                    if ($tokens[$i-1] == ')') {
1373
+                    if ($tokens[$i - 1] == ')') {
1374 1374
                         $is_arg_start = array_pop($is_arg_stack);
1375 1375
                         if ($is_arg_start != 0) {
1376
-                            if (preg_match('~^' . $this->_func_regexp . '$~', $tokens[$is_arg_start-1])) {
1376
+                            if (preg_match('~^'.$this->_func_regexp.'$~', $tokens[$is_arg_start - 1])) {
1377 1377
                                 $is_arg_start--;
1378 1378
                             } 
1379 1379
                         } 
1380 1380
                     } else
1381
-                        $is_arg_start = $i-1;
1381
+                        $is_arg_start = $i - 1;
1382 1382
                     /* Construct the argument for 'is' expression, so it knows
1383 1383
                        what to operate on. */
1384 1384
                     $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
                        return modified tokens, where the first one is the result
1389 1389
                        of the 'is' expression and the rest are the tokens it
1390 1390
                        didn't touch. */
1391
-                    $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
1391
+                    $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1));
1392 1392
 
1393 1393
                     /* Replace the old tokens with the new ones. */
1394 1394
                     array_splice($tokens, $is_arg_start, count($tokens), $new_tokens);
@@ -1399,19 +1399,19 @@  discard block
 block discarded – undo
1399 1399
                     break;
1400 1400
 
1401 1401
                 default:
1402
-                    if(preg_match('~^' . $this->_func_regexp . '$~', $token) ) {
1402
+                    if (preg_match('~^'.$this->_func_regexp.'$~', $token)) {
1403 1403
                             // function call
1404
-                            if($this->security &&
1404
+                            if ($this->security &&
1405 1405
                                !in_array($token, $this->security_settings['IF_FUNCS'])) {
1406 1406
                                 $this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__);
1407 1407
                             }
1408
-                    } elseif(preg_match('~^' . $this->_var_regexp . '$~', $token) && (strpos('+-*/^%&|', substr($token, -1)) === false) && isset($tokens[$i+1]) && $tokens[$i+1] == '(') {
1408
+                    } elseif (preg_match('~^'.$this->_var_regexp.'$~', $token) && (strpos('+-*/^%&|', substr($token, -1)) === false) && isset($tokens[$i + 1]) && $tokens[$i + 1] == '(') {
1409 1409
                         // variable function call
1410 1410
                         $this->_syntax_error("variable function call '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__);                      
1411
-                    } elseif(preg_match('~^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$~', $token)) {
1411
+                    } elseif (preg_match('~^'.$this->_obj_call_regexp.'|'.$this->_var_regexp.'(?:'.$this->_mod_regexp.'*)$~', $token)) {
1412 1412
                         // object or variable
1413 1413
                         $token = $this->_parse_var_props($token);
1414
-                    } elseif(is_numeric($token)) {
1414
+                    } elseif (is_numeric($token)) {
1415 1415
                         // number, skip it
1416 1416
                     } else {
1417 1417
                         $this->_syntax_error("unidentified token '$token'", E_USER_ERROR, __FILE__, __LINE__);
@@ -1483,7 +1483,7 @@  discard block
 block discarded – undo
1483 1483
                 if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') {
1484 1484
                     $expr_end++;
1485 1485
                     $expr_arg = $tokens[$expr_end++];
1486
-                    $expr = "!(1 & ($is_arg / " . $this->_parse_var_props($expr_arg) . "))";
1486
+                    $expr = "!(1 & ($is_arg / ".$this->_parse_var_props($expr_arg)."))";
1487 1487
                 } else
1488 1488
                     $expr = "!(1 & $is_arg)";
1489 1489
                 break;
@@ -1492,7 +1492,7 @@  discard block
 block discarded – undo
1492 1492
                 if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') {
1493 1493
                     $expr_end++;
1494 1494
                     $expr_arg = $tokens[$expr_end++];
1495
-                    $expr = "(1 & ($is_arg / " . $this->_parse_var_props($expr_arg) . "))";
1495
+                    $expr = "(1 & ($is_arg / ".$this->_parse_var_props($expr_arg)."))";
1496 1496
                 } else
1497 1497
                     $expr = "(1 & $is_arg)";
1498 1498
                 break;
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
                 if (@$tokens[$expr_end] == 'by') {
1502 1502
                     $expr_end++;
1503 1503
                     $expr_arg = $tokens[$expr_end++];
1504
-                    $expr = "!($is_arg % " . $this->_parse_var_props($expr_arg) . ")";
1504
+                    $expr = "!($is_arg % ".$this->_parse_var_props($expr_arg).")";
1505 1505
                 } else {
1506 1506
                     $this->_syntax_error("expecting 'by' after 'div'", E_USER_ERROR, __FILE__, __LINE__);
1507 1507
                 }
@@ -1532,11 +1532,11 @@  discard block
 block discarded – undo
1532 1532
     {
1533 1533
 
1534 1534
         /* Tokenize tag attributes. */
1535
-        preg_match_all('~(?:' . $this->_obj_call_regexp . '|' . $this->_qstr_regexp . ' | (?>[^"\'=\s]+)
1535
+        preg_match_all('~(?:'.$this->_obj_call_regexp.'|'.$this->_qstr_regexp.' | (?>[^"\'=\s]+)
1536 1536
                          )+ |
1537 1537
                          [=]
1538 1538
                         ~x', $tag_args, $match);
1539
-        $tokens       = $match[0];
1539
+        $tokens = $match[0];
1540 1540
 
1541 1541
         $attrs = array();
1542 1542
         /* Parse state:
@@ -1577,9 +1577,9 @@  discard block
 block discarded – undo
1577 1577
                             $token = 'false';
1578 1578
                         } else if ($token == 'null') {
1579 1579
                             $token = 'null';
1580
-                        } else if (preg_match('~^' . $this->_num_const_regexp . '|0[xX][0-9a-fA-F]+$~', $token)) {
1580
+                        } else if (preg_match('~^'.$this->_num_const_regexp.'|0[xX][0-9a-fA-F]+$~', $token)) {
1581 1581
                             /* treat integer literally */
1582
-                        } else if (!preg_match('~^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')*$~', $token)) {
1582
+                        } else if (!preg_match('~^'.$this->_obj_call_regexp.'|'.$this->_var_regexp.'(?:'.$this->_mod_regexp.')*$~', $token)) {
1583 1583
                             /* treat as a string, double-quote it escaping quotes */
1584 1584
                             $token = '"'.addslashes($token).'"';
1585 1585
                         }
@@ -1593,8 +1593,8 @@  discard block
 block discarded – undo
1593 1593
             $last_token = $token;
1594 1594
         }
1595 1595
 
1596
-        if($state != 0) {
1597
-            if($state == 1) {
1596
+        if ($state != 0) {
1597
+            if ($state == 1) {
1598 1598
                 $this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__);
1599 1599
             } else {
1600 1600
                 $this->_syntax_error("missing attribute value", E_USER_ERROR, __FILE__, __LINE__);
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
      */
1615 1615
     function _parse_vars_props(&$tokens)
1616 1616
     {
1617
-        foreach($tokens as $key => $val) {
1617
+        foreach ($tokens as $key => $val) {
1618 1618
             $tokens[$key] = $this->_parse_var_props($val);
1619 1619
         }
1620 1620
     }
@@ -1631,52 +1631,52 @@  discard block
 block discarded – undo
1631 1631
     {
1632 1632
         $val = trim($val);
1633 1633
 
1634
-        if(preg_match('~^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(' . $this->_mod_regexp . '*)$~', $val, $match)) {
1634
+        if (preg_match('~^('.$this->_obj_call_regexp.'|'.$this->_dvar_regexp.')('.$this->_mod_regexp.'*)$~', $val, $match)) {
1635 1635
             // $ variable or object
1636 1636
             $return = $this->_parse_var($match[1]);
1637 1637
             $modifiers = $match[2];
1638
-            if (!empty($this->default_modifiers) && !preg_match('~(^|\|)smarty:nodefaults($|\|)~',$modifiers)) {
1639
-                $_default_mod_string = implode('|',(array)$this->default_modifiers);
1640
-                $modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers;
1638
+            if (!empty($this->default_modifiers) && !preg_match('~(^|\|)smarty:nodefaults($|\|)~', $modifiers)) {
1639
+                $_default_mod_string = implode('|', (array)$this->default_modifiers);
1640
+                $modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string.'|'.$modifiers;
1641 1641
             }
1642 1642
             $this->_parse_modifiers($return, $modifiers);
1643 1643
             return $return;
1644
-        } elseif (preg_match('~^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1644
+        } elseif (preg_match('~^'.$this->_db_qstr_regexp.'(?:'.$this->_mod_regexp.'*)$~', $val)) {
1645 1645
                 // double quoted text
1646
-                preg_match('~^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . '*)$~', $val, $match);
1646
+                preg_match('~^('.$this->_db_qstr_regexp.')('.$this->_mod_regexp.'*)$~', $val, $match);
1647 1647
                 $return = $this->_expand_quoted_text($match[1]);
1648
-                if($match[2] != '') {
1648
+                if ($match[2] != '') {
1649 1649
                     $this->_parse_modifiers($return, $match[2]);
1650 1650
                 }
1651 1651
                 return $return;
1652 1652
             }
1653
-        elseif(preg_match('~^' . $this->_num_const_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1653
+        elseif (preg_match('~^'.$this->_num_const_regexp.'(?:'.$this->_mod_regexp.'*)$~', $val)) {
1654 1654
                 // numerical constant
1655
-                preg_match('~^(' . $this->_num_const_regexp . ')('. $this->_mod_regexp . '*)$~', $val, $match);
1656
-                if($match[2] != '') {
1655
+                preg_match('~^('.$this->_num_const_regexp.')('.$this->_mod_regexp.'*)$~', $val, $match);
1656
+                if ($match[2] != '') {
1657 1657
                     $this->_parse_modifiers($match[1], $match[2]);
1658 1658
                     return $match[1];
1659 1659
                 }
1660 1660
             }
1661
-        elseif(preg_match('~^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1661
+        elseif (preg_match('~^'.$this->_si_qstr_regexp.'(?:'.$this->_mod_regexp.'*)$~', $val)) {
1662 1662
                 // single quoted text
1663
-                preg_match('~^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . '*)$~', $val, $match);
1664
-                if($match[2] != '') {
1663
+                preg_match('~^('.$this->_si_qstr_regexp.')('.$this->_mod_regexp.'*)$~', $val, $match);
1664
+                if ($match[2] != '') {
1665 1665
                     $this->_parse_modifiers($match[1], $match[2]);
1666 1666
                     return $match[1];
1667 1667
                 }
1668 1668
             }
1669
-        elseif(preg_match('~^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1669
+        elseif (preg_match('~^'.$this->_cvar_regexp.'(?:'.$this->_mod_regexp.'*)$~', $val)) {
1670 1670
                 // config var
1671 1671
                 return $this->_parse_conf_var($val);
1672 1672
             }
1673
-        elseif(preg_match('~^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1673
+        elseif (preg_match('~^'.$this->_svar_regexp.'(?:'.$this->_mod_regexp.'*)$~', $val)) {
1674 1674
                 // section var
1675 1675
                 return $this->_parse_section_prop($val);
1676 1676
             }
1677
-        elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) {
1677
+        elseif (!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) {
1678 1678
             // literal string
1679
-            return $this->_expand_quoted_text('"' . strtr($val, array('\\' => '\\\\', '"' => '\\"')) .'"');
1679
+            return $this->_expand_quoted_text('"'.strtr($val, array('\\' => '\\\\', '"' => '\\"')).'"');
1680 1680
         }
1681 1681
         return $val;
1682 1682
     }
@@ -1690,11 +1690,11 @@  discard block
 block discarded – undo
1690 1690
     function _expand_quoted_text($var_expr)
1691 1691
     {
1692 1692
         // if contains unescaped $, expand it
1693
-        if(preg_match_all('~(?:\`(?<!\\\\)\$' . $this->_dvar_guts_regexp . '(?:' . $this->_obj_ext_regexp . ')*\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)~', $var_expr, $_match)) {
1693
+        if (preg_match_all('~(?:\`(?<!\\\\)\$'.$this->_dvar_guts_regexp.'(?:'.$this->_obj_ext_regexp.')*\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)~', $var_expr, $_match)) {
1694 1694
             $_match = $_match[0];
1695 1695
             $_replace = array();
1696
-            foreach($_match as $_var) {
1697
-                $_replace[$_var] = '".(' . $this->_parse_var(str_replace('`','',$_var)) . ')."';
1696
+            foreach ($_match as $_var) {
1697
+                $_replace[$_var] = '".('.$this->_parse_var(str_replace('`', '', $_var)).')."';
1698 1698
             }
1699 1699
             $var_expr = strtr($var_expr, $_replace);
1700 1700
             $_return = preg_replace('~\.""|(?<!\\\\)""\.~', '', $var_expr);
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
             $_return = $var_expr;
1703 1703
         }
1704 1704
         // replace double quoted literal string with single quotes
1705
-        $_return = preg_replace('~^"([\s\w]+)"$~',"'\\1'",$_return);
1705
+        $_return = preg_replace('~^"([\s\w]+)"$~', "'\\1'", $_return);
1706 1706
         return $_return;
1707 1707
     }
1708 1708
 
@@ -1718,26 +1718,26 @@  discard block
 block discarded – undo
1718 1718
         $_has_math = false;
1719 1719
         $_math_vars = preg_split('~('.$this->_dvar_math_regexp.'|'.$this->_qstr_regexp.')~', $var_expr, -1, PREG_SPLIT_DELIM_CAPTURE);
1720 1720
 
1721
-        if(count($_math_vars) > 1) {
1721
+        if (count($_math_vars) > 1) {
1722 1722
             $_first_var = "";
1723 1723
             $_complete_var = "";
1724 1724
             $_output = "";
1725 1725
             // simple check if there is any math, to stop recursion (due to modifiers with "xx % yy" as parameter)
1726
-            foreach($_math_vars as $_k => $_math_var) {
1726
+            foreach ($_math_vars as $_k => $_math_var) {
1727 1727
                 $_math_var = $_math_vars[$_k];
1728 1728
 
1729
-                if(!empty($_math_var) || is_numeric($_math_var)) {
1729
+                if (!empty($_math_var) || is_numeric($_math_var)) {
1730 1730
                     // hit a math operator, so process the stuff which came before it
1731
-                    if(preg_match('~^' . $this->_dvar_math_regexp . '$~', $_math_var)) {
1731
+                    if (preg_match('~^'.$this->_dvar_math_regexp.'$~', $_math_var)) {
1732 1732
                         $_has_math = true;
1733
-                        if(!empty($_complete_var) || is_numeric($_complete_var)) {
1733
+                        if (!empty($_complete_var) || is_numeric($_complete_var)) {
1734 1734
                             $_output .= $this->_parse_var($_complete_var);
1735 1735
                         }
1736 1736
 
1737 1737
                         // just output the math operator to php
1738 1738
                         $_output .= $_math_var;
1739 1739
 
1740
-                        if(empty($_first_var))
1740
+                        if (empty($_first_var))
1741 1741
                             $_first_var = $_complete_var;
1742 1742
 
1743 1743
                         $_complete_var = "";
@@ -1746,8 +1746,8 @@  discard block
 block discarded – undo
1746 1746
                     }
1747 1747
                 }
1748 1748
             }
1749
-            if($_has_math) {
1750
-                if(!empty($_complete_var) || is_numeric($_complete_var))
1749
+            if ($_has_math) {
1750
+                if (!empty($_complete_var) || is_numeric($_complete_var))
1751 1751
                     $_output .= $this->_parse_var($_complete_var);
1752 1752
 
1753 1753
                 // get the modifiers working (only the last var from math + modifier is left)
@@ -1756,15 +1756,15 @@  discard block
 block discarded – undo
1756 1756
         }
1757 1757
 
1758 1758
         // prevent cutting of first digit in the number (we _definitly_ got a number if the first char is a digit)
1759
-        if(is_numeric(substr($var_expr, 0, 1)))
1759
+        if (is_numeric(substr($var_expr, 0, 1)))
1760 1760
             $_var_ref = $var_expr;
1761 1761
         else
1762 1762
             $_var_ref = substr($var_expr, 1);
1763 1763
         
1764
-        if(!$_has_math) {
1764
+        if (!$_has_math) {
1765 1765
             
1766 1766
             // get [foo] and .foo and ->foo and (...) pieces
1767
-            preg_match_all('~(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\$?\w+|\.\$?\w+|\S+~', $_var_ref, $match);
1767
+            preg_match_all('~(?:^\w+)|'.$this->_obj_params_regexp.'|(?:'.$this->_var_bracket_regexp.')|->\$?\w+|\.\$?\w+|\S+~', $_var_ref, $match);
1768 1768
                         
1769 1769
             $_indexes = $match[0];
1770 1770
             $_var_name = array_shift($_indexes);
@@ -1782,9 +1782,9 @@  discard block
 block discarded – undo
1782 1782
                     $_var_name = substr(array_shift($_indexes), 1);
1783 1783
                     $_output = "\$this->_smarty_vars['$_var_name']";
1784 1784
                 }
1785
-            } elseif(is_numeric($_var_name) && is_numeric(substr($var_expr, 0, 1))) {
1785
+            } elseif (is_numeric($_var_name) && is_numeric(substr($var_expr, 0, 1))) {
1786 1786
                 // because . is the operator for accessing arrays thru inidizes we need to put it together again for floating point numbers
1787
-                if(count($_indexes) > 0)
1787
+                if (count($_indexes) > 0)
1788 1788
                 {
1789 1789
                     $_var_name .= implode("", $_indexes);
1790 1790
                     $_indexes = array();
@@ -1801,9 +1801,9 @@  discard block
 block discarded – undo
1801 1801
                         $_output .= "[$_index]";
1802 1802
                     } elseif (substr($_index, 0, 1) == '$') {
1803 1803
                         if (strpos($_index, '.') !== false) {
1804
-                            $_output .= '[' . $this->_parse_var($_index) . ']';
1804
+                            $_output .= '['.$this->_parse_var($_index).']';
1805 1805
                         } else {
1806
-                            $_output .= "[\$this->_tpl_vars['" . substr($_index, 1) . "']]";
1806
+                            $_output .= "[\$this->_tpl_vars['".substr($_index, 1)."']]";
1807 1807
                         }
1808 1808
                     } else {
1809 1809
                         $_var_parts = explode('.', $_index);
@@ -1813,19 +1813,19 @@  discard block
 block discarded – undo
1813 1813
                     }
1814 1814
                 } else if (substr($_index, 0, 1) == '.') {
1815 1815
                     if (substr($_index, 1, 1) == '$')
1816
-                        $_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]";
1816
+                        $_output .= "[\$this->_tpl_vars['".substr($_index, 2)."']]";
1817 1817
                     else
1818
-                        $_output .= "['" . substr($_index, 1) . "']";
1819
-                } else if (substr($_index,0,2) == '->') {
1820
-                    if(substr($_index,2,2) == '__') {
1818
+                        $_output .= "['".substr($_index, 1)."']";
1819
+                } else if (substr($_index, 0, 2) == '->') {
1820
+                    if (substr($_index, 2, 2) == '__') {
1821 1821
                         $this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
1822
-                    } elseif($this->security && substr($_index, 2, 1) == '_') {
1822
+                    } elseif ($this->security && substr($_index, 2, 1) == '_') {
1823 1823
                         $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
1824 1824
                     } elseif (substr($_index, 2, 1) == '$') {
1825 1825
                         if ($this->security) {
1826 1826
                             $this->_syntax_error('(secure) call to dynamic object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
1827 1827
                         } else {
1828
-                            $_output .= '->{(($_var=$this->_tpl_vars[\''.substr($_index,3).'\']) && substr($_var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$_var\\"")}';
1828
+                            $_output .= '->{(($_var=$this->_tpl_vars[\''.substr($_index, 3).'\']) && substr($_var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$_var\\"")}';
1829 1829
                         }
1830 1830
                     } else {
1831 1831
                         $_output .= $_index;
@@ -1850,7 +1850,7 @@  discard block
 block discarded – undo
1850 1850
      */
1851 1851
     function _parse_parenth_args($parenth_args)
1852 1852
     {
1853
-        preg_match_all('~' . $this->_param_regexp . '~',$parenth_args, $match);
1853
+        preg_match_all('~'.$this->_param_regexp.'~', $parenth_args, $match);
1854 1854
         $orig_vals = $match = $match[0];
1855 1855
         $this->_parse_vars_props($match);
1856 1856
         $replace = array();
@@ -1913,18 +1913,18 @@  discard block
 block discarded – undo
1913 1913
      */
1914 1914
     function _parse_modifiers(&$output, $modifier_string)
1915 1915
     {
1916
-        preg_match_all('~\|(@?\w+)((?>:(?:'. $this->_qstr_regexp . '|[^|]+))*)~', '|' . $modifier_string, $_match);
1916
+        preg_match_all('~\|(@?\w+)((?>:(?:'.$this->_qstr_regexp.'|[^|]+))*)~', '|'.$modifier_string, $_match);
1917 1917
         list(, $_modifiers, $modifier_arg_strings) = $_match;
1918 1918
 
1919 1919
         for ($_i = 0, $_for_max = count($_modifiers); $_i < $_for_max; $_i++) {
1920 1920
             $_modifier_name = $_modifiers[$_i];
1921 1921
 
1922
-            if($_modifier_name == 'smarty') {
1922
+            if ($_modifier_name == 'smarty') {
1923 1923
                 // skip smarty modifier
1924 1924
                 continue;
1925 1925
             }
1926 1926
 
1927
-            preg_match_all('~:(' . $this->_qstr_regexp . '|[^:]+)~', $modifier_arg_strings[$_i], $_match);
1927
+            preg_match_all('~:('.$this->_qstr_regexp.'|[^:]+)~', $modifier_arg_strings[$_i], $_match);
1928 1928
             $_modifier_args = $_match[1];
1929 1929
 
1930 1930
             if (substr($_modifier_name, 0, 1) == '@') {
@@ -1938,22 +1938,22 @@  discard block
 block discarded – undo
1938 1938
                 && !$this->_get_plugin_filepath('modifier', $_modifier_name)
1939 1939
                 && function_exists($_modifier_name)) {
1940 1940
                 if ($this->security && !in_array($_modifier_name, $this->security_settings['MODIFIER_FUNCS'])) {
1941
-                    $this->_trigger_fatal_error("[plugin] (secure mode) modifier '$_modifier_name' is not allowed" , $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
1941
+                    $this->_trigger_fatal_error("[plugin] (secure mode) modifier '$_modifier_name' is not allowed", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
1942 1942
                 } else {
1943
-                    $this->_plugins['modifier'][$_modifier_name] = array($_modifier_name,  null, null, false);
1943
+                    $this->_plugins['modifier'][$_modifier_name] = array($_modifier_name, null, null, false);
1944 1944
                 }
1945 1945
             }
1946 1946
             $this->_add_plugin('modifier', $_modifier_name);
1947 1947
 
1948 1948
             $this->_parse_vars_props($_modifier_args);
1949 1949
 
1950
-            if($_modifier_name == 'default') {
1950
+            if ($_modifier_name == 'default') {
1951 1951
                 // supress notifications of default modifier vars and args
1952
-                if(substr($output, 0, 1) == '$') {
1953
-                    $output = '@' . $output;
1952
+                if (substr($output, 0, 1) == '$') {
1953
+                    $output = '@'.$output;
1954 1954
                 }
1955
-                if(isset($_modifier_args[0]) && substr($_modifier_args[0], 0, 1) == '$') {
1956
-                    $_modifier_args[0] = '@' . $_modifier_args[0];
1955
+                if (isset($_modifier_args[0]) && substr($_modifier_args[0], 0, 1) == '$') {
1956
+                    $_modifier_args[0] = '@'.$_modifier_args[0];
1957 1957
                 }
1958 1958
             }
1959 1959
             if (count($_modifier_args) > 0)
@@ -1962,7 +1962,7 @@  discard block
 block discarded – undo
1962 1962
                 $_modifier_args = '';
1963 1963
 
1964 1964
             if ($_map_array) {
1965
-                $output = "((is_array(\$_tmp=$output)) ? \$this->_run_mod_handler('$_modifier_name', true, \$_tmp$_modifier_args) : " . $this->_compile_plugin_call('modifier', $_modifier_name) . "(\$_tmp$_modifier_args))";
1965
+                $output = "((is_array(\$_tmp=$output)) ? \$this->_run_mod_handler('$_modifier_name', true, \$_tmp$_modifier_args) : ".$this->_compile_plugin_call('modifier', $_modifier_name)."(\$_tmp$_modifier_args))";
1966 1966
 
1967 1967
             } else {
1968 1968
 
@@ -2003,9 +2003,9 @@  discard block
 block discarded – undo
2003 2003
     {
2004 2004
         /* Extract the reference name. */
2005 2005
         $_ref = substr($indexes[0], 1);
2006
-        foreach($indexes as $_index_no=>$_index) {
2007
-            if (substr($_index, 0, 1) != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) {
2008
-                $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
2006
+        foreach ($indexes as $_index_no=>$_index) {
2007
+            if (substr($_index, 0, 1) != '.' && $_index_no < 2 || !preg_match('~^(\.|\[|->)~', $_index)) {
2008
+                $this->_syntax_error('$smarty'.implode('', array_slice($indexes, 0, 2)).' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
2009 2009
             }
2010 2010
         }
2011 2011
 
@@ -2129,7 +2129,7 @@  discard block
 block discarded – undo
2129 2129
                 return null;
2130 2130
 
2131 2131
             case 'template':
2132
-                $compiled_ref = "'" . addslashes($this->_current_file) . "'";
2132
+                $compiled_ref = "'".addslashes($this->_current_file)."'";
2133 2133
                 $_max_index = 1;
2134 2134
                 break;
2135 2135
 
@@ -2146,10 +2146,10 @@  discard block
 block discarded – undo
2146 2146
                 }
2147 2147
                 array_shift($indexes);
2148 2148
                 if (preg_match('!^\.\w+$!', $indexes[0])) {
2149
-                    $compiled_ref = '@' . substr($indexes[0], 1);
2149
+                    $compiled_ref = '@'.substr($indexes[0], 1);
2150 2150
                 } else {
2151 2151
                     $_val = $this->_parse_var_props(substr($indexes[0], 1));
2152
-                    $compiled_ref = '@constant(' . $_val . ')';
2152
+                    $compiled_ref = '@constant('.$_val.')';
2153 2153
                 }
2154 2154
                 $_max_index = 1;
2155 2155
                 break;
@@ -2168,12 +2168,12 @@  discard block
 block discarded – undo
2168 2168
                 break;
2169 2169
                 
2170 2170
             default:
2171
-                $this->_syntax_error('$smarty.' . $_ref . ' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__);
2171
+                $this->_syntax_error('$smarty.'.$_ref.' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__);
2172 2172
                 break;
2173 2173
         }
2174 2174
 
2175 2175
         if (isset($_max_index) && count($indexes) > $_max_index) {
2176
-            $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
2176
+            $this->_syntax_error('$smarty'.implode('', $indexes).' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
2177 2177
         }
2178 2178
 
2179 2179
         array_shift($indexes);
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
                 return ((is_object($this->_plugins[$type][$name][0][0])) ?
2198 2198
                         "\$this->_plugins['$type']['$name'][0][0]->"    /* method callback */
2199 2199
                         : (string)($this->_plugins[$type][$name][0][0]).'::'    /* class callback */
2200
-                       ). $this->_plugins[$type][$name][0][1];
2200
+                       ).$this->_plugins[$type][$name][0][1];
2201 2201
 
2202 2202
             } else {
2203 2203
                 /* function callback */
@@ -2221,7 +2221,7 @@  discard block
 block discarded – undo
2221 2221
                 if ($prefilter === false) {
2222 2222
                     unset($this->_plugins['prefilter'][$filter_name]);
2223 2223
                     $_params = array('plugins' => array(array('prefilter', $filter_name, null, null, false)));
2224
-                    require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
2224
+                    require_once(SMARTY_CORE_DIR.'core.load_plugins.php');
2225 2225
                     smarty_core_load_plugins($_params, $this);
2226 2226
                 }
2227 2227
             }
@@ -2231,7 +2231,7 @@  discard block
 block discarded – undo
2231 2231
                 if ($postfilter === false) {
2232 2232
                     unset($this->_plugins['postfilter'][$filter_name]);
2233 2233
                     $_params = array('plugins' => array(array('postfilter', $filter_name, null, null, false)));
2234
-                    require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
2234
+                    require_once(SMARTY_CORE_DIR.'core.load_plugins.php');
2235 2235
                     smarty_core_load_plugins($_params, $this);
2236 2236
                 }
2237 2237
             }
@@ -2258,7 +2258,7 @@  discard block
 block discarded – undo
2258 2258
      * @param string $file
2259 2259
      * @param integer $line
2260 2260
      */
2261
-    function _syntax_error($error_msg, $error_type = E_USER_ERROR, $file=null, $line=null)
2261
+    function _syntax_error($error_msg, $error_type = E_USER_ERROR, $file = null, $line = null)
2262 2262
     {
2263 2263
         $this->_trigger_fatal_error("syntax error: $error_msg", $this->_current_file, $this->_current_line_no, $file, $line, $error_type);
2264 2264
     }
@@ -2273,10 +2273,10 @@  discard block
 block discarded – undo
2273 2273
     function _push_cacheable_state($type, $name) {
2274 2274
         $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
2275 2275
         if ($_cacheable
2276
-            || 0<$this->_cacheable_state++) return '';
2276
+            || 0 < $this->_cacheable_state++) return '';
2277 2277
         if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty'));
2278 2278
         $_ret = 'if ($this->caching && !$this->_cache_including): echo \'{nocache:'
2279
-            . $this->_cache_serial . '#' . $this->_nocache_count
2279
+            . $this->_cache_serial.'#'.$this->_nocache_count
2280 2280
             . '}\'; endif;';
2281 2281
         return $_ret;
2282 2282
     }
@@ -2291,9 +2291,9 @@  discard block
 block discarded – undo
2291 2291
     function _pop_cacheable_state($type, $name) {
2292 2292
         $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
2293 2293
         if ($_cacheable
2294
-            || --$this->_cacheable_state>0) return '';
2294
+            || --$this->_cacheable_state > 0) return '';
2295 2295
         return 'if ($this->caching && !$this->_cache_including): echo \'{/nocache:'
2296
-            . $this->_cache_serial . '#' . ($this->_nocache_count++)
2296
+            . $this->_cache_serial.'#'.($this->_nocache_count++)
2297 2297
             . '}\'; endif;';
2298 2298
     }
2299 2299
 
@@ -2316,12 +2316,12 @@  discard block
 block discarded – undo
2316 2316
     function _pop_tag($close_tag)
2317 2317
     {
2318 2318
         $message = '';
2319
-        if (count($this->_tag_stack)>0) {
2319
+        if (count($this->_tag_stack) > 0) {
2320 2320
             list($_open_tag, $_line_no) = array_pop($this->_tag_stack);
2321 2321
             if ($close_tag == $_open_tag) {
2322 2322
                 return $_open_tag;
2323 2323
             }
2324
-            if ($close_tag == 'if' && ($_open_tag == 'else' || $_open_tag == 'elseif' )) {
2324
+            if ($close_tag == 'if' && ($_open_tag == 'else' || $_open_tag == 'elseif')) {
2325 2325
                 return $this->_pop_tag($close_tag);
2326 2326
             }
2327 2327
             if ($close_tag == 'section' && $_open_tag == 'sectionelse') {
@@ -2357,10 +2357,10 @@  discard block
 block discarded – undo
2357 2357
  */
2358 2358
 function _smarty_sort_length($a, $b)
2359 2359
 {
2360
-    if($a == $b)
2360
+    if ($a == $b)
2361 2361
         return 0;
2362 2362
 
2363
-    if(strlen($a) == strlen($b))
2363
+    if (strlen($a) == strlen($b))
2364 2364
         return ($a > $b) ? -1 : 1;
2365 2365
 
2366 2366
     return (strlen($a) > strlen($b)) ? -1 : 1;
Please login to merge, or discard this patch.
Braces   +148 added lines, -108 removed lines patch added patch discarded remove patch
@@ -243,7 +243,9 @@  discard block
 block discarded – undo
243 243
         // run template source through prefilter functions
244 244
         if (count($this->_plugins['prefilter']) > 0) {
245 245
             foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) {
246
-                if ($prefilter === false) continue;
246
+                if ($prefilter === false) {
247
+                    continue;
248
+                }
247 249
                 if ($prefilter[3] || is_callable($prefilter[0])) {
248 250
                     $source_content = call_user_func_array($prefilter[0],
249 251
                                                             array($source_content, &$this));
@@ -385,7 +387,9 @@  discard block
 block discarded – undo
385 387
         // run compiled template through postfilter functions
386 388
         if (count($this->_plugins['postfilter']) > 0) {
387 389
             foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
388
-                if ($postfilter === false) continue;
390
+                if ($postfilter === false) {
391
+                    continue;
392
+                }
389 393
                 if ($postfilter[3] || is_callable($postfilter[0])) {
390 394
                     $compiled_content = call_user_func_array($postfilter[0],
391 395
                                                               array($compiled_content, &$this));
@@ -435,8 +439,9 @@  discard block
 block discarded – undo
435 439
     function _compile_tag($template_tag)
436 440
     {
437 441
         /* Matched comment. */
438
-        if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*')
439
-            return '';
442
+        if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*') {
443
+                    return '';
444
+        }
440 445
         
441 446
         /* Split tag into two three parts: command, command modifiers and the arguments. */
442 447
         if(! preg_match('~^(?:(' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp
@@ -474,18 +479,21 @@  discard block
 block discarded – undo
474 479
 
475 480
             case 'else':
476 481
                 list($_open_tag) = end($this->_tag_stack);
477
-                if ($_open_tag != 'if' && $_open_tag != 'elseif')
478
-                    $this->_syntax_error('unexpected {else}', E_USER_ERROR, __FILE__, __LINE__);
479
-                else
480
-                    $this->_push_tag('else');
482
+                if ($_open_tag != 'if' && $_open_tag != 'elseif') {
483
+                                    $this->_syntax_error('unexpected {else}', E_USER_ERROR, __FILE__, __LINE__);
484
+                } else {
485
+                                    $this->_push_tag('else');
486
+                }
481 487
                 return '<?php else: ?>';
482 488
 
483 489
             case 'elseif':
484 490
                 list($_open_tag) = end($this->_tag_stack);
485
-                if ($_open_tag != 'if' && $_open_tag != 'elseif')
486
-                    $this->_syntax_error('unexpected {elseif}', E_USER_ERROR, __FILE__, __LINE__);
487
-                if ($_open_tag == 'if')
488
-                    $this->_push_tag('elseif');
491
+                if ($_open_tag != 'if' && $_open_tag != 'elseif') {
492
+                                    $this->_syntax_error('unexpected {elseif}', E_USER_ERROR, __FILE__, __LINE__);
493
+                }
494
+                if ($_open_tag == 'if') {
495
+                                    $this->_push_tag('elseif');
496
+                }
489 497
                 return $this->_compile_if_tag($tag_args, true);
490 498
 
491 499
             case '/if':
@@ -515,10 +523,11 @@  discard block
 block discarded – undo
515 523
 
516 524
             case '/section':
517 525
                 $_open_tag = $this->_pop_tag('section');
518
-                if ($_open_tag == 'sectionelse')
519
-                    return "<?php endif; ?>";
520
-                else
521
-                    return "<?php endfor; endif; ?>";
526
+                if ($_open_tag == 'sectionelse') {
527
+                                    return "<?php endif; ?>";
528
+                } else {
529
+                                    return "<?php endfor; endif; ?>";
530
+                }
522 531
 
523 532
             case 'foreach':
524 533
                 $this->_push_tag('foreach');
@@ -531,10 +540,11 @@  discard block
 block discarded – undo
531 540
 
532 541
             case '/foreach':
533 542
                 $_open_tag = $this->_pop_tag('foreach');
534
-                if ($_open_tag == 'foreachelse')
535
-                    return "<?php endif; unset(\$_from); ?>";
536
-                else
537
-                    return "<?php endforeach; endif; unset(\$_from); ?>";
543
+                if ($_open_tag == 'foreachelse') {
544
+                                    return "<?php endif; unset(\$_from); ?>";
545
+                } else {
546
+                                    return "<?php endforeach; endif; unset(\$_from); ?>";
547
+                }
538 548
                 break;
539 549
 
540 550
             case 'strip':
@@ -677,8 +687,9 @@  discard block
 block discarded – undo
677 687
         if (substr($tag_command, 0, 1) == '/') {
678 688
             $start_tag = false;
679 689
             $tag_command = substr($tag_command, 1);
680
-        } else
681
-            $start_tag = true;
690
+        } else {
691
+                    $start_tag = true;
692
+        }
682 693
 
683 694
         $found = false;
684 695
         $have_function = true;
@@ -728,10 +739,11 @@  discard block
 block discarded – undo
728 739
          */
729 740
         $this->_add_plugin('block', $tag_command);
730 741
 
731
-        if ($start_tag)
732
-            $this->_push_tag($tag_command);
733
-        else
734
-            $this->_pop_tag($tag_command);
742
+        if ($start_tag) {
743
+                    $this->_push_tag($tag_command);
744
+        } else {
745
+                    $this->_pop_tag($tag_command);
746
+        }
735 747
 
736 748
         if ($start_tag) {
737 749
             $output = '<?php ' . $this->_push_cacheable_state('block', $tag_command);
@@ -856,8 +868,9 @@  discard block
 block discarded – undo
856 868
                     unset($attrs['assign']);
857 869
                     continue;
858 870
                 }
859
-                if (is_bool($arg_value))
860
-                    $arg_value = $arg_value ? 'true' : 'false';
871
+                if (is_bool($arg_value)) {
872
+                                    $arg_value = $arg_value ? 'true' : 'false';
873
+                }
861 874
                 $arg_list[] = "'$arg_name' => $arg_value";
862 875
             }
863 876
         }
@@ -948,8 +961,9 @@  discard block
 block discarded – undo
948 961
         }
949 962
 
950 963
         foreach ($attrs as $arg_name => $arg_value) {
951
-            if (is_bool($arg_value))
952
-                $arg_value = $arg_value ? 'true' : 'false';
964
+            if (is_bool($arg_value)) {
965
+                            $arg_value = $arg_value ? 'true' : 'false';
966
+            }
953 967
             $arg_list[] = "'$arg_name' => $arg_value";
954 968
         }
955 969
 
@@ -987,13 +1001,15 @@  discard block
 block discarded – undo
987 1001
                 $theme_template = $arg_value;
988 1002
                 continue;
989 1003
             }
990
-            if (is_bool($arg_value))
991
-                $arg_value = $arg_value ? 'true' : 'false';
1004
+            if (is_bool($arg_value)) {
1005
+                            $arg_value = $arg_value ? 'true' : 'false';
1006
+            }
992 1007
             $arg_list[] = "'$arg_name' => $arg_value";
993 1008
         }
994 1009
 
995
-        if ( $theme_template == 'true' )
996
-            $include_file = '"'.SugarThemeRegistry::current()->getTemplate(str_replace(array('"',"'"),'',$include_file)).'"';
1010
+        if ( $theme_template == 'true' ) {
1011
+                    $include_file = '"'.SugarThemeRegistry::current()->getTemplate(str_replace(array('"',"'"),'',$include_file)).'"';
1012
+        }
997 1013
 
998 1014
         $output = '<?php ';
999 1015
 
@@ -1040,8 +1056,9 @@  discard block
 block discarded – undo
1040 1056
         $arg_list = array();
1041 1057
         foreach($attrs as $arg_name => $arg_value) {
1042 1058
             if($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') {
1043
-                if(is_bool($arg_value))
1044
-                    $arg_value = $arg_value ? 'true' : 'false';
1059
+                if(is_bool($arg_value)) {
1060
+                                    $arg_value = $arg_value ? 'true' : 'false';
1061
+                }
1045 1062
                 $arg_list[] = "'$arg_name' => $arg_value";
1046 1063
             }
1047 1064
         }
@@ -1079,10 +1096,11 @@  discard block
 block discarded – undo
1079 1096
                     break;
1080 1097
 
1081 1098
                 case 'show':
1082
-                    if (is_bool($attr_value))
1083
-                        $show_attr_value = $attr_value ? 'true' : 'false';
1084
-                    else
1085
-                        $show_attr_value = "(bool)$attr_value";
1099
+                    if (is_bool($attr_value)) {
1100
+                                            $show_attr_value = $attr_value ? 'true' : 'false';
1101
+                    } else {
1102
+                                            $show_attr_value = "(bool)$attr_value";
1103
+                    }
1086 1104
                     $output .= "{$section_props}['show'] = $show_attr_value;\n";
1087 1105
                     break;
1088 1106
 
@@ -1105,24 +1123,28 @@  discard block
 block discarded – undo
1105 1123
             }
1106 1124
         }
1107 1125
 
1108
-        if (!isset($attrs['show']))
1109
-            $output .= "{$section_props}['show'] = true;\n";
1126
+        if (!isset($attrs['show'])) {
1127
+                    $output .= "{$section_props}['show'] = true;\n";
1128
+        }
1110 1129
 
1111
-        if (!isset($attrs['loop']))
1112
-            $output .= "{$section_props}['loop'] = 1;\n";
1130
+        if (!isset($attrs['loop'])) {
1131
+                    $output .= "{$section_props}['loop'] = 1;\n";
1132
+        }
1113 1133
 
1114
-        if (!isset($attrs['max']))
1115
-            $output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
1116
-        else
1117
-            $output .= "if ({$section_props}['max'] < 0)\n" .
1134
+        if (!isset($attrs['max'])) {
1135
+                    $output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
1136
+        } else {
1137
+                    $output .= "if ({$section_props}['max'] < 0)\n" .
1118 1138
                        "    {$section_props}['max'] = {$section_props}['loop'];\n";
1139
+        }
1119 1140
 
1120
-        if (!isset($attrs['step']))
1121
-            $output .= "{$section_props}['step'] = 1;\n";
1141
+        if (!isset($attrs['step'])) {
1142
+                    $output .= "{$section_props}['step'] = 1;\n";
1143
+        }
1122 1144
 
1123
-        if (!isset($attrs['start']))
1124
-            $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
1125
-        else {
1145
+        if (!isset($attrs['start'])) {
1146
+                    $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
1147
+        } else {
1126 1148
             $output .= "if ({$section_props}['start'] < 0)\n" .
1127 1149
                        "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" .
1128 1150
                        "else\n" .
@@ -1377,8 +1399,9 @@  discard block
 block discarded – undo
1377 1399
                                 $is_arg_start--;
1378 1400
                             } 
1379 1401
                         } 
1380
-                    } else
1381
-                        $is_arg_start = $i-1;
1402
+                    } else {
1403
+                                            $is_arg_start = $i-1;
1404
+                    }
1382 1405
                     /* Construct the argument for 'is' expression, so it knows
1383 1406
                        what to operate on. */
1384 1407
                     $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
@@ -1420,10 +1443,11 @@  discard block
 block discarded – undo
1420 1443
             }
1421 1444
         }
1422 1445
 
1423
-        if ($elseif)
1424
-            return '<?php elseif ('.implode(' ', $tokens).'): ?>';
1425
-        else
1426
-            return '<?php if ('.implode(' ', $tokens).'): ?>';
1446
+        if ($elseif) {
1447
+                    return '<?php elseif ('.implode(' ', $tokens).'): ?>';
1448
+        } else {
1449
+                    return '<?php if ('.implode(' ', $tokens).'): ?>';
1450
+        }
1427 1451
     }
1428 1452
 
1429 1453
 
@@ -1447,10 +1471,12 @@  discard block
 block discarded – undo
1447 1471
         }
1448 1472
 
1449 1473
         foreach ($attrs as $arg_name => $arg_value) {
1450
-            if (is_bool($arg_value))
1451
-                $arg_value = $arg_value ? 'true' : 'false';
1452
-            if (is_null($arg_value))
1453
-                $arg_value = 'null';
1474
+            if (is_bool($arg_value)) {
1475
+                            $arg_value = $arg_value ? 'true' : 'false';
1476
+            }
1477
+            if (is_null($arg_value)) {
1478
+                            $arg_value = 'null';
1479
+            }
1454 1480
             if ($_cache_attrs && in_array($arg_name, $_cache_attrs)) {
1455 1481
                 $arg_list[] = "'$arg_name' => (\$this->_cache_including) ? \$_cache_attrs['$arg_name'] : (\$_cache_attrs['$arg_name']=$arg_value)";
1456 1482
             } else {
@@ -1475,8 +1501,9 @@  discard block
 block discarded – undo
1475 1501
         if (($first_token = array_shift($tokens)) == 'not') {
1476 1502
             $negate_expr = true;
1477 1503
             $expr_type = array_shift($tokens);
1478
-        } else
1479
-            $expr_type = $first_token;
1504
+        } else {
1505
+                    $expr_type = $first_token;
1506
+        }
1480 1507
 
1481 1508
         switch ($expr_type) {
1482 1509
             case 'even':
@@ -1484,8 +1511,9 @@  discard block
 block discarded – undo
1484 1511
                     $expr_end++;
1485 1512
                     $expr_arg = $tokens[$expr_end++];
1486 1513
                     $expr = "!(1 & ($is_arg / " . $this->_parse_var_props($expr_arg) . "))";
1487
-                } else
1488
-                    $expr = "!(1 & $is_arg)";
1514
+                } else {
1515
+                                    $expr = "!(1 & $is_arg)";
1516
+                }
1489 1517
                 break;
1490 1518
 
1491 1519
             case 'odd':
@@ -1493,8 +1521,9 @@  discard block
 block discarded – undo
1493 1521
                     $expr_end++;
1494 1522
                     $expr_arg = $tokens[$expr_end++];
1495 1523
                     $expr = "(1 & ($is_arg / " . $this->_parse_var_props($expr_arg) . "))";
1496
-                } else
1497
-                    $expr = "(1 & $is_arg)";
1524
+                } else {
1525
+                                    $expr = "(1 & $is_arg)";
1526
+                }
1498 1527
                 break;
1499 1528
 
1500 1529
             case 'div':
@@ -1553,16 +1582,18 @@  discard block
 block discarded – undo
1553 1582
                     if (preg_match('~^\w+$~', $token)) {
1554 1583
                         $attr_name = $token;
1555 1584
                         $state = 1;
1556
-                    } else
1557
-                        $this->_syntax_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__);
1585
+                    } else {
1586
+                                            $this->_syntax_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__);
1587
+                    }
1558 1588
                     break;
1559 1589
 
1560 1590
                 case 1:
1561 1591
                     /* If the token is '=', then we go to state 2. */
1562 1592
                     if ($token == '=') {
1563 1593
                         $state = 2;
1564
-                    } else
1565
-                        $this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__);
1594
+                    } else {
1595
+                                            $this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__);
1596
+                    }
1566 1597
                     break;
1567 1598
 
1568 1599
                 case 2:
@@ -1586,8 +1617,9 @@  discard block
 block discarded – undo
1586 1617
 
1587 1618
                         $attrs[$attr_name] = $token;
1588 1619
                         $state = 0;
1589
-                    } else
1590
-                        $this->_syntax_error("'=' cannot be an attribute value", E_USER_ERROR, __FILE__, __LINE__);
1620
+                    } else {
1621
+                                            $this->_syntax_error("'=' cannot be an attribute value", E_USER_ERROR, __FILE__, __LINE__);
1622
+                    }
1591 1623
                     break;
1592 1624
             }
1593 1625
             $last_token = $token;
@@ -1649,32 +1681,27 @@  discard block
 block discarded – undo
1649 1681
                     $this->_parse_modifiers($return, $match[2]);
1650 1682
                 }
1651 1683
                 return $return;
1652
-            }
1653
-        elseif(preg_match('~^' . $this->_num_const_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1684
+            } elseif(preg_match('~^' . $this->_num_const_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1654 1685
                 // numerical constant
1655 1686
                 preg_match('~^(' . $this->_num_const_regexp . ')('. $this->_mod_regexp . '*)$~', $val, $match);
1656 1687
                 if($match[2] != '') {
1657 1688
                     $this->_parse_modifiers($match[1], $match[2]);
1658 1689
                     return $match[1];
1659 1690
                 }
1660
-            }
1661
-        elseif(preg_match('~^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1691
+            } elseif(preg_match('~^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1662 1692
                 // single quoted text
1663 1693
                 preg_match('~^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . '*)$~', $val, $match);
1664 1694
                 if($match[2] != '') {
1665 1695
                     $this->_parse_modifiers($match[1], $match[2]);
1666 1696
                     return $match[1];
1667 1697
                 }
1668
-            }
1669
-        elseif(preg_match('~^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1698
+            } elseif(preg_match('~^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1670 1699
                 // config var
1671 1700
                 return $this->_parse_conf_var($val);
1672
-            }
1673
-        elseif(preg_match('~^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1701
+            } elseif(preg_match('~^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$~', $val)) {
1674 1702
                 // section var
1675 1703
                 return $this->_parse_section_prop($val);
1676
-            }
1677
-        elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) {
1704
+            } elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) {
1678 1705
             // literal string
1679 1706
             return $this->_expand_quoted_text('"' . strtr($val, array('\\' => '\\\\', '"' => '\\"')) .'"');
1680 1707
         }
@@ -1737,8 +1764,9 @@  discard block
 block discarded – undo
1737 1764
                         // just output the math operator to php
1738 1765
                         $_output .= $_math_var;
1739 1766
 
1740
-                        if(empty($_first_var))
1741
-                            $_first_var = $_complete_var;
1767
+                        if(empty($_first_var)) {
1768
+                                                    $_first_var = $_complete_var;
1769
+                        }
1742 1770
 
1743 1771
                         $_complete_var = "";
1744 1772
                     } else {
@@ -1747,8 +1775,9 @@  discard block
 block discarded – undo
1747 1775
                 }
1748 1776
             }
1749 1777
             if($_has_math) {
1750
-                if(!empty($_complete_var) || is_numeric($_complete_var))
1751
-                    $_output .= $this->_parse_var($_complete_var);
1778
+                if(!empty($_complete_var) || is_numeric($_complete_var)) {
1779
+                                    $_output .= $this->_parse_var($_complete_var);
1780
+                }
1752 1781
 
1753 1782
                 // get the modifiers working (only the last var from math + modifier is left)
1754 1783
                 $var_expr = $_complete_var;
@@ -1756,10 +1785,11 @@  discard block
 block discarded – undo
1756 1785
         }
1757 1786
 
1758 1787
         // prevent cutting of first digit in the number (we _definitly_ got a number if the first char is a digit)
1759
-        if(is_numeric(substr($var_expr, 0, 1)))
1760
-            $_var_ref = $var_expr;
1761
-        else
1762
-            $_var_ref = substr($var_expr, 1);
1788
+        if(is_numeric(substr($var_expr, 0, 1))) {
1789
+                    $_var_ref = $var_expr;
1790
+        } else {
1791
+                    $_var_ref = substr($var_expr, 1);
1792
+        }
1763 1793
         
1764 1794
         if(!$_has_math) {
1765 1795
             
@@ -1812,10 +1842,11 @@  discard block
 block discarded – undo
1812 1842
                         $_output .= "[\$this->_sections['$_var_section']['$_var_section_prop']]";
1813 1843
                     }
1814 1844
                 } else if (substr($_index, 0, 1) == '.') {
1815
-                    if (substr($_index, 1, 1) == '$')
1816
-                        $_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]";
1817
-                    else
1818
-                        $_output .= "['" . substr($_index, 1) . "']";
1845
+                    if (substr($_index, 1, 1) == '$') {
1846
+                                            $_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]";
1847
+                    } else {
1848
+                                            $_output .= "['" . substr($_index, 1) . "']";
1849
+                    }
1819 1850
                 } else if (substr($_index,0,2) == '->') {
1820 1851
                     if(substr($_index,2,2) == '__') {
1821 1852
                         $this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
@@ -1956,10 +1987,11 @@  discard block
 block discarded – undo
1956 1987
                     $_modifier_args[0] = '@' . $_modifier_args[0];
1957 1988
                 }
1958 1989
             }
1959
-            if (count($_modifier_args) > 0)
1960
-                $_modifier_args = ', '.implode(', ', $_modifier_args);
1961
-            else
1962
-                $_modifier_args = '';
1990
+            if (count($_modifier_args) > 0) {
1991
+                            $_modifier_args = ', '.implode(', ', $_modifier_args);
1992
+            } else {
1993
+                            $_modifier_args = '';
1994
+            }
1963 1995
 
1964 1996
             if ($_map_array) {
1965 1997
                 $output = "((is_array(\$_tmp=$output)) ? \$this->_run_mod_handler('$_modifier_name', true, \$_tmp$_modifier_args) : " . $this->_compile_plugin_call('modifier', $_modifier_name) . "(\$_tmp$_modifier_args))";
@@ -2273,8 +2305,12 @@  discard block
 block discarded – undo
2273 2305
     function _push_cacheable_state($type, $name) {
2274 2306
         $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
2275 2307
         if ($_cacheable
2276
-            || 0<$this->_cacheable_state++) return '';
2277
-        if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty'));
2308
+            || 0<$this->_cacheable_state++) {
2309
+            return '';
2310
+        }
2311
+        if (!isset($this->_cache_serial)) {
2312
+            $this->_cache_serial = md5(uniqid('Smarty'));
2313
+        }
2278 2314
         $_ret = 'if ($this->caching && !$this->_cache_including): echo \'{nocache:'
2279 2315
             . $this->_cache_serial . '#' . $this->_nocache_count
2280 2316
             . '}\'; endif;';
@@ -2291,7 +2327,9 @@  discard block
 block discarded – undo
2291 2327
     function _pop_cacheable_state($type, $name) {
2292 2328
         $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
2293 2329
         if ($_cacheable
2294
-            || --$this->_cacheable_state>0) return '';
2330
+            || --$this->_cacheable_state>0) {
2331
+            return '';
2332
+        }
2295 2333
         return 'if ($this->caching && !$this->_cache_including): echo \'{/nocache:'
2296 2334
             . $this->_cache_serial . '#' . ($this->_nocache_count++)
2297 2335
             . '}\'; endif;';
@@ -2357,11 +2395,13 @@  discard block
 block discarded – undo
2357 2395
  */
2358 2396
 function _smarty_sort_length($a, $b)
2359 2397
 {
2360
-    if($a == $b)
2361
-        return 0;
2398
+    if($a == $b) {
2399
+            return 0;
2400
+    }
2362 2401
 
2363
-    if(strlen($a) == strlen($b))
2364
-        return ($a > $b) ? -1 : 1;
2402
+    if(strlen($a) == strlen($b)) {
2403
+            return ($a > $b) ? -1 : 1;
2404
+    }
2365 2405
 
2366 2406
     return (strlen($a) > strlen($b)) ? -1 : 1;
2367 2407
 }
Please login to merge, or discard this patch.
Doc Comments   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      * @param string $resource_name
221 221
      * @param string $source_content
222 222
      * @param string $compiled_content
223
-     * @return true
223
+     * @return null|boolean
224 224
      */
225 225
     function _compile_file($resource_name, $source_content, &$compiled_content)
226 226
     {
@@ -761,7 +761,8 @@  discard block
 block discarded – undo
761 761
      * @param string $tag_command
762 762
      * @param string $tag_args
763 763
      * @param string $tag_modifier
764
-     * @return string
764
+     * @param string $output
765
+     * @return boolean
765 766
      */
766 767
     function _compile_custom_tag($tag_command, $tag_args, $tag_modifier, &$output)
767 768
     {
@@ -1427,6 +1428,11 @@  discard block
 block discarded – undo
1427 1428
     }
1428 1429
 
1429 1430
 
1431
+    /**
1432
+     * @param string $type
1433
+     * @param string $name
1434
+     * @param string $cache_code
1435
+     */
1430 1436
     function _compile_arg_list($type, $name, $attrs, &$cache_code) {
1431 1437
         $arg_list = array();
1432 1438
 
@@ -1624,7 +1630,6 @@  discard block
 block discarded – undo
1624 1630
      * PHP code
1625 1631
      *
1626 1632
      * @param string $val
1627
-     * @param string $tag_attrs
1628 1633
      * @return string
1629 1634
      */
1630 1635
     function _parse_var_props($val)
@@ -1710,7 +1715,6 @@  discard block
 block discarded – undo
1710 1715
      * parse variable expression into PHP code
1711 1716
      *
1712 1717
      * @param string $var_expr
1713
-     * @param string $output
1714 1718
      * @return string
1715 1719
      */
1716 1720
     function _parse_var($var_expr)
@@ -1978,7 +1982,7 @@  discard block
 block discarded – undo
1978 1982
      *
1979 1983
      * @param string $type
1980 1984
      * @param string $name
1981
-     * @param boolean? $delayed_loading
1985
+     * @param boolean $delayed_loading
1982 1986
      */
1983 1987
     function _add_plugin($type, $name, $delayed_loading = null)
1984 1988
     {
@@ -2268,6 +2272,8 @@  discard block
 block discarded – undo
2268 2272
      * check if the compilation changes from cacheable to
2269 2273
      * non-cacheable state with the beginning of the current
2270 2274
      * plugin. return php-code to reflect the transition.
2275
+     * @param string $type
2276
+     * @param string $name
2271 2277
      * @return string
2272 2278
      */
2273 2279
     function _push_cacheable_state($type, $name) {
@@ -2286,6 +2292,8 @@  discard block
 block discarded – undo
2286 2292
      * check if the compilation changes from non-cacheable to
2287 2293
      * cacheable state with the end of the current plugin return
2288 2294
      * php-code to reflect the transition.
2295
+     * @param string $type
2296
+     * @param string $name
2289 2297
      * @return string
2290 2298
      */
2291 2299
     function _pop_cacheable_state($type, $name) {
@@ -2301,6 +2309,7 @@  discard block
 block discarded – undo
2301 2309
     /**
2302 2310
      * push opening tag-name, file-name and line-number on the tag-stack
2303 2311
      * @param string the opening tag's name
2312
+     * @param string $open_tag
2304 2313
      */
2305 2314
     function _push_tag($open_tag)
2306 2315
     {
@@ -2311,6 +2320,7 @@  discard block
 block discarded – undo
2311 2320
      * pop closing tag-name
2312 2321
      * raise an error if this stack-top doesn't match with the closing tag
2313 2322
      * @param string the closing tag's name
2323
+     * @param string $close_tag
2314 2324
      * @return string the opening tag's name
2315 2325
      */
2316 2326
     function _pop_tag($close_tag)
Please login to merge, or discard this patch.
data/SugarBean.php 4 patches
Indentation   +738 added lines, -738 removed lines patch added patch discarded remove patch
@@ -84,27 +84,27 @@  discard block
 block discarded – undo
84 84
     public $id;
85 85
 
86 86
     /**
87
-	 * When createing a bean, you can specify a value in the id column as
88
-	 * long as that value is unique.  During save, if the system finds an
89
-	 * id, it assumes it is an update.  Setting new_with_id to true will
90
-	 * make sure the system performs an insert instead of an update.
91
-	 *
92
-	 * @var BOOL -- default false
93
-	 */
94
-	var $new_with_id = false;
95
-
96
-
97
-	/**
98
-	 * How deep logic hooks can go
99
-	 * @var int
100
-	 */
101
-	protected $max_logic_depth = 10;
102
-
103
-	/**
104
-	 * Disble vardefs.  This should be set to true only for beans that do not have varders.  Tracker is an example
105
-	 *
106
-	 * @var BOOL -- default false
107
-	 */
87
+     * When createing a bean, you can specify a value in the id column as
88
+     * long as that value is unique.  During save, if the system finds an
89
+     * id, it assumes it is an update.  Setting new_with_id to true will
90
+     * make sure the system performs an insert instead of an update.
91
+     *
92
+     * @var BOOL -- default false
93
+     */
94
+    var $new_with_id = false;
95
+
96
+
97
+    /**
98
+     * How deep logic hooks can go
99
+     * @var int
100
+     */
101
+    protected $max_logic_depth = 10;
102
+
103
+    /**
104
+     * Disble vardefs.  This should be set to true only for beans that do not have varders.  Tracker is an example
105
+     *
106
+     * @var BOOL -- default false
107
+     */
108 108
     var $disable_vardefs = false;
109 109
 
110 110
 
@@ -116,20 +116,20 @@  discard block
 block discarded – undo
116 116
      */
117 117
     var $new_assigned_user_name;
118 118
 
119
-	/**
120
-	 * An array of booleans.  This array is cleared out when data is loaded.
121
-	 * As date/times are converted, a "1" is placed under the key, the field is converted.
122
-	 *
123
-	 * @var Array of booleans
124
-	 */
125
-	var $processed_dates_times = array();
119
+    /**
120
+     * An array of booleans.  This array is cleared out when data is loaded.
121
+     * As date/times are converted, a "1" is placed under the key, the field is converted.
122
+     *
123
+     * @var Array of booleans
124
+     */
125
+    var $processed_dates_times = array();
126 126
 
127
-	/**
128
-	 * Whether to process date/time fields for storage in the database in GMT
129
-	 *
130
-	 * @var BOOL
131
-	 */
132
-	var $process_save_dates =true;
127
+    /**
128
+     * Whether to process date/time fields for storage in the database in GMT
129
+     *
130
+     * @var BOOL
131
+     */
132
+    var $process_save_dates =true;
133 133
 
134 134
     /**
135 135
      * This signals to the bean that it is being saved in a mass mode.
@@ -140,20 +140,20 @@  discard block
 block discarded – undo
140 140
      */
141 141
     var $save_from_post = true;
142 142
 
143
-	/**
144
-	 * When running a query on related items using the method: retrieve_by_string_fields
145
-	 * this value will be set to true if more than one item matches the search criteria.
146
-	 *
147
-	 * @var BOOL
148
-	 */
149
-	var $duplicates_found = false;
143
+    /**
144
+     * When running a query on related items using the method: retrieve_by_string_fields
145
+     * this value will be set to true if more than one item matches the search criteria.
146
+     *
147
+     * @var BOOL
148
+     */
149
+    var $duplicates_found = false;
150 150
 
151
-	/**
152
-	 * true if this bean has been deleted, false otherwise.
153
-	 *
154
-	 * @var BOOL
155
-	 */
156
-	var $deleted = 0;
151
+    /**
152
+     * true if this bean has been deleted, false otherwise.
153
+     *
154
+     * @var BOOL
155
+     */
156
+    var $deleted = 0;
157 157
 
158 158
     /**
159 159
      * Should the date modified column of the bean be updated during save?
@@ -201,22 +201,22 @@  discard block
 block discarded – undo
201 201
     var $table_name = '';
202 202
 
203 203
     /**
204
-    * This is the singular name of the bean.  (i.e. Contact).
205
-    *
206
-    * @var String
207
-    */
204
+     * This is the singular name of the bean.  (i.e. Contact).
205
+     *
206
+     * @var String
207
+     */
208 208
     var $object_name = '';
209 209
 
210 210
     /** Set this to true if you query contains a sub-select and bean is converting both select statements
211
-    * into count queries.
212
-    */
211
+     * into count queries.
212
+     */
213 213
     var $ungreedy_count=false;
214 214
 
215 215
     /**
216
-    * The name of the module folder for this type of bean.
217
-    *
218
-    * @var String
219
-    */
216
+     * The name of the module folder for this type of bean.
217
+     *
218
+     * @var String
219
+     */
220 220
     var $module_dir = '';
221 221
     var $module_name = '';
222 222
     var $field_name_map;
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
     var $importable = false;
250 250
 
251 251
     /**
252
-    * Set to true in the child beans if the module use the special notification template
253
-    */
252
+     * Set to true in the child beans if the module use the special notification template
253
+     */
254 254
     var $special_notification = false;
255 255
 
256 256
     /**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      */
283 283
     protected $loaded_relationships = array();
284 284
 
285
-	/**
285
+    /**
286 286
      * set to true if dependent fields updated
287 287
      */
288 288
     protected $is_updated_dependent_fields = false;
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
             return;
662 662
 
663 663
         foreach ($this->field_defs as $field => $value) {
664
-		    if( !empty($this->$field)
664
+            if( !empty($this->$field)
665 665
                   && ((isset($value['default']) && $this->$field == $value['default']) || (!empty($value['display_default']) && $this->$field == $value['display_default']))
666 666
                     ) {
667 667
                 $this->$field = null;
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
                             $this->$field = $this->parseDateDefault($value['display_default']);
711 711
                         }
712 712
                         break;
713
-                   case 'datetime':
713
+                    case 'datetime':
714 714
                    case 'datetimecombo':
715 715
                         if(!empty($value['display_default'])){
716 716
                             $this->$field = $this->parseDateDefault($value['display_default'], true);
@@ -723,9 +723,9 @@  discard block
 block discarded – undo
723 723
                             $this->$field = $value['default'];
724 724
                         break;
725 725
                     case 'bool':
726
-                    	if(isset($this->$field)){
727
-                    		break;
728
-                    	}
726
+                        if(isset($this->$field)){
727
+                            break;
728
+                        }
729 729
                     default:
730 730
                         if ( isset($value['default']) && $value['default'] !== '' ) {
731 731
                             $this->$field = htmlentities($value['default'], ENT_QUOTES, 'UTF-8');
@@ -788,10 +788,10 @@  discard block
 block discarded – undo
788 788
     /**
789 789
      * This method has been deprecated.
790 790
      *
791
-    * @see removeRelationshipMeta()
791
+     * @see removeRelationshipMeta()
792 792
      * @deprecated 4.5.1 - Nov 14, 2006
793 793
      * @static
794
-    */
794
+     */
795 795
     static function remove_relationship_meta($key,$db,$log,$tablename,$dictionary,$module_dir)
796 796
     {
797 797
         SugarBean::removeRelationshipMeta($key,$db,$tablename,$dictionary,$module_dir);
@@ -927,10 +927,10 @@  discard block
 block discarded – undo
927 927
 
928 928
     /**
929 929
      * This method has been deprecated.
930
-    * @see createRelationshipMeta()
930
+     * @see createRelationshipMeta()
931 931
      * @deprecated 4.5.1 - Nov 14, 2006
932 932
      * @static
933
-    */
933
+     */
934 934
     static function create_relationship_meta($key,&$db,&$log,$tablename,$dictionary,$module_dir)
935 935
     {
936 936
         SugarBean::createRelationshipMeta($key,$db,$tablename,$dictionary,$module_dir);
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
 
1085 1085
         $linked_fields=array();
1086 1086
 
1087
- //   	require_once('data/Link.php');
1087
+    //   	require_once('data/Link.php');
1088 1088
 
1089 1089
         $fieldDefs = $this->getFieldDefinitions();
1090 1090
 
@@ -1314,8 +1314,8 @@  discard block
 block discarded – undo
1314 1314
     }
1315 1315
 
1316 1316
     /**
1317
-    * Cleans char, varchar, text, etc. fields of XSS type materials
1318
-    */
1317
+     * Cleans char, varchar, text, etc. fields of XSS type materials
1318
+     */
1319 1319
     function cleanBean() {
1320 1320
         foreach($this->field_defs as $key => $def) {
1321 1321
 
@@ -1338,14 +1338,14 @@  discard block
 block discarded – undo
1338 1338
     }
1339 1339
 
1340 1340
     /**
1341
-    * Implements a generic insert and update logic for any SugarBean
1342
-    * This method only works for subclasses that implement the same variable names.
1343
-    * This method uses the presence of an id field that is not null to signify and update.
1344
-    * The id field should not be set otherwise.
1345
-    *
1346
-    * @param boolean $check_notify Optional, default false, if set to true assignee of the record is notified via email.
1347
-    * @todo Add support for field type validation and encoding of parameters.
1348
-    */
1341
+     * Implements a generic insert and update logic for any SugarBean
1342
+     * This method only works for subclasses that implement the same variable names.
1343
+     * This method uses the presence of an id field that is not null to signify and update.
1344
+     * The id field should not be set otherwise.
1345
+     *
1346
+     * @param boolean $check_notify Optional, default false, if set to true assignee of the record is notified via email.
1347
+     * @todo Add support for field type validation and encoding of parameters.
1348
+     */
1349 1349
     function save($check_notify = FALSE)
1350 1350
     {
1351 1351
         $this->in_save = true;
@@ -1362,14 +1362,14 @@  discard block
 block discarded – undo
1362 1362
             $isUpdate = false;
1363 1363
         }
1364 1364
 
1365
-		if ( $this->new_with_id == true )
1366
-		{
1367
-			$isUpdate = false;
1368
-		}
1369
-		if(empty($this->date_modified) || $this->update_date_modified)
1370
-		{
1371
-			$this->date_modified = $GLOBALS['timedate']->nowDb();
1372
-		}
1365
+        if ( $this->new_with_id == true )
1366
+        {
1367
+            $isUpdate = false;
1368
+        }
1369
+        if(empty($this->date_modified) || $this->update_date_modified)
1370
+        {
1371
+            $this->date_modified = $GLOBALS['timedate']->nowDb();
1372
+        }
1373 1373
 
1374 1374
         $this->_checkOptimisticLocking($action, $isUpdate);
1375 1375
 
@@ -1483,10 +1483,10 @@  discard block
 block discarded – undo
1483 1483
         }
1484 1484
 
1485 1485
 
1486
-		/* BEGIN - SECURITY GROUPS - inheritance */ 
1487
-		require_once('modules/SecurityGroups/SecurityGroup.php');
1488
-		SecurityGroup::inherit($this,$isUpdate);
1489
-		/* END - SECURITY GROUPS */ 
1486
+        /* BEGIN - SECURITY GROUPS - inheritance */ 
1487
+        require_once('modules/SecurityGroups/SecurityGroup.php');
1488
+        SecurityGroup::inherit($this,$isUpdate);
1489
+        /* END - SECURITY GROUPS */ 
1490 1490
         //If we aren't in setup mode and we have a current user and module, then we track
1491 1491
         if(isset($GLOBALS['current_user']) && isset($this->module_dir))
1492 1492
         {
@@ -1527,8 +1527,8 @@  discard block
 block discarded – undo
1527 1527
     }
1528 1528
 
1529 1529
     /**
1530
-    * Determines which users receive a notification
1531
-    */
1530
+     * Determines which users receive a notification
1531
+     */
1532 1532
     function get_notification_recipients() {
1533 1533
         $notify_user = new User();
1534 1534
         $notify_user->retrieve($this->assigned_user_id);
@@ -1545,11 +1545,11 @@  discard block
 block discarded – undo
1545 1545
     }
1546 1546
 
1547 1547
     /**
1548
-    * Handles sending out email notifications when items are first assigned to users
1549
-    *
1550
-    * @param string $notify_user user to notify
1551
-    * @param string $admin the admin user that sends out the notification
1552
-    */
1548
+     * Handles sending out email notifications when items are first assigned to users
1549
+     *
1550
+     * @param string $notify_user user to notify
1551
+     * @param string $admin the admin user that sends out the notification
1552
+     */
1553 1553
     function send_assignment_notifications($notify_user, $admin)
1554 1554
     {
1555 1555
         global $current_user;
@@ -1580,7 +1580,7 @@  discard block
 block discarded – undo
1580 1580
                 $notify_mail->FromName = $from_name;
1581 1581
             }
1582 1582
 
1583
-           $oe = new OutboundEmail();
1583
+            $oe = new OutboundEmail();
1584 1584
             $oe = $oe->getUserMailerSettings($current_user);
1585 1585
             //only send if smtp server is defined
1586 1586
             if($sendEmail){
@@ -1616,9 +1616,9 @@  discard block
 block discarded – undo
1616 1616
     }
1617 1617
 
1618 1618
     /**
1619
-    * This function handles create the email notifications email.
1620
-    * @param string $notify_user the user to send the notification email to
1621
-    */
1619
+     * This function handles create the email notifications email.
1620
+     * @param string $notify_user the user to send the notification email to
1621
+     */
1622 1622
     function create_notification_email($notify_user) {
1623 1623
         global $sugar_version;
1624 1624
         global $sugar_config;
@@ -2027,104 +2027,104 @@  discard block
 block discarded – undo
2027 2027
     }
2028 2028
 
2029 2029
     /**
2030
-    * This function retrieves a record of the appropriate type from the DB.
2031
-    * It fills in all of the fields from the DB into the object it was called on.
2032
-    *
2033
-    * @param $id - If ID is specified, it overrides the current value of $this->id.  If not specified the current value of $this->id will be used.
2034
-    * @return this - The object that it was called apon or null if exactly 1 record was not found.
2035
-    *
2036
-	*/
2037
-
2038
-	function check_date_relationships_load()
2039
-	{
2040
-		global $disable_date_format;
2041
-		global $timedate;
2042
-		if (empty($timedate))
2043
-			$timedate=TimeDate::getInstance();
2044
-
2045
-		if(empty($this->field_defs))
2046
-		{
2047
-			return;
2048
-		}
2049
-		foreach($this->field_defs as $fieldDef)
2050
-		{
2051
-			$field = $fieldDef['name'];
2052
-			if(!isset($this->processed_dates_times[$field]))
2053
-			{
2054
-				$this->processed_dates_times[$field] = '1';
2055
-				if(empty($this->$field)) continue;
2056
-				if($field == 'date_modified' || $field == 'date_entered')
2057
-				{
2058
-					$this->$field = $this->db->fromConvert($this->$field, 'datetime');
2059
-					if(empty($disable_date_format)) {
2060
-						$this->$field = $timedate->to_display_date_time($this->$field);
2061
-					}
2062
-				}
2063
-				elseif(isset($this->field_name_map[$field]['type']))
2064
-				{
2065
-					$type = $this->field_name_map[$field]['type'];
2066
-
2067
-					if($type == 'relate'  && isset($this->field_name_map[$field]['custom_module']))
2068
-					{
2069
-						$type = $this->field_name_map[$field]['type'];
2070
-					}
2071
-
2072
-					if($type == 'date')
2073
-					{
2074
-						if($this->$field == '0000-00-00')
2075
-						{
2076
-							$this->$field = '';
2077
-						} elseif(!empty($this->field_name_map[$field]['rel_field']))
2078
-						{
2079
-							$rel_field = $this->field_name_map[$field]['rel_field'];
2080
-
2081
-							if(!empty($this->$rel_field))
2082
-							{
2083
-								if(empty($disable_date_format)) {
2084
-									$mergetime = $timedate->merge_date_time($this->$field,$this->$rel_field);
2085
-									$this->$field = $timedate->to_display_date($mergetime);
2086
-									$this->$rel_field = $timedate->to_display_time($mergetime);
2087
-								}
2088
-							}
2089
-						}
2090
-						else
2091
-						{
2092
-							if(empty($disable_date_format)) {
2093
-								$this->$field = $timedate->to_display_date($this->$field, false);
2094
-							}
2095
-						}
2096
-					} elseif($type == 'datetime' || $type == 'datetimecombo')
2097
-					{
2098
-						if($this->$field == '0000-00-00 00:00:00')
2099
-						{
2100
-							$this->$field = '';
2101
-						}
2102
-						else
2103
-						{
2104
-							if(empty($disable_date_format)) {
2105
-								$this->$field = $timedate->to_display_date_time($this->$field, true, true);
2106
-							}
2107
-						}
2108
-					} elseif($type == 'time')
2109
-					{
2110
-						if($this->$field == '00:00:00')
2111
-						{
2112
-							$this->$field = '';
2113
-						} else
2114
-						{
2115
-							//$this->$field = from_db_convert($this->$field, 'time');
2116
-							if(empty($this->field_name_map[$field]['rel_field']) && empty($disable_date_format))
2117
-							{
2118
-								$this->$field = $timedate->to_display_time($this->$field,true, false);
2119
-							}
2120
-						}
2121
-					} elseif($type == 'encrypt' && empty($disable_date_format)){
2122
-						$this->$field = $this->decrypt_after_retrieve($this->$field);
2123
-					}
2124
-				}
2125
-			}
2126
-		}
2127
-	}
2030
+     * This function retrieves a record of the appropriate type from the DB.
2031
+     * It fills in all of the fields from the DB into the object it was called on.
2032
+     *
2033
+     * @param $id - If ID is specified, it overrides the current value of $this->id.  If not specified the current value of $this->id will be used.
2034
+     * @return this - The object that it was called apon or null if exactly 1 record was not found.
2035
+     *
2036
+     */
2037
+
2038
+    function check_date_relationships_load()
2039
+    {
2040
+        global $disable_date_format;
2041
+        global $timedate;
2042
+        if (empty($timedate))
2043
+            $timedate=TimeDate::getInstance();
2044
+
2045
+        if(empty($this->field_defs))
2046
+        {
2047
+            return;
2048
+        }
2049
+        foreach($this->field_defs as $fieldDef)
2050
+        {
2051
+            $field = $fieldDef['name'];
2052
+            if(!isset($this->processed_dates_times[$field]))
2053
+            {
2054
+                $this->processed_dates_times[$field] = '1';
2055
+                if(empty($this->$field)) continue;
2056
+                if($field == 'date_modified' || $field == 'date_entered')
2057
+                {
2058
+                    $this->$field = $this->db->fromConvert($this->$field, 'datetime');
2059
+                    if(empty($disable_date_format)) {
2060
+                        $this->$field = $timedate->to_display_date_time($this->$field);
2061
+                    }
2062
+                }
2063
+                elseif(isset($this->field_name_map[$field]['type']))
2064
+                {
2065
+                    $type = $this->field_name_map[$field]['type'];
2066
+
2067
+                    if($type == 'relate'  && isset($this->field_name_map[$field]['custom_module']))
2068
+                    {
2069
+                        $type = $this->field_name_map[$field]['type'];
2070
+                    }
2071
+
2072
+                    if($type == 'date')
2073
+                    {
2074
+                        if($this->$field == '0000-00-00')
2075
+                        {
2076
+                            $this->$field = '';
2077
+                        } elseif(!empty($this->field_name_map[$field]['rel_field']))
2078
+                        {
2079
+                            $rel_field = $this->field_name_map[$field]['rel_field'];
2080
+
2081
+                            if(!empty($this->$rel_field))
2082
+                            {
2083
+                                if(empty($disable_date_format)) {
2084
+                                    $mergetime = $timedate->merge_date_time($this->$field,$this->$rel_field);
2085
+                                    $this->$field = $timedate->to_display_date($mergetime);
2086
+                                    $this->$rel_field = $timedate->to_display_time($mergetime);
2087
+                                }
2088
+                            }
2089
+                        }
2090
+                        else
2091
+                        {
2092
+                            if(empty($disable_date_format)) {
2093
+                                $this->$field = $timedate->to_display_date($this->$field, false);
2094
+                            }
2095
+                        }
2096
+                    } elseif($type == 'datetime' || $type == 'datetimecombo')
2097
+                    {
2098
+                        if($this->$field == '0000-00-00 00:00:00')
2099
+                        {
2100
+                            $this->$field = '';
2101
+                        }
2102
+                        else
2103
+                        {
2104
+                            if(empty($disable_date_format)) {
2105
+                                $this->$field = $timedate->to_display_date_time($this->$field, true, true);
2106
+                            }
2107
+                        }
2108
+                    } elseif($type == 'time')
2109
+                    {
2110
+                        if($this->$field == '00:00:00')
2111
+                        {
2112
+                            $this->$field = '';
2113
+                        } else
2114
+                        {
2115
+                            //$this->$field = from_db_convert($this->$field, 'time');
2116
+                            if(empty($this->field_name_map[$field]['rel_field']) && empty($disable_date_format))
2117
+                            {
2118
+                                $this->$field = $timedate->to_display_time($this->$field,true, false);
2119
+                            }
2120
+                        }
2121
+                    } elseif($type == 'encrypt' && empty($disable_date_format)){
2122
+                        $this->$field = $this->decrypt_after_retrieve($this->$field);
2123
+                    }
2124
+                }
2125
+            }
2126
+        }
2127
+    }
2128 2128
 
2129 2129
     /**
2130 2130
      * This function processes the fields before save.
@@ -2136,21 +2136,21 @@  discard block
 block discarded – undo
2136 2136
     }
2137 2137
 
2138 2138
     /**
2139
-    * Removes formatting from values posted from the user interface.
2139
+     * Removes formatting from values posted from the user interface.
2140 2140
      * It only unformats numbers.  Function relies on user/system prefernce for format strings.
2141 2141
      *
2142 2142
      * Internal Function, do not override.
2143
-    */
2143
+     */
2144 2144
     function unformat_all_fields()
2145 2145
     {
2146 2146
         $GLOBALS['log']->deprecated('SugarBean.php: unformat_all_fields() is deprecated');
2147 2147
     }
2148 2148
 
2149 2149
     /**
2150
-    * This functions adds formatting to all number fields before presenting them to user interface.
2150
+     * This functions adds formatting to all number fields before presenting them to user interface.
2151 2151
      *
2152 2152
      * Internal function, do not override.
2153
-    */
2153
+     */
2154 2154
     function format_all_fields()
2155 2155
     {
2156 2156
         $GLOBALS['log']->deprecated('SugarBean.php: format_all_fields() is deprecated');
@@ -2190,8 +2190,8 @@  discard block
 block discarded – undo
2190 2190
                 case 'datetimecombo':
2191 2191
                     if(empty($this->$field)) break;
2192 2192
                     if ($this->$field == 'NULL') {
2193
-                    	$this->$field = '';
2194
-                    	break;
2193
+                        $this->$field = '';
2194
+                        break;
2195 2195
                     }
2196 2196
                     if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/',$this->$field) ) {
2197 2197
                         // This appears to be formatted in user date/time
@@ -2202,8 +2202,8 @@  discard block
 block discarded – undo
2202 2202
                 case 'date':
2203 2203
                     if(empty($this->$field)) break;
2204 2204
                     if ($this->$field == 'NULL') {
2205
-                    	$this->$field = '';
2206
-                    	break;
2205
+                        $this->$field = '';
2206
+                        break;
2207 2207
                     }
2208 2208
                     if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',$this->$field) ) {
2209 2209
                         // This date appears to be formatted in the user's format
@@ -2214,8 +2214,8 @@  discard block
 block discarded – undo
2214 2214
                 case 'time':
2215 2215
                     if(empty($this->$field)) break;
2216 2216
                     if ($this->$field == 'NULL') {
2217
-                    	$this->$field = '';
2218
-                    	break;
2217
+                        $this->$field = '';
2218
+                        break;
2219 2219
                     }
2220 2220
                     if ( preg_match('/(am|pm)/i',$this->$field) ) {
2221 2221
                         // This time appears to be formatted in the user's format
@@ -2235,7 +2235,7 @@  discard block
 block discarded – undo
2235 2235
                         $reformatted = true;
2236 2236
                     }
2237 2237
                     break;
2238
-               case 'uint':
2238
+                case 'uint':
2239 2239
                case 'ulong':
2240 2240
                case 'long':
2241 2241
                case 'short':
@@ -2248,21 +2248,21 @@  discard block
 block discarded – undo
2248 2248
                         $this->$field = (int)unformat_number($this->$field);
2249 2249
                         $reformatted = true;
2250 2250
                     }
2251
-                   break;
2252
-               case 'bool':
2251
+                    break;
2252
+                case 'bool':
2253 2253
                    if (empty($this->$field)) {
2254
-                       $this->$field = false;
2255
-                   } else if(true === $this->$field || 1 == $this->$field) {
2256
-                       $this->$field = true;
2257
-                   } else if(in_array(strval($this->$field), $boolean_false_values)) {
2258
-                       $this->$field = false;
2259
-                       $reformatted = true;
2260
-                   } else {
2261
-                       $this->$field = true;
2262
-                       $reformatted = true;
2263
-                   }
2264
-                   break;
2265
-               case 'encrypt':
2254
+                        $this->$field = false;
2255
+                    } else if(true === $this->$field || 1 == $this->$field) {
2256
+                        $this->$field = true;
2257
+                    } else if(in_array(strval($this->$field), $boolean_false_values)) {
2258
+                        $this->$field = false;
2259
+                        $reformatted = true;
2260
+                    } else {
2261
+                        $this->$field = true;
2262
+                        $reformatted = true;
2263
+                    }
2264
+                    break;
2265
+                case 'encrypt':
2266 2266
                     $this->$field = $this->encrpyt_before_save($this->$field);
2267 2267
                     break;
2268 2268
             }
@@ -2284,7 +2284,7 @@  discard block
 block discarded – undo
2284 2284
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
2285 2285
      *
2286 2286
      * Internal function, do not override.
2287
-    */
2287
+     */
2288 2288
     function retrieve($id = -1, $encode=true,$deleted=true)
2289 2289
     {
2290 2290
 
@@ -2340,17 +2340,17 @@  discard block
 block discarded – undo
2340 2340
             $this->custom_fields->fill_relationships();
2341 2341
         }
2342 2342
 
2343
-		$this->is_updated_dependent_fields = false;
2343
+        $this->is_updated_dependent_fields = false;
2344 2344
         $this->fill_in_additional_detail_fields();
2345 2345
         $this->fill_in_relationship_fields();
2346 2346
 // save related fields values for audit
2347
-         foreach ($this->get_related_fields() as $rel_field_name)
2348
-         {
2349
-             if (! empty($this->$rel_field_name['name']))
2350
-             {
2351
-                 $this->fetched_rel_row[$rel_field_name['name']] = $this->$rel_field_name['name'];
2352
-             }
2353
-         }
2347
+            foreach ($this->get_related_fields() as $rel_field_name)
2348
+            {
2349
+                if (! empty($this->$rel_field_name['name']))
2350
+                {
2351
+                    $this->fetched_rel_row[$rel_field_name['name']] = $this->$rel_field_name['name'];
2352
+                }
2353
+            }
2354 2354
         //make a copy of fields in the relationship_fields array. These field values will be used to
2355 2355
         //clear relationship.
2356 2356
         foreach ( $this->field_defs as $key => $def )
@@ -2363,7 +2363,7 @@  discard block
 block discarded – undo
2363 2363
                 }
2364 2364
                 else
2365 2365
                     $this->rel_fields_before_value[$key]=null;
2366
-           }
2366
+            }
2367 2367
         }
2368 2368
         if (isset($this->relationship_fields) && is_array($this->relationship_fields))
2369 2369
         {
@@ -2418,14 +2418,14 @@  discard block
 block discarded – undo
2418 2418
 
2419 2419
 
2420 2420
     /**
2421
-    * Add any required joins to the list count query.  The joins are required if there
2422
-    * is a field in the $where clause that needs to be joined.
2423
-    *
2424
-    * @param string $query
2425
-    * @param string $where
2426
-    *
2427
-    * Internal Function, do Not override.
2428
-    */
2421
+     * Add any required joins to the list count query.  The joins are required if there
2422
+     * is a field in the $where clause that needs to be joined.
2423
+     *
2424
+     * @param string $query
2425
+     * @param string $where
2426
+     *
2427
+     * Internal Function, do Not override.
2428
+     */
2429 2429
     function add_list_count_joins(&$query, $where)
2430 2430
     {
2431 2431
         $custom_join = $this->getCustomJoin();
@@ -2434,15 +2434,15 @@  discard block
 block discarded – undo
2434 2434
     }
2435 2435
 
2436 2436
     /**
2437
-    * Changes the select expression of the given query to be 'count(*)' so you
2438
-    * can get the number of items the query will return.  This is used to
2439
-    * populate the upper limit on ListViews.
2437
+     * Changes the select expression of the given query to be 'count(*)' so you
2438
+     * can get the number of items the query will return.  This is used to
2439
+     * populate the upper limit on ListViews.
2440 2440
      *
2441 2441
      * @param string $query Select query string
2442 2442
      * @return string count query
2443 2443
      *
2444 2444
      * Internal function, do not override.
2445
-    */
2445
+     */
2446 2446
     function create_list_count_query($query)
2447 2447
     {
2448 2448
         // remove the 'order by' clause which is expected to be at the end of the query
@@ -2495,21 +2495,21 @@  discard block
 block discarded – undo
2495 2495
     }
2496 2496
 
2497 2497
     /**
2498
-    * This function returns a paged list of the current object type.  It is intended to allow for
2499
-    * hopping back and forth through pages of data.  It only retrieves what is on the current page.
2500
-    *
2501
-    * @internal This method must be called on a new instance.  It trashes the values of all the fields in the current one.
2502
-    * @param string $order_by
2503
-    * @param string $where Additional where clause
2504
-    * @param int $row_offset Optaional,default 0, starting row number
2505
-    * @param init $limit Optional, default -1
2506
-    * @param int $max Optional, default -1
2507
-    * @param boolean $show_deleted Optional, default 0, if set to 1 system will show deleted records.
2508
-    * @return array Fetched data.
2509
-    *
2510
-    * Internal function, do not override.
2511
-    *
2512
-    */
2498
+     * This function returns a paged list of the current object type.  It is intended to allow for
2499
+     * hopping back and forth through pages of data.  It only retrieves what is on the current page.
2500
+     *
2501
+     * @internal This method must be called on a new instance.  It trashes the values of all the fields in the current one.
2502
+     * @param string $order_by
2503
+     * @param string $where Additional where clause
2504
+     * @param int $row_offset Optaional,default 0, starting row number
2505
+     * @param init $limit Optional, default -1
2506
+     * @param int $max Optional, default -1
2507
+     * @param boolean $show_deleted Optional, default 0, if set to 1 system will show deleted records.
2508
+     * @return array Fetched data.
2509
+     *
2510
+     * Internal function, do not override.
2511
+     *
2512
+     */
2513 2513
     function get_list($order_by = "", $where = "", $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $singleSelect=false, $select_fields = array())
2514 2514
     {
2515 2515
         $GLOBALS['log']->debug("get_list:  order_by = '$order_by' and where = '$where' and limit = '$limit'");
@@ -2539,15 +2539,15 @@  discard block
 block discarded – undo
2539 2539
     }
2540 2540
 
2541 2541
     /**
2542
-    * Prefixes column names with this bean's table name.
2543
-    *
2544
-    * @param string $order_by  Order by clause to be processed
2545
-    * @param SugarBean $submodule name of the module this order by clause is for
2546
-    * @param boolean $suppress_table_name Whether table name should be suppressed
2547
-    * @return string Processed order by clause
2548
-    *
2549
-    * Internal function, do not override.
2550
-    */
2542
+     * Prefixes column names with this bean's table name.
2543
+     *
2544
+     * @param string $order_by  Order by clause to be processed
2545
+     * @param SugarBean $submodule name of the module this order by clause is for
2546
+     * @param boolean $suppress_table_name Whether table name should be suppressed
2547
+     * @return string Processed order by clause
2548
+     *
2549
+     * Internal function, do not override.
2550
+     */
2551 2551
     public function process_order_by($order_by, $submodule = null, $suppress_table_name = false)
2552 2552
     {
2553 2553
         if (empty($order_by))
@@ -2621,21 +2621,21 @@  discard block
 block discarded – undo
2621 2621
 
2622 2622
 
2623 2623
     /**
2624
-    * Returns a detail object like retrieving of the current object type.
2625
-    *
2626
-    * It is intended for use in navigation buttons on the DetailView.  It will pass an offset and limit argument to the sql query.
2627
-    * @internal This method must be called on a new instance.  It overrides the values of all the fields in the current one.
2628
-    *
2629
-    * @param string $order_by
2630
-    * @param string $where Additional where clause
2631
-    * @param int $row_offset Optaional,default 0, starting row number
2632
-    * @param init $limit Optional, default -1
2633
-    * @param int $max Optional, default -1
2634
-    * @param boolean $show_deleted Optioanl, default 0, if set to 1 system will show deleted records.
2635
-    * @return array Fetched data.
2636
-    *
2637
-    * Internal function, do not override.
2638
-    */
2624
+     * Returns a detail object like retrieving of the current object type.
2625
+     *
2626
+     * It is intended for use in navigation buttons on the DetailView.  It will pass an offset and limit argument to the sql query.
2627
+     * @internal This method must be called on a new instance.  It overrides the values of all the fields in the current one.
2628
+     *
2629
+     * @param string $order_by
2630
+     * @param string $where Additional where clause
2631
+     * @param int $row_offset Optaional,default 0, starting row number
2632
+     * @param init $limit Optional, default -1
2633
+     * @param int $max Optional, default -1
2634
+     * @param boolean $show_deleted Optioanl, default 0, if set to 1 system will show deleted records.
2635
+     * @return array Fetched data.
2636
+     *
2637
+     * Internal function, do not override.
2638
+     */
2639 2639
     function get_detail($order_by = "", $where = "",  $offset = 0, $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0)
2640 2640
     {
2641 2641
         $GLOBALS['log']->debug("get_detail:  order_by = '$order_by' and where = '$where' and limit = '$limit' and offset = '$offset'");
@@ -2659,25 +2659,25 @@  discard block
 block discarded – undo
2659 2659
             }
2660 2660
         }
2661 2661
 
2662
-		/* BEGIN - SECURITY GROUPS */
2663
-    	if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
2664
-    	{
2665
-			require_once('modules/SecurityGroups/SecurityGroup.php');
2666
-    		global $current_user;
2667
-    		$owner_where = $this->getOwnerWhere($current_user->id);
2668
-    		$group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
2669
-	    	if(!empty($owner_where)){
2670
-				if(empty($where))
2671
-	    		{
2672
-	    			$where = " (".  $owner_where." or ".$group_where.") ";
2673
-	    		} else {
2674
-	    			$where .= " AND (".  $owner_where." or ".$group_where.") ";
2675
-	    		}
2676
-			} else {
2677
-				$where .= ' AND '.  $group_where;
2678
-			}
2679
-    	}
2680
-    	/* END - SECURITY GROUPS */
2662
+        /* BEGIN - SECURITY GROUPS */
2663
+        if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
2664
+        {
2665
+            require_once('modules/SecurityGroups/SecurityGroup.php');
2666
+            global $current_user;
2667
+            $owner_where = $this->getOwnerWhere($current_user->id);
2668
+            $group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
2669
+            if(!empty($owner_where)){
2670
+                if(empty($where))
2671
+                {
2672
+                    $where = " (".  $owner_where." or ".$group_where.") ";
2673
+                } else {
2674
+                    $where .= " AND (".  $owner_where." or ".$group_where.") ";
2675
+                }
2676
+            } else {
2677
+                $where .= ' AND '.  $group_where;
2678
+            }
2679
+        }
2680
+        /* END - SECURITY GROUPS */
2681 2681
         $query = $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted, $offset);
2682 2682
 
2683 2683
         //Add Limit and Offset to query
@@ -2687,16 +2687,16 @@  discard block
 block discarded – undo
2687 2687
     }
2688 2688
 
2689 2689
     /**
2690
-    * Fetches data from all related tables.
2691
-    *
2692
-    * @param object $child_seed
2693
-    * @param string $related_field_name relation to fetch data for
2694
-    * @param string $order_by Optional, default empty
2695
-    * @param string $where Optional, additional where clause
2696
-    * @return array Fetched data.
2697
-    *
2698
-    * Internal function, do not override.
2699
-    */
2690
+     * Fetches data from all related tables.
2691
+     *
2692
+     * @param object $child_seed
2693
+     * @param string $related_field_name relation to fetch data for
2694
+     * @param string $order_by Optional, default empty
2695
+     * @param string $where Optional, additional where clause
2696
+     * @return array Fetched data.
2697
+     *
2698
+     * Internal function, do not override.
2699
+     */
2700 2700
     function get_related_list($child_seed,$related_field_name, $order_by = "", $where = "",
2701 2701
     $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0)
2702 2702
     {
@@ -3072,13 +3072,13 @@  discard block
 block discarded – undo
3072 3072
 
3073 3073
 
3074 3074
     /**
3075
-    * Returns a full (ie non-paged) list of the current object type.
3076
-    *
3077
-    * @param string $order_by the order by SQL parameter. defaults to ""
3078
-    * @param string $where where clause. defaults to ""
3079
-    * @param boolean $check_dates. defaults to false
3080
-    * @param int $show_deleted show deleted records. defaults to 0
3081
-    */
3075
+     * Returns a full (ie non-paged) list of the current object type.
3076
+     *
3077
+     * @param string $order_by the order by SQL parameter. defaults to ""
3078
+     * @param string $where where clause. defaults to ""
3079
+     * @param boolean $check_dates. defaults to false
3080
+     * @param int $show_deleted show deleted records. defaults to 0
3081
+     */
3082 3082
     function get_full_list($order_by = "", $where = "", $check_dates=false, $show_deleted = 0)
3083 3083
     {
3084 3084
         $GLOBALS['log']->debug("get_full_list:  order_by = '$order_by' and where = '$where'");
@@ -3106,7 +3106,7 @@  discard block
 block discarded – undo
3106 3106
      * @param boolean $singleSelect Optional, default false.
3107 3107
      * @return String select query string, optionally an array value will be returned if $return_array= true.
3108 3108
      */
3109
-	function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false, $ifListForExport = false)
3109
+    function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false, $ifListForExport = false)
3110 3110
     {
3111 3111
         global $beanFiles, $beanList;
3112 3112
         $selectedFields = array();
@@ -3126,41 +3126,41 @@  discard block
 block discarded – undo
3126 3126
                 $where .= ' AND '.  $owner_where;
3127 3127
             }
3128 3128
         }
3129
-		/* BEGIN - SECURITY GROUPS */
3130
-    	global $current_user, $sugar_config;
3131
-    	if($this->module_dir == 'Users' && !is_admin($current_user)
3132
-				&& isset($sugar_config['securitysuite_filter_user_list'])
3133
-				&& $sugar_config['securitysuite_filter_user_list'] == true
3134
-    	) {
3135
-			require_once('modules/SecurityGroups/SecurityGroup.php');
3136
-    		global $current_user;
3137
-    		$group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
3138
-    		//$group_where = "user_name = 'admin'";
3139
-    		if(empty($where))
3140
-    		{
3141
-    			$where = " (".$group_where.") ";
3142
-    		} else {
3143
-    			$where .= " AND (".$group_where.") ";
3144
-    		}
3145
-    	} else
3146
-    	if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
3147
-    	{
3148
-			require_once('modules/SecurityGroups/SecurityGroup.php');
3149
-    		global $current_user;
3150
-    		$owner_where = $this->getOwnerWhere($current_user->id);
3151
-    		$group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
3152
-	    	if(!empty($owner_where)){
3153
-				if(empty($where))
3154
-	    		{
3155
-	    			$where = " (".  $owner_where." or ".$group_where.") ";
3156
-	    		} else {
3157
-	    			$where .= " AND (".  $owner_where." or ".$group_where.") ";
3158
-	    		}
3159
-			} else {
3160
-				$where .= ' AND '.  $group_where;
3161
-			}
3162
-    	}
3163
-    	/* END - SECURITY GROUPS */
3129
+        /* BEGIN - SECURITY GROUPS */
3130
+        global $current_user, $sugar_config;
3131
+        if($this->module_dir == 'Users' && !is_admin($current_user)
3132
+                && isset($sugar_config['securitysuite_filter_user_list'])
3133
+                && $sugar_config['securitysuite_filter_user_list'] == true
3134
+        ) {
3135
+            require_once('modules/SecurityGroups/SecurityGroup.php');
3136
+            global $current_user;
3137
+            $group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
3138
+            //$group_where = "user_name = 'admin'";
3139
+            if(empty($where))
3140
+            {
3141
+                $where = " (".$group_where.") ";
3142
+            } else {
3143
+                $where .= " AND (".$group_where.") ";
3144
+            }
3145
+        } else
3146
+        if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
3147
+        {
3148
+            require_once('modules/SecurityGroups/SecurityGroup.php');
3149
+            global $current_user;
3150
+            $owner_where = $this->getOwnerWhere($current_user->id);
3151
+            $group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
3152
+            if(!empty($owner_where)){
3153
+                if(empty($where))
3154
+                {
3155
+                    $where = " (".  $owner_where." or ".$group_where.") ";
3156
+                } else {
3157
+                    $where .= " AND (".  $owner_where." or ".$group_where.") ";
3158
+                }
3159
+            } else {
3160
+                $where .= ' AND '.  $group_where;
3161
+            }
3162
+        }
3163
+        /* END - SECURITY GROUPS */
3164 3164
         if(!empty($params['distinct']))
3165 3165
         {
3166 3166
             $distinct = ' DISTINCT ';
@@ -3246,24 +3246,24 @@  discard block
 block discarded – undo
3246 3246
 
3247 3247
         $used_join_key = array();
3248 3248
 
3249
-	//walk through the fields and for every relationship field add their relationship_info field
3250
-	//relationshipfield-aliases are resolved in SugarBean::create_new_list_query through their relationship_info field
3251
-	$addrelate = array();
3252
-	foreach($fields as $field=>$value)
3253
-	{
3254
-		if (isset($this->field_defs[$field]) && isset($this->field_defs[$field]['source']) && 
3255
-			$this->field_defs[$field]['source'] == 'non-db')
3256
-		{
3257
-			$addrelatefield = $this->get_relationship_field($field);
3258
-			if ($addrelatefield)
3259
-				$addrelate[$addrelatefield] = true;
3260
-		}
3261
-		if(!empty($this->field_defs[$field]['id_name'])){
3262
-			$addrelate[$this->field_defs[$field]['id_name']] = true;
3263
-		}
3264
-	}
3265
-
3266
-	$fields = array_merge($addrelate, $fields);
3249
+    //walk through the fields and for every relationship field add their relationship_info field
3250
+    //relationshipfield-aliases are resolved in SugarBean::create_new_list_query through their relationship_info field
3251
+    $addrelate = array();
3252
+    foreach($fields as $field=>$value)
3253
+    {
3254
+        if (isset($this->field_defs[$field]) && isset($this->field_defs[$field]['source']) && 
3255
+            $this->field_defs[$field]['source'] == 'non-db')
3256
+        {
3257
+            $addrelatefield = $this->get_relationship_field($field);
3258
+            if ($addrelatefield)
3259
+                $addrelate[$addrelatefield] = true;
3260
+        }
3261
+        if(!empty($this->field_defs[$field]['id_name'])){
3262
+            $addrelate[$this->field_defs[$field]['id_name']] = true;
3263
+        }
3264
+    }
3265
+
3266
+    $fields = array_merge($addrelate, $fields);
3267 3267
 
3268 3268
         foreach($fields as $field=>$value)
3269 3269
         {
@@ -3296,7 +3296,7 @@  discard block
 block discarded – undo
3296 3296
             //in opportunities module remove the contact_role/opportunity_role field.
3297 3297
             if (isset($data['relationship_fields']) and !empty($data['relationship_fields']))
3298 3298
             {
3299
-		$process_field = false;
3299
+        $process_field = false;
3300 3300
                 foreach ($data['relationship_fields'] as $field_name)
3301 3301
                 {
3302 3302
                     if (isset($fields[$field_name]))
@@ -3306,8 +3306,8 @@  discard block
 block discarded – undo
3306 3306
                     }
3307 3307
                 }
3308 3308
 		
3309
-            	if (!$process_field)
3310
-                	continue;
3309
+                if (!$process_field)
3310
+                    continue;
3311 3311
             }
3312 3312
 
3313 3313
             if(  (!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter) ))
@@ -3414,27 +3414,27 @@  discard block
 block discarded – undo
3414 3414
                     $rel_module = $this->$data['link']->getRelatedModuleName();
3415 3415
                     $table_joined = !empty($joined_tables[$params['join_table_alias']]) || (!empty($joined_tables[$params['join_table_link_alias']]) && isset($data['link_type']) && $data['link_type'] == 'relationship_info');
3416 3416
 
3417
-					//if rname is set to 'name', and bean files exist, then check if field should be a concatenated name
3418
-					global $beanFiles, $beanList;
3417
+                    //if rname is set to 'name', and bean files exist, then check if field should be a concatenated name
3418
+                    global $beanFiles, $beanList;
3419 3419
                     // °3/21/2014 FIX NS-TEAM - Relationship fields could not be displayed in subpanels
3420 3420
                     //if($data['rname'] && !empty($beanFiles[$beanList[$rel_module]])) {
3421 3421
                     if(isset($data['rname']) && $data['rname'] == 'name' && !empty($beanFiles[$beanList[$rel_module]])) {
3422 3422
 
3423
-						//create an instance of the related bean
3424
-						require_once($beanFiles[$beanList[$rel_module]]);
3425
-						$rel_mod = new $beanList[$rel_module]();
3426
-						//if bean has first and last name fields, then name should be concatenated
3427
-						if(isset($rel_mod->field_name_map['first_name']) && isset($rel_mod->field_name_map['last_name'])){
3428
-								$data['db_concat_fields'] = array(0=>'first_name', 1=>'last_name');
3429
-						}
3430
-					}
3423
+                        //create an instance of the related bean
3424
+                        require_once($beanFiles[$beanList[$rel_module]]);
3425
+                        $rel_mod = new $beanList[$rel_module]();
3426
+                        //if bean has first and last name fields, then name should be concatenated
3427
+                        if(isset($rel_mod->field_name_map['first_name']) && isset($rel_mod->field_name_map['last_name'])){
3428
+                                $data['db_concat_fields'] = array(0=>'first_name', 1=>'last_name');
3429
+                        }
3430
+                    }
3431 3431
 
3432 3432
 
3433
-    				if($join['type'] == 'many-to-many')
3434
-    				{
3435
-    					if(empty($ret_array['secondary_select']))
3436
-    					{
3437
-    						$ret_array['secondary_select'] = " SELECT $this->table_name.id ref_id  ";
3433
+                    if($join['type'] == 'many-to-many')
3434
+                    {
3435
+                        if(empty($ret_array['secondary_select']))
3436
+                        {
3437
+                            $ret_array['secondary_select'] = " SELECT $this->table_name.id ref_id  ";
3438 3438
 
3439 3439
                             if(!empty($beanFiles[$beanList[$rel_module]]) && $join_primary)
3440 3440
                             {
@@ -3546,42 +3546,42 @@  discard block
 block discarded – undo
3546 3546
                     // and this code changes accounts to jt4 as there is a self join with the accounts table.
3547 3547
                     //Martin fix #27494
3548 3548
                     if(isset($data['db_concat_fields'])){
3549
-                    	$buildWhere = false;
3549
+                        $buildWhere = false;
3550 3550
                         if(in_array('first_name', $data['db_concat_fields']) && in_array('last_name', $data['db_concat_fields']))
3551
-                    	{
3552
-                     	   $exp = '/\(\s*?'.$data['name'].'.*?\%\'\s*?\)/';
3553
-                    	   if(preg_match($exp, $where, $matches))
3554
-                    	   {
3555
-                    	   	  $search_expression = $matches[0];
3556
-                    	   	  //Create three search conditions - first + last, first, last
3557
-                    	   	  $first_name_search = str_replace($data['name'], $params['join_table_alias'] . '.first_name', $search_expression);
3558
-                    	   	  $last_name_search = str_replace($data['name'], $params['join_table_alias'] . '.last_name', $search_expression);
3559
-							  $full_name_search = str_replace($data['name'], $this->db->concat($params['join_table_alias'], $data['db_concat_fields']), $search_expression);
3560
-							  $buildWhere = true;
3561
-							  $where = str_replace($search_expression, '(' . $full_name_search . ' OR ' . $first_name_search . ' OR ' . $last_name_search . ')', $where);
3562
-                    	   }
3563
-                    	}
3564
-
3565
-                    	if(!$buildWhere)
3566
-                    	{
3567
-	                       $db_field = $this->db->concat($params['join_table_alias'], $data['db_concat_fields']);
3568
-	                       $where = preg_replace('/'.$data['name'].'/', $db_field, $where);
3569
-
3570
-				// For relationship fields replace their alias by the corresponsding link table and r_name
3571
-				if(isset($data['relationship_fields']))
3572
-					foreach($data['relationship_fields'] as $r_name=>$alias_name)
3573
-					{
3574
-						$db_field = $this->db->concat($params['join_table_link_alias'], $r_name);
3575
-						$where = preg_replace('/' . $alias_name . '/', $db_field, $where);
3576
-					}
3577
-                    	}
3551
+                        {
3552
+                            $exp = '/\(\s*?'.$data['name'].'.*?\%\'\s*?\)/';
3553
+                            if(preg_match($exp, $where, $matches))
3554
+                            {
3555
+                                    $search_expression = $matches[0];
3556
+                                    //Create three search conditions - first + last, first, last
3557
+                                    $first_name_search = str_replace($data['name'], $params['join_table_alias'] . '.first_name', $search_expression);
3558
+                                    $last_name_search = str_replace($data['name'], $params['join_table_alias'] . '.last_name', $search_expression);
3559
+                                $full_name_search = str_replace($data['name'], $this->db->concat($params['join_table_alias'], $data['db_concat_fields']), $search_expression);
3560
+                                $buildWhere = true;
3561
+                                $where = str_replace($search_expression, '(' . $full_name_search . ' OR ' . $first_name_search . ' OR ' . $last_name_search . ')', $where);
3562
+                            }
3563
+                        }
3564
+
3565
+                        if(!$buildWhere)
3566
+                        {
3567
+                            $db_field = $this->db->concat($params['join_table_alias'], $data['db_concat_fields']);
3568
+                            $where = preg_replace('/'.$data['name'].'/', $db_field, $where);
3569
+
3570
+                // For relationship fields replace their alias by the corresponsding link table and r_name
3571
+                if(isset($data['relationship_fields']))
3572
+                    foreach($data['relationship_fields'] as $r_name=>$alias_name)
3573
+                    {
3574
+                        $db_field = $this->db->concat($params['join_table_link_alias'], $r_name);
3575
+                        $where = preg_replace('/' . $alias_name . '/', $db_field, $where);
3576
+                    }
3577
+                        }
3578 3578
                     }else{
3579 3579
                         $where = preg_replace('/(^|[\s(])' . $data['name'] . '/', '${1}' . $params['join_table_alias'] . '.'.$data['rname'], $where);
3580 3580
 
3581
-			// For relationship fields replace their alias by the corresponsding link table and r_name
3582
-			if(isset($data['relationship_fields']))
3583
-				foreach($data['relationship_fields'] as $r_name=>$alias_name)
3584
-					$where = preg_replace('/(^|[\s(])' . $alias_name . '/', '${1}' . $params['join_table_link_alias'] . '.'.$r_name, $where);
3581
+            // For relationship fields replace their alias by the corresponsding link table and r_name
3582
+            if(isset($data['relationship_fields']))
3583
+                foreach($data['relationship_fields'] as $r_name=>$alias_name)
3584
+                    $where = preg_replace('/(^|[\s(])' . $alias_name . '/', '${1}' . $params['join_table_link_alias'] . '.'.$r_name, $where);
3585 3585
                     }
3586 3586
                     if(!$table_joined)
3587 3587
                     {
@@ -3610,12 +3610,12 @@  discard block
 block discarded – undo
3610 3610
 
3611 3611
         }
3612 3612
 
3613
-	if ($ifListForExport) {
3614
-		if(isset($this->field_defs['email1'])) {
3615
-			$ret_array['select'].= " ,email_addresses.email_address email1";
3616
-			$ret_array['from'].= " LEFT JOIN email_addr_bean_rel on {$this->table_name}.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='{$this->module_dir}' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ";
3617
-		}
3618
-	}
3613
+    if ($ifListForExport) {
3614
+        if(isset($this->field_defs['email1'])) {
3615
+            $ret_array['select'].= " ,email_addresses.email_address email1";
3616
+            $ret_array['from'].= " LEFT JOIN email_addr_bean_rel on {$this->table_name}.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='{$this->module_dir}' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ";
3617
+        }
3618
+    }
3619 3619
 
3620 3620
         $where_auto = '1=1';
3621 3621
         if($show_deleted == 0)
@@ -3650,18 +3650,18 @@  discard block
 block discarded – undo
3650 3650
         return  $ret_array['select'] . $ret_array['from'] . $ret_array['where']. $ret_array['order_by'];
3651 3651
     }
3652 3652
 
3653
-	// Check if field is defined through a relationship_info field, add this field when not present 
3654
-	function get_relationship_field($field)
3655
-	{
3656
-		foreach ($this->field_defs as $field_def => $value)
3657
-		{
3658
-			if (isset($value['relationship_fields']) && 
3659
-				in_array($field, $value['relationship_fields']) )
3660
-				return $field_def;
3661
-		}
3653
+    // Check if field is defined through a relationship_info field, add this field when not present 
3654
+    function get_relationship_field($field)
3655
+    {
3656
+        foreach ($this->field_defs as $field_def => $value)
3657
+        {
3658
+            if (isset($value['relationship_fields']) && 
3659
+                in_array($field, $value['relationship_fields']) )
3660
+                return $field_def;
3661
+        }
3662 3662
 
3663
-		return false;
3664
-	}
3663
+        return false;
3664
+    }
3665 3665
 
3666 3666
     /**
3667 3667
      * Returns parent record data for objects that store relationship information
@@ -3768,8 +3768,8 @@  discard block
 block discarded – undo
3768 3768
         global $sugar_config;
3769 3769
         $db = DBManagerFactory::getInstance('listviews');
3770 3770
         /**
3771
-        * if the row_offset is set to 'end' go to the end of the list
3772
-        */
3771
+         * if the row_offset is set to 'end' go to the end of the list
3772
+         */
3773 3773
         $toEnd = strval($row_offset) == 'end';
3774 3774
         $GLOBALS['log']->debug("process_list_query: ".$query);
3775 3775
         if($max_per_page == -1)
@@ -3897,13 +3897,13 @@  discard block
 block discarded – undo
3897 3897
     }
3898 3898
 
3899 3899
     /**
3900
-    * Returns the number of rows that the given SQL query should produce
3900
+     * Returns the number of rows that the given SQL query should produce
3901 3901
      *
3902 3902
      * Internal function, do not override.
3903 3903
      * @param string $query valid select  query
3904 3904
      * @param boolean $is_count_query Optional, Default false, set to true if passed query is a count query.
3905 3905
      * @return int count of rows found
3906
-    */
3906
+     */
3907 3907
     function _get_num_rows_in_query($query, $is_count_query=false)
3908 3908
     {
3909 3909
         $num_rows_in_query = 0;
@@ -3945,8 +3945,8 @@  discard block
 block discarded – undo
3945 3945
     {
3946 3946
         $db = DBManagerFactory::getInstance('listviews');
3947 3947
         /**
3948
-        * if the row_offset is set to 'end' go to the end of the list
3949
-        */
3948
+         * if the row_offset is set to 'end' go to the end of the list
3949
+         */
3950 3950
         $toEnd = strval($row_offset) == 'end';
3951 3951
         global $sugar_config;
3952 3952
         $use_count_query=false;
@@ -4184,7 +4184,7 @@  discard block
 block discarded – undo
4184 4184
             }
4185 4185
             if(!empty($sugar_config['disable_count_query']) && !empty($limit))
4186 4186
             {
4187
-            	//C.L. Bug 43535 - Use the $index value to set the $rows_found value here
4187
+                //C.L. Bug 43535 - Use the $index value to set the $rows_found value here
4188 4188
                 $rows_found = isset($index) ? $index : $row_offset + count($list);
4189 4189
 
4190 4190
                 if(count($list) >= $limit)
@@ -4334,28 +4334,28 @@  discard block
 block discarded – undo
4334 4334
     }
4335 4335
 
4336 4336
     /**
4337
-    * Tracks the viewing of a detail record.
4338
-    * This leverages get_summary_text() which is object specific.
4339
-    *
4340
-    * Internal function, do not override.
4341
-    * @param string $user_id - String value of the user that is viewing the record.
4342
-    * @param string $current_module - String value of the module being processed.
4343
-    * @param string $current_view - String value of the current view
4344
-	*/
4345
-	function track_view($user_id, $current_module, $current_view='')
4346
-	{
4347
-	    $trackerManager = TrackerManager::getInstance();
4348
-		if($monitor = $trackerManager->getMonitor('tracker')){
4349
-	        $monitor->setValue('date_modified', $GLOBALS['timedate']->nowDb());
4350
-	        $monitor->setValue('user_id', $user_id);
4351
-	        $monitor->setValue('module_name', $current_module);
4352
-	        $monitor->setValue('action', $current_view);
4353
-	        $monitor->setValue('item_id', $this->id);
4354
-	        $monitor->setValue('item_summary', $this->get_summary_text());
4355
-	        $monitor->setValue('visible', $this->tracker_visibility);
4356
-	        $trackerManager->saveMonitor($monitor);
4357
-		}
4358
-	}
4337
+     * Tracks the viewing of a detail record.
4338
+     * This leverages get_summary_text() which is object specific.
4339
+     *
4340
+     * Internal function, do not override.
4341
+     * @param string $user_id - String value of the user that is viewing the record.
4342
+     * @param string $current_module - String value of the module being processed.
4343
+     * @param string $current_view - String value of the current view
4344
+     */
4345
+    function track_view($user_id, $current_module, $current_view='')
4346
+    {
4347
+        $trackerManager = TrackerManager::getInstance();
4348
+        if($monitor = $trackerManager->getMonitor('tracker')){
4349
+            $monitor->setValue('date_modified', $GLOBALS['timedate']->nowDb());
4350
+            $monitor->setValue('user_id', $user_id);
4351
+            $monitor->setValue('module_name', $current_module);
4352
+            $monitor->setValue('action', $current_view);
4353
+            $monitor->setValue('item_id', $this->id);
4354
+            $monitor->setValue('item_summary', $this->get_summary_text());
4355
+            $monitor->setValue('visible', $this->tracker_visibility);
4356
+            $trackerManager->saveMonitor($monitor);
4357
+        }
4358
+    }
4359 4359
 
4360 4360
     /**
4361 4361
      * Returns the summary text that should show up in the recent history list for this object.
@@ -4368,12 +4368,12 @@  discard block
 block discarded – undo
4368 4368
     }
4369 4369
 
4370 4370
     /**
4371
-    * This is designed to be overridden and add specific fields to each record.
4372
-    * This allows the generic query to fill in the major fields, and then targeted
4373
-    * queries to get related fields and add them to the record.  The contact's
4374
-    * account for instance.  This method is only used for populating extra fields
4375
-    * in lists.
4376
-    */
4371
+     * This is designed to be overridden and add specific fields to each record.
4372
+     * This allows the generic query to fill in the major fields, and then targeted
4373
+     * queries to get related fields and add them to the record.  The contact's
4374
+     * account for instance.  This method is only used for populating extra fields
4375
+     * in lists.
4376
+     */
4377 4377
     function fill_in_additional_list_fields(){
4378 4378
         if(!empty($this->field_defs['parent_name']) && empty($this->parent_name)){
4379 4379
             $this->fill_in_additional_parent_fields();
@@ -4381,12 +4381,12 @@  discard block
 block discarded – undo
4381 4381
     }
4382 4382
 
4383 4383
     /**
4384
-    * This is designed to be overridden and add specific fields to each record.
4385
-    * This allows the generic query to fill in the major fields, and then targeted
4386
-    * queries to get related fields and add them to the record.  The contact's
4387
-    * account for instance.  This method is only used for populating extra fields
4388
-    * in the detail form
4389
-    */
4384
+     * This is designed to be overridden and add specific fields to each record.
4385
+     * This allows the generic query to fill in the major fields, and then targeted
4386
+     * queries to get related fields and add them to the record.  The contact's
4387
+     * account for instance.  This method is only used for populating extra fields
4388
+     * in the detail form
4389
+     */
4390 4390
     function fill_in_additional_detail_fields()
4391 4391
     {
4392 4392
         if(!empty($this->field_defs['assigned_user_name']) && !empty($this->assigned_user_id)){
@@ -4394,20 +4394,20 @@  discard block
 block discarded – undo
4394 4394
             $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
4395 4395
 
4396 4396
         }
4397
-		if(!empty($this->field_defs['created_by']) && !empty($this->created_by))
4398
-		$this->created_by_name = get_assigned_user_name($this->created_by);
4399
-		if(!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4400
-		$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
4397
+        if(!empty($this->field_defs['created_by']) && !empty($this->created_by))
4398
+        $this->created_by_name = get_assigned_user_name($this->created_by);
4399
+        if(!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4400
+        $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
4401 4401
 
4402
-		if(!empty($this->field_defs['parent_name'])){
4403
-			$this->fill_in_additional_parent_fields();
4404
-		}
4402
+        if(!empty($this->field_defs['parent_name'])){
4403
+            $this->fill_in_additional_parent_fields();
4404
+        }
4405 4405
     }
4406 4406
 
4407 4407
     /**
4408
-    * This is desgined to be overridden or called from extending bean. This method
4409
-    * will fill in any parent_name fields.
4410
-    */
4408
+     * This is desgined to be overridden or called from extending bean. This method
4409
+     * will fill in any parent_name fields.
4410
+     */
4411 4411
     function fill_in_additional_parent_fields() {
4412 4412
 
4413 4413
         if(!empty($this->parent_id) && !empty($this->last_parent_id) && $this->last_parent_id == $this->parent_id){
@@ -4448,8 +4448,8 @@  discard block
 block discarded – undo
4448 4448
     }
4449 4449
 
4450 4450
     /**
4451
-    * Fill in fields where type = relate
4452
-    */
4451
+     * Fill in fields where type = relate
4452
+     */
4453 4453
     function fill_in_relationship_fields(){
4454 4454
         global $fill_in_rel_depth;
4455 4455
         if(empty($fill_in_rel_depth) || $fill_in_rel_depth < 0)
@@ -4473,7 +4473,7 @@  discard block
 block discarded – undo
4473 4473
 
4474 4474
                     if (empty($this->$id_name))
4475 4475
                     {
4476
-                       $this->fill_in_link_field($id_name, $field);
4476
+                        $this->fill_in_link_field($id_name, $field);
4477 4477
                     }
4478 4478
                     if(!empty($this->$id_name) && ( $this->object_name != $related_module || ( $this->object_name == $related_module && $this->$id_name != $this->id ))){
4479 4479
                         if(isset($GLOBALS['beanList'][ $related_module])){
@@ -4499,7 +4499,7 @@  discard block
 block discarded – undo
4499 4499
                     if(!empty($this->$id_name) && isset($this->$name))
4500 4500
                     {
4501 4501
                         if(!isset($field['additionalFields']))
4502
-                           $field['additionalFields'] = array();
4502
+                            $field['additionalFields'] = array();
4503 4503
                         if(!empty($field['rname']))
4504 4504
                         {
4505 4505
                             $field['additionalFields'][$field['rname']]= $name;
@@ -4517,8 +4517,8 @@  discard block
 block discarded – undo
4517 4517
     }
4518 4518
 
4519 4519
     /**
4520
-    * This is a helper function that is used to quickly created indexes when creating tables.
4521
-    */
4520
+     * This is a helper function that is used to quickly created indexes when creating tables.
4521
+     */
4522 4522
     function create_index($query)
4523 4523
     {
4524 4524
         $GLOBALS['log']->info("create_index: $query");
@@ -4530,21 +4530,21 @@  discard block
 block discarded – undo
4530 4530
      * This function should be overridden in each module.  It marks an item as deleted.
4531 4531
      *
4532 4532
      * If it is not overridden, then marking this type of item is not allowed
4533
-	 */
4534
-	function mark_deleted($id)
4535
-	{
4536
-		global $current_user;
4537
-		$date_modified = $GLOBALS['timedate']->nowDb();
4533
+     */
4534
+    function mark_deleted($id)
4535
+    {
4536
+        global $current_user;
4537
+        $date_modified = $GLOBALS['timedate']->nowDb();
4538 4538
         $id = $this->db->quote($id);
4539
-		if(isset($_SESSION['show_deleted']))
4540
-		{
4541
-			$this->mark_undeleted($id);
4542
-		}
4543
-		else
4544
-		{
4545
-			// call the custom business logic
4546
-			$custom_logic_arguments['id'] = $id;
4547
-			$this->call_custom_logic("before_delete", $custom_logic_arguments);
4539
+        if(isset($_SESSION['show_deleted']))
4540
+        {
4541
+            $this->mark_undeleted($id);
4542
+        }
4543
+        else
4544
+        {
4545
+            // call the custom business logic
4546
+            $custom_logic_arguments['id'] = $id;
4547
+            $this->call_custom_logic("before_delete", $custom_logic_arguments);
4548 4548
             $this->deleted = 1;
4549 4549
             $this->mark_relationships_deleted($id);
4550 4550
             if ( isset($this->field_defs['modified_user_id']) ) {
@@ -4577,16 +4577,16 @@  discard block
 block discarded – undo
4577 4577
      * Restores data deleted by call to mark_deleted() function.
4578 4578
      *
4579 4579
      * Internal function, do not override.
4580
-    */
4580
+     */
4581 4581
     function mark_undeleted($id)
4582 4582
     {
4583 4583
         // call the custom business logic
4584 4584
         $custom_logic_arguments['id'] = $id;
4585 4585
         $this->call_custom_logic("before_restore", $custom_logic_arguments);
4586 4586
 
4587
-		$date_modified = $GLOBALS['timedate']->nowDb();
4588
-		$query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='" . $this->db->quote($id) ."'";
4589
-		$this->db->query($query, true,"Error marking record undeleted: ");
4587
+        $date_modified = $GLOBALS['timedate']->nowDb();
4588
+        $query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='" . $this->db->quote($id) ."'";
4589
+        $this->db->query($query, true,"Error marking record undeleted: ");
4590 4590
 
4591 4591
         $this->restoreFiles();
4592 4592
 
@@ -4594,17 +4594,17 @@  discard block
 block discarded – undo
4594 4594
         $this->call_custom_logic("after_restore", $custom_logic_arguments);
4595 4595
     }
4596 4596
 
4597
-   /**
4598
-    * This function deletes relationships to this object.  It should be overridden
4599
-    * to handle the relationships of the specific object.
4600
-    * This function is called when the item itself is being deleted.
4601
-    *
4602
-    * @param int $id id of the relationship to delete
4603
-    */
4604
-   function mark_relationships_deleted($id)
4605
-   {
4597
+    /**
4598
+     * This function deletes relationships to this object.  It should be overridden
4599
+     * to handle the relationships of the specific object.
4600
+     * This function is called when the item itself is being deleted.
4601
+     *
4602
+     * @param int $id id of the relationship to delete
4603
+     */
4604
+    function mark_relationships_deleted($id)
4605
+    {
4606 4606
     $this->delete_linked($id);
4607
-   }
4607
+    }
4608 4608
 
4609 4609
     /**
4610 4610
      * Returns path for files of bean or false on error
@@ -4784,16 +4784,16 @@  discard block
 block discarded – undo
4784 4784
     }
4785 4785
 
4786 4786
     /**
4787
-    * This function is used to execute the query and create an array template objects
4788
-    * from the resulting ids from the query.
4789
-    * It is currently used for building sub-panel arrays.
4790
-    *
4791
-    * @param string $query - the query that should be executed to build the list
4792
-    * @param object $template - The object that should be used to copy the records.
4793
-    * @param int $row_offset Optional, default 0
4794
-    * @param int $limit Optional, default -1
4795
-    * @return array
4796
-    */
4787
+     * This function is used to execute the query and create an array template objects
4788
+     * from the resulting ids from the query.
4789
+     * It is currently used for building sub-panel arrays.
4790
+     *
4791
+     * @param string $query - the query that should be executed to build the list
4792
+     * @param object $template - The object that should be used to copy the records.
4793
+     * @param int $row_offset Optional, default 0
4794
+     * @param int $limit Optional, default -1
4795
+     * @return array
4796
+     */
4797 4797
     function build_related_list($query, &$template, $row_offset = 0, $limit = -1)
4798 4798
     {
4799 4799
         $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
@@ -4829,17 +4829,17 @@  discard block
 block discarded – undo
4829 4829
         return $list;
4830 4830
     }
4831 4831
 
4832
-  /**
4833
-    * This function is used to execute the query and create an array template objects
4834
-    * from the resulting ids from the query.
4835
-    * It is currently used for building sub-panel arrays. It supports an additional
4836
-    * where clause that is executed as a filter on the results
4837
-    *
4838
-    * @param string $query - the query that should be executed to build the list
4839
-    * @param object $template - The object that should be used to copy the records.
4840
-    */
4841
-  function build_related_list_where($query, &$template, $where='', $in='', $order_by, $limit='', $row_offset = 0)
4842
-  {
4832
+    /**
4833
+     * This function is used to execute the query and create an array template objects
4834
+     * from the resulting ids from the query.
4835
+     * It is currently used for building sub-panel arrays. It supports an additional
4836
+     * where clause that is executed as a filter on the results
4837
+     *
4838
+     * @param string $query - the query that should be executed to build the list
4839
+     * @param object $template - The object that should be used to copy the records.
4840
+     */
4841
+    function build_related_list_where($query, &$template, $where='', $in='', $order_by, $limit='', $row_offset = 0)
4842
+    {
4843 4843
     $db = DBManagerFactory::getInstance('listviews');
4844 4844
     // No need to do an additional query
4845 4845
     $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
@@ -4900,7 +4900,7 @@  discard block
 block discarded – undo
4900 4900
     }
4901 4901
 
4902 4902
     return $list;
4903
-  }
4903
+    }
4904 4904
 
4905 4905
     /**
4906 4906
      * Constructs an comma separated list of ids from passed query results.
@@ -4936,15 +4936,15 @@  discard block
 block discarded – undo
4936 4936
     }
4937 4937
 
4938 4938
     /**
4939
-    * Optionally copies values from fetched row into the bean.
4940
-    *
4941
-    * Internal function, do not override.
4942
-    *
4943
-    * @param string $query - the query that should be executed to build the list
4944
-    * @param object $template - The object that should be used to copy the records
4945
-    * @param array $field_list List of  fields.
4946
-    * @return array
4947
-    */
4939
+     * Optionally copies values from fetched row into the bean.
4940
+     *
4941
+     * Internal function, do not override.
4942
+     *
4943
+     * @param string $query - the query that should be executed to build the list
4944
+     * @param object $template - The object that should be used to copy the records
4945
+     * @param array $field_list List of  fields.
4946
+     * @return array
4947
+     */
4948 4948
     function build_related_list2($query, &$template, &$field_list)
4949 4949
     {
4950 4950
         $GLOBALS['log']->debug("Finding linked values $this->object_name: ".$query);
@@ -5117,19 +5117,19 @@  discard block
 block discarded – undo
5117 5117
         $row = $this->convertRow($row);
5118 5118
         $this->fetched_row = $row;
5119 5119
         $this->fromArray($row);
5120
-		$this->is_updated_dependent_fields = false;
5120
+        $this->is_updated_dependent_fields = false;
5121 5121
         $this->fill_in_additional_detail_fields();
5122 5122
         return $this;
5123 5123
     }
5124 5124
 
5125 5125
     /**
5126
-    * This method is called during an import before inserting a bean
5127
-    * Define an associative array called $special_fields
5128
-    * the keys are user defined, and don't directly map to the bean's fields
5129
-    * the value is the method name within that bean that will do extra
5130
-    * processing for that field. example: 'full_name'=>'get_names_from_full_name'
5131
-    *
5132
-    */
5126
+     * This method is called during an import before inserting a bean
5127
+     * Define an associative array called $special_fields
5128
+     * the keys are user defined, and don't directly map to the bean's fields
5129
+     * the value is the method name within that bean that will do extra
5130
+     * processing for that field. example: 'full_name'=>'get_names_from_full_name'
5131
+     *
5132
+     */
5133 5133
     function process_special_fields()
5134 5134
     {
5135 5135
         foreach ($this->special_functions as $func_name)
@@ -5263,8 +5263,8 @@  discard block
 block discarded – undo
5263 5263
     {
5264 5264
         $where = '';
5265 5265
 
5266
-		// make sure there is a date modified
5267
-		$date_modified = $this->db->convert("'".$GLOBALS['timedate']->nowDb()."'", 'datetime');
5266
+        // make sure there is a date modified
5267
+        $date_modified = $this->db->convert("'".$GLOBALS['timedate']->nowDb()."'", 'datetime');
5268 5268
 
5269 5269
         $row=null;
5270 5270
         if($check_duplicates)
@@ -5341,30 +5341,30 @@  discard block
 block discarded – undo
5341 5341
     }
5342 5342
 
5343 5343
     /**
5344
-    * Trigger custom logic for this module that is defined for the provided hook
5345
-    * The custom logic file is located under custom/modules/[CURRENT_MODULE]/logic_hooks.php.
5346
-    * That file should define the $hook_version that should be used.
5347
-    * It should also define the $hook_array.  The $hook_array will be a two dimensional array
5348
-    * the first dimension is the name of the event, the second dimension is the information needed
5349
-    * to fire the hook.  Each entry in the top level array should be defined on a single line to make it
5350
-    * easier to automatically replace this file.  There should be no contents of this file that are not replacable.
5351
-    *
5352
-    * $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/Leads/test12.php', 'TestClass', 'lead_before_save_1');
5353
-    * This sample line creates a before_save hook.  The hooks are procesed in the order in which they
5354
-    * are added to the array.  The second dimension is an array of:
5355
-    *		processing index (for sorting before exporting the array)
5356
-    *		A logic type hook
5357
-    *		label/type
5358
-    *		php file to include
5359
-    *		php class the method is in
5360
-    *		php method to call
5361
-    *
5362
-    * The method signature for version 1 hooks is:
5363
-    * function NAME(&$bean, $event, $arguments)
5364
-    * 		$bean - $this bean passed in by reference.
5365
-    *		$event - The string for the current event (i.e. before_save)
5366
-    * 		$arguments - An array of arguments that are specific to the event.
5367
-    */
5344
+     * Trigger custom logic for this module that is defined for the provided hook
5345
+     * The custom logic file is located under custom/modules/[CURRENT_MODULE]/logic_hooks.php.
5346
+     * That file should define the $hook_version that should be used.
5347
+     * It should also define the $hook_array.  The $hook_array will be a two dimensional array
5348
+     * the first dimension is the name of the event, the second dimension is the information needed
5349
+     * to fire the hook.  Each entry in the top level array should be defined on a single line to make it
5350
+     * easier to automatically replace this file.  There should be no contents of this file that are not replacable.
5351
+     *
5352
+     * $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/Leads/test12.php', 'TestClass', 'lead_before_save_1');
5353
+     * This sample line creates a before_save hook.  The hooks are procesed in the order in which they
5354
+     * are added to the array.  The second dimension is an array of:
5355
+     *		processing index (for sorting before exporting the array)
5356
+     *		A logic type hook
5357
+     *		label/type
5358
+     *		php file to include
5359
+     *		php class the method is in
5360
+     *		php method to call
5361
+     *
5362
+     * The method signature for version 1 hooks is:
5363
+     * function NAME(&$bean, $event, $arguments)
5364
+     * 		$bean - $this bean passed in by reference.
5365
+     *		$event - The string for the current event (i.e. before_save)
5366
+     * 		$arguments - An array of arguments that are specific to the event.
5367
+     */
5368 5368
     function call_custom_logic($event, $arguments = null)
5369 5369
     {
5370 5370
         if(!isset($this->processed) || $this->processed == false){
@@ -5428,14 +5428,14 @@  discard block
 block discarded – undo
5428 5428
         return false;
5429 5429
     }
5430 5430
     /**
5431
-    * Check whether the user has access to a particular view for the current bean/module
5432
-    * @param $view string required, the view to determine access for i.e. DetailView, ListView...
5433
-    * @param $is_owner bool optional, this is part of the ACL check if the current user is an owner they will receive different access
5434
-    */
5435
-	/* BEGIN - SECURITY GROUPS - aclaccess */  
5436
-	/**
5431
+     * Check whether the user has access to a particular view for the current bean/module
5432
+     * @param $view string required, the view to determine access for i.e. DetailView, ListView...
5433
+     * @param $is_owner bool optional, this is part of the ACL check if the current user is an owner they will receive different access
5434
+     */
5435
+    /* BEGIN - SECURITY GROUPS - aclaccess */  
5436
+    /**
5437 5437
     function ACLAccess($view,$is_owner='not_set')
5438
-	*/
5438
+     */
5439 5439
     function ACLAccess($view,$is_owner='not_set',$in_group='not_set')
5440 5440
     {
5441 5441
         global $current_user;
@@ -5443,61 +5443,61 @@  discard block
 block discarded – undo
5443 5443
             return true;
5444 5444
         }
5445 5445
         $not_set = false;
5446
-		/**
5446
+        /**
5447 5447
         if($is_owner == 'not_set')
5448
-		*/
5449
-    	if($is_owner === 'not_set') //eggsurplus: should be ===
5448
+         */
5449
+        if($is_owner === 'not_set') //eggsurplus: should be ===
5450 5450
         {
5451 5451
             $not_set = true;
5452 5452
             $is_owner = $this->isOwner($current_user->id);
5453 5453
         }
5454
-		// DJM - OBS Customizations - May 2009
5455
-		// Moved this code to convert to lowercase from below.
5456
-		// Added new action variable.
5457
-		$view = strtolower($view);
5458
-		$action = '';
5459
-		// DJM - OBS Customizations - END CHANGE
5460
-    	if($in_group === 'not_set')
5461
-    	{
5462
-			require_once("modules/SecurityGroups/SecurityGroup.php");
5463
-			// DJM - OBS Customizations - May 2009
5464
-			// Added the following switch statement to convert the view
5465
-			// into an action value.  As per the switch below.
5466
-			// Added the action parameter to the groupHasAccess call.
5467
-    			switch ($view)
5468
-    			{
5469
-    				case 'list':
5470
-    				case 'index':
5471
-    				case 'listview':
5472
-    					$action = "list";
5473
-					break;
5474
-    				case 'edit':
5475
-    				case 'save':
5476
-		    		case 'popupeditview':
5477
- 		   		case 'editview':
5478
-  		  			$action = "edit";
5479
-					break;
5480
- 		   		case 'view':
5481
- 		   		case 'detail':
5482
- 		   		case 'detailview':
5483
- 		   			$action = "view";
5484
-					break;
5485
- 		   		case 'delete':
5486
- 		   			$action = "delete" ;
5487
-					break;
5488
- 		   		case 'export':
5489
- 		   			$action = "export";
5490
-					break;
5491
- 		   		case 'import':
5492
-  		  			$action = "import";
5493
-					break;
5494
-				default:
5495
-					$action = "";
5496
-					break;
5497
-    			}
5498
-			$in_group = SecurityGroup::groupHasAccess($this->module_dir,$this->id, $action); 
5499
-			// DJM - OBS Customizations - END CHANGE
5500
-    	}
5454
+        // DJM - OBS Customizations - May 2009
5455
+        // Moved this code to convert to lowercase from below.
5456
+        // Added new action variable.
5457
+        $view = strtolower($view);
5458
+        $action = '';
5459
+        // DJM - OBS Customizations - END CHANGE
5460
+        if($in_group === 'not_set')
5461
+        {
5462
+            require_once("modules/SecurityGroups/SecurityGroup.php");
5463
+            // DJM - OBS Customizations - May 2009
5464
+            // Added the following switch statement to convert the view
5465
+            // into an action value.  As per the switch below.
5466
+            // Added the action parameter to the groupHasAccess call.
5467
+                switch ($view)
5468
+                {
5469
+                    case 'list':
5470
+                    case 'index':
5471
+                    case 'listview':
5472
+                        $action = "list";
5473
+                    break;
5474
+                    case 'edit':
5475
+                    case 'save':
5476
+                    case 'popupeditview':
5477
+                    case 'editview':
5478
+                        $action = "edit";
5479
+                    break;
5480
+                    case 'view':
5481
+                    case 'detail':
5482
+                    case 'detailview':
5483
+                        $action = "view";
5484
+                    break;
5485
+                    case 'delete':
5486
+                        $action = "delete" ;
5487
+                    break;
5488
+                    case 'export':
5489
+                        $action = "export";
5490
+                    break;
5491
+                    case 'import':
5492
+                        $action = "import";
5493
+                    break;
5494
+                default:
5495
+                    $action = "";
5496
+                    break;
5497
+                }
5498
+            $in_group = SecurityGroup::groupHasAccess($this->module_dir,$this->id, $action); 
5499
+            // DJM - OBS Customizations - END CHANGE
5500
+        }
5501 5501
         //if we don't implent acls return true
5502 5502
         if(!$this->bean_implements('ACL'))
5503 5503
         return true;
@@ -5507,10 +5507,10 @@  discard block
 block discarded – undo
5507 5507
             case 'list':
5508 5508
             case 'index':
5509 5509
             case 'listview':
5510
-				/**
5510
+                /**
5511 5511
                 return ACLController::checkAccess($this->module_dir,'list', true);
5512
-				*/
5513
-    			return ACLController::checkAccess($this->module_dir,'list', true, $this->acltype, $in_group);
5512
+                 */
5513
+                return ACLController::checkAccess($this->module_dir,'list', true, $this->acltype, $in_group);
5514 5514
             case 'edit':
5515 5515
             case 'save':
5516 5516
                 if( !$is_owner && $not_set && !empty($this->id)){
@@ -5525,32 +5525,32 @@  discard block
 block discarded – undo
5525 5525
                 }
5526 5526
             case 'popupeditview':
5527 5527
             case 'editview':
5528
-				/**
5528
+                /**
5529 5529
                 return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype);
5530
-				*/
5531
-    			return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype, $in_group);
5530
+                 */
5531
+                return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype, $in_group);
5532 5532
             case 'view':
5533 5533
             case 'detail':
5534 5534
             case 'detailview':
5535
-				/**
5535
+                /**
5536 5536
                 return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype);
5537
-				*/
5538
-    			return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype, $in_group);
5537
+                 */
5538
+                return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype, $in_group);
5539 5539
             case 'delete':
5540
-				/**
5540
+                /**
5541 5541
                 return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype);
5542
-				*/
5543
-    			return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype, $in_group);
5542
+                 */
5543
+                return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype, $in_group);
5544 5544
             case 'export':
5545
-				/**
5545
+                /**
5546 5546
                 return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype);
5547
-				*/
5548
-    			return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype, $in_group);
5547
+                 */
5548
+                return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype, $in_group);
5549 5549
             case 'import':
5550
-				/**
5550
+                /**
5551 5551
                 return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype);
5552
-				*/
5553
-    			return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype, $in_group);
5552
+                 */
5553
+                return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype, $in_group);
5554 5554
         }
5555 5555
         //if it is not one of the above views then it should be implemented on the page level
5556 5556
         return true;
@@ -5558,10 +5558,10 @@  discard block
 block discarded – undo
5558 5558
     /* END - SECURITY GROUPS */
5559 5559
 
5560 5560
     /**
5561
-    * Get owner field
5562
-    *
5563
-    * @return STRING
5564
-    */
5561
+     * Get owner field
5562
+     *
5563
+     * @return STRING
5564
+     */
5565 5565
     function getOwnerField($returnFieldName = false)
5566 5566
     {
5567 5567
         if (isset($this->field_defs['assigned_user_id']))
@@ -5578,11 +5578,11 @@  discard block
 block discarded – undo
5578 5578
     }
5579 5579
 
5580 5580
     /**
5581
-    * Returns true of false if the user_id passed is the owner
5582
-    *
5583
-    * @param GUID $user_id
5584
-    * @return boolean
5585
-    */
5581
+     * Returns true of false if the user_id passed is the owner
5582
+     *
5583
+     * @param GUID $user_id
5584
+     * @return boolean
5585
+     */
5586 5586
     function isOwner($user_id)
5587 5587
     {
5588 5588
         //if we don't have an id we must be the owner as we are creating it
@@ -5611,11 +5611,11 @@  discard block
 block discarded – undo
5611 5611
         return false;
5612 5612
     }
5613 5613
     /**
5614
-    * Gets there where statement for checking if a user is an owner
5615
-    *
5616
-    * @param GUID $user_id
5617
-    * @return STRING
5618
-    */
5614
+     * Gets there where statement for checking if a user is an owner
5615
+     *
5616
+     * @param GUID $user_id
5617
+     * @return STRING
5618
+     */
5619 5619
     function getOwnerWhere($user_id)
5620 5620
     {
5621 5621
         if(isset($this->field_defs['assigned_user_id']))
@@ -5630,12 +5630,12 @@  discard block
 block discarded – undo
5630 5630
     }
5631 5631
 
5632 5632
     /**
5633
-    *
5634
-    * Used in order to manage ListView links and if they should
5635
-    * links or not based on the ACL permissions of the user
5636
-    *
5637
-    * @return ARRAY of STRINGS
5638
-    */
5633
+     *
5634
+     * Used in order to manage ListView links and if they should
5635
+     * links or not based on the ACL permissions of the user
5636
+     *
5637
+     * @return ARRAY of STRINGS
5638
+     */
5639 5639
     function listviewACLHelper()
5640 5640
     {
5641 5641
         $array_assign = array();
@@ -5651,10 +5651,10 @@  discard block
 block discarded – undo
5651 5651
     }
5652 5652
 
5653 5653
     /**
5654
-    * returns this bean as an array
5655
-    *
5656
-    * @return array of fields with id, name, access and category
5657
-    */
5654
+     * returns this bean as an array
5655
+     *
5656
+     * @return array of fields with id, name, access and category
5657
+     */
5658 5658
     function toArray($dbOnly = false, $stringOnly = false, $upperKeys=false)
5659 5659
     {
5660 5660
         static $cache = array();
@@ -5684,10 +5684,10 @@  discard block
 block discarded – undo
5684 5684
     }
5685 5685
 
5686 5686
     /**
5687
-    * Converts an array into an acl mapping name value pairs into files
5688
-    *
5689
-    * @param Array $arr
5690
-    */
5687
+     * Converts an array into an acl mapping name value pairs into files
5688
+     *
5689
+     * @param Array $arr
5690
+     */
5691 5691
     function fromArray($arr)
5692 5692
     {
5693 5693
         foreach($arr as $name=>$value)
@@ -5705,13 +5705,13 @@  discard block
 block discarded – undo
5705 5705
     public function convertRow($row)
5706 5706
     {
5707 5707
         foreach($this->field_defs as $name => $fieldDef)
5708
-		{
5709
-		    // skip empty fields and non-db fields
5708
+        {
5709
+            // skip empty fields and non-db fields
5710 5710
             if (isset($name) && !empty($row[$name])) {
5711 5711
                 $row[$name] = $this->convertField($row[$name], $fieldDef);
5712 5712
             }
5713 5713
         }
5714
-		return $row;
5714
+        return $row;
5715 5715
     }
5716 5716
 
5717 5717
     /**
@@ -5759,18 +5759,18 @@  discard block
 block discarded – undo
5759 5759
         return !empty($GLOBALS['dictionary'][$this->object_name]['custom_fields']);
5760 5760
     }
5761 5761
 
5762
-   /**
5763
-    * Ensure that fields within order by clauses are properly qualified with
5764
-    * their tablename.  This qualification is a requirement for sql server support.
5765
-    *
5766
-    * @param string $order_by original order by from the query
5767
-    * @param string $qualify prefix for columns in the order by list.
5768
-    * @return  prefixed
5769
-    *
5770
-    * Internal function do not override.
5771
-    */
5772
-   function create_qualified_order_by( $order_by, $qualify)
5773
-   {	// if the column is empty, but the sort order is defined, the value will throw an error, so do not proceed if no order by is given
5762
+    /**
5763
+     * Ensure that fields within order by clauses are properly qualified with
5764
+     * their tablename.  This qualification is a requirement for sql server support.
5765
+     *
5766
+     * @param string $order_by original order by from the query
5767
+     * @param string $qualify prefix for columns in the order by list.
5768
+     * @return  prefixed
5769
+     *
5770
+     * Internal function do not override.
5771
+     */
5772
+    function create_qualified_order_by( $order_by, $qualify)
5773
+    {	// if the column is empty, but the sort order is defined, the value will throw an error, so do not proceed if no order by is given
5774 5774
     if (empty($order_by))
5775 5775
     {
5776 5776
         return $order_by;
@@ -5785,17 +5785,17 @@  discard block
 block discarded – undo
5785 5785
         $comma = ", ";
5786 5786
     }
5787 5787
     return $order_by_clause;
5788
-   }
5788
+    }
5789 5789
 
5790
-   /**
5791
-    * Combined the contents of street field 2 thru 4 into the main field
5792
-    *
5793
-    * @param string $street_field
5794
-    */
5790
+    /**
5791
+     * Combined the contents of street field 2 thru 4 into the main field
5792
+     *
5793
+     * @param string $street_field
5794
+     */
5795 5795
 
5796
-   function add_address_streets(
5797
-       $street_field
5798
-       )
5796
+    function add_address_streets(
5797
+        $street_field
5798
+        )
5799 5799
     {
5800 5800
         if (isset($this->$street_field)) {
5801 5801
             $street_field_2 = $street_field.'_2';
@@ -5849,9 +5849,9 @@  discard block
 block discarded – undo
5849 5849
     }
5850 5850
 
5851 5851
     /**
5852
-    * Moved from save() method, functionality is the same, but this is intended to handle
5853
-    * Optimistic locking functionality.
5854
-    */
5852
+     * Moved from save() method, functionality is the same, but this is intended to handle
5853
+     * Optimistic locking functionality.
5854
+     */
5855 5855
     private function _checkOptimisticLocking($action, $isUpdate){
5856 5856
         if($this->optimistic_lock && !isset($_SESSION['o_lock_fs'])){
5857 5857
             if(isset($_SESSION['o_lock_id']) && $_SESSION['o_lock_id'] == $this->id && $_SESSION['o_lock_on'] == $this->object_name)
@@ -5890,8 +5890,8 @@  discard block
 block discarded – undo
5890 5890
     }
5891 5891
 
5892 5892
     /**
5893
-    * Send assignment notifications and invites for meetings and calls
5894
-    */
5893
+     * Send assignment notifications and invites for meetings and calls
5894
+     */
5895 5895
     private function _sendNotifications($check_notify){
5896 5896
         if($check_notify || (isset($this->notify_inworkflow) && $this->notify_inworkflow == true) // cn: bug 5795 - no invites sent to Contacts, and also bug 25995, in workflow, it will set the notify_on_save=true.
5897 5897
            && !$this->isOwner($this->created_by) )  // cn: bug 42727 no need to send email to owner (within workflow)
@@ -5979,11 +5979,11 @@  discard block
 block discarded – undo
5979 5979
         $result = sugar_cache_retrieve($cache_key);
5980 5980
         if(!empty($result))
5981 5981
         {
5982
-        	// Use SugarCache::EXTERNAL_CACHE_NULL_VALUE to store null values in the cache.
5983
-        	if($result == SugarCache::EXTERNAL_CACHE_NULL_VALUE)
5984
-        	{
5985
-        		return null;
5986
-        	}
5982
+            // Use SugarCache::EXTERNAL_CACHE_NULL_VALUE to store null values in the cache.
5983
+            if($result == SugarCache::EXTERNAL_CACHE_NULL_VALUE)
5984
+            {
5985
+                return null;
5986
+            }
5987 5987
 
5988 5988
             return $result;
5989 5989
         }
@@ -6000,7 +6000,7 @@  discard block
 block discarded – undo
6000 6000
             if(empty($moduleDefs[$module]) || empty($moduleDefs[$module][$module][$key]))
6001 6001
             {
6002 6002
                 // It was not loaded....  Fail.  Cache null to prevent future repeats of this calculation
6003
-				sugar_cache_put($cache_key, SugarCache::EXTERNAL_CACHE_NULL_VALUE);
6003
+                sugar_cache_put($cache_key, SugarCache::EXTERNAL_CACHE_NULL_VALUE);
6004 6004
                 return  null;
6005 6005
             }
6006 6006
 
@@ -6011,8 +6011,8 @@  discard block
 block discarded – undo
6011 6011
 
6012 6012
         // It was not loaded....  Fail.  Cache null to prevent future repeats of this calculation
6013 6013
         sugar_cache_put($cache_key, SugarCache::EXTERNAL_CACHE_NULL_VALUE);
6014
-		return null;
6015
-	}
6014
+        return null;
6015
+    }
6016 6016
 
6017 6017
     /**
6018 6018
      * Returns the ACL category for this module; defaults to the SugarBean::$acl_category if defined
@@ -6033,10 +6033,10 @@  discard block
 block discarded – undo
6033 6033
      * @param string $where
6034 6034
      * @return string SQL query
6035 6035
      */
6036
-	public function create_export_query($order_by, $where)
6037
-	{
6038
-		return $this->create_new_list_query($order_by, $where, array(), array(), 0, '', false, $this, true, true);
6039
-	}
6036
+    public function create_export_query($order_by, $where)
6037
+    {
6038
+        return $this->create_new_list_query($order_by, $where, array(), array(), 0, '', false, $this, true, true);
6039
+    }
6040 6040
 
6041 6041
     /**
6042 6042
      * Determine whether the given field is a relate field
Please login to merge, or discard this patch.
Spacing   +837 added lines, -837 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
2
+if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 3
 /*********************************************************************************
4 4
  * SugarCRM Community Edition is a customer relationship management program developed by
5 5
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @var BOOL
131 131
 	 */
132
-	var $process_save_dates =true;
132
+	var $process_save_dates = true;
133 133
 
134 134
     /**
135 135
      * This signals to the bean that it is being saved in a mass mode.
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     /** Set this to true if you query contains a sub-select and bean is converting both select statements
211 211
     * into count queries.
212 212
     */
213
-    var $ungreedy_count=false;
213
+    var $ungreedy_count = false;
214 214
 
215 215
     /**
216 216
     * The name of the module folder for this type of bean.
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
     var $additional_column_fields = array();
228 228
     var $relationship_fields = array();
229 229
     var $current_notify_user;
230
-    var $fetched_row=false;
230
+    var $fetched_row = false;
231 231
     var $fetched_rel_row = array();
232 232
     var $layout_def;
233 233
     var $force_load_details = false;
234 234
     var $optimistic_lock = false;
235 235
     var $disable_custom_fields = false;
236 236
     var $number_formatting_done = false;
237
-    var $process_field_encrypted=false;
237
+    var $process_field_encrypted = false;
238 238
     /*
239 239
     * The default ACL type
240 240
     */
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
         $this->db = DBManagerFactory::getInstance();
318 318
         if (empty($this->module_name))
319 319
             $this->module_name = $this->module_dir;
320
-        if((false == $this->disable_vardefs && empty($loaded_defs[$this->object_name])) || !empty($GLOBALS['reload_vardefs']))
320
+        if ((false == $this->disable_vardefs && empty($loaded_defs[$this->object_name])) || !empty($GLOBALS['reload_vardefs']))
321 321
         {
322 322
             VardefManager::loadVardef($this->module_dir, $this->object_name);
323 323
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
             if (!empty($dictionary[$this->object_name]['fields'])) {
326 326
                 foreach ($dictionary[$this->object_name]['fields'] as $key=>$value_array) {
327 327
                     $column_fields[] = $key;
328
-                    if(!empty($value_array['required']) && !empty($value_array['name'])) {
328
+                    if (!empty($value_array['required']) && !empty($value_array['name'])) {
329 329
                         $this->required_fields[$value_array['name']] = 1;
330 330
                     }
331 331
                 }
@@ -333,57 +333,57 @@  discard block
 block discarded – undo
333 333
             }
334 334
 
335 335
             //setup custom fields
336
-            if(!isset($this->custom_fields) &&
336
+            if (!isset($this->custom_fields) &&
337 337
                 empty($this->disable_custom_fields))
338 338
             {
339 339
                 $this->setupCustomFields($this->module_dir);
340 340
             }
341 341
             //load up field_arrays from CacheHandler;
342
-            if(empty($this->list_fields))
342
+            if (empty($this->list_fields))
343 343
                 $this->list_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'list_fields');
344
-            if(empty($this->column_fields))
344
+            if (empty($this->column_fields))
345 345
                 $this->column_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'column_fields');
346
-            if(empty($this->required_fields))
346
+            if (empty($this->required_fields))
347 347
                 $this->required_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'required_fields');
348 348
 
349
-            if(isset($GLOBALS['dictionary'][$this->object_name]) && !$this->disable_vardefs)
349
+            if (isset($GLOBALS['dictionary'][$this->object_name]) && !$this->disable_vardefs)
350 350
             {
351 351
                 $this->field_name_map = $dictionary[$this->object_name]['fields'];
352
-                $this->field_defs =	$dictionary[$this->object_name]['fields'];
352
+                $this->field_defs = $dictionary[$this->object_name]['fields'];
353 353
 
354
-                if(!empty($dictionary[$this->object_name]['optimistic_locking']))
354
+                if (!empty($dictionary[$this->object_name]['optimistic_locking']))
355 355
                 {
356
-                    $this->optimistic_lock=true;
356
+                    $this->optimistic_lock = true;
357 357
                 }
358 358
             }
359
-            $loaded_defs[$this->object_name]['column_fields'] =& $this->column_fields;
360
-            $loaded_defs[$this->object_name]['list_fields'] =& $this->list_fields;
361
-            $loaded_defs[$this->object_name]['required_fields'] =& $this->required_fields;
362
-            $loaded_defs[$this->object_name]['field_name_map'] =& $this->field_name_map;
363
-            $loaded_defs[$this->object_name]['field_defs'] =& $this->field_defs;
359
+            $loaded_defs[$this->object_name]['column_fields'] = & $this->column_fields;
360
+            $loaded_defs[$this->object_name]['list_fields'] = & $this->list_fields;
361
+            $loaded_defs[$this->object_name]['required_fields'] = & $this->required_fields;
362
+            $loaded_defs[$this->object_name]['field_name_map'] = & $this->field_name_map;
363
+            $loaded_defs[$this->object_name]['field_defs'] = & $this->field_defs;
364 364
         }
365 365
         else
366 366
         {
367
-            $this->column_fields =& $loaded_defs[$this->object_name]['column_fields'] ;
368
-            $this->list_fields =& $loaded_defs[$this->object_name]['list_fields'];
369
-            $this->required_fields =& $loaded_defs[$this->object_name]['required_fields'];
370
-            $this->field_name_map =& $loaded_defs[$this->object_name]['field_name_map'];
371
-            $this->field_defs =& $loaded_defs[$this->object_name]['field_defs'];
367
+            $this->column_fields = & $loaded_defs[$this->object_name]['column_fields'];
368
+            $this->list_fields = & $loaded_defs[$this->object_name]['list_fields'];
369
+            $this->required_fields = & $loaded_defs[$this->object_name]['required_fields'];
370
+            $this->field_name_map = & $loaded_defs[$this->object_name]['field_name_map'];
371
+            $this->field_defs = & $loaded_defs[$this->object_name]['field_defs'];
372 372
             $this->added_custom_field_defs = true;
373 373
 
374
-            if(!isset($this->custom_fields) &&
374
+            if (!isset($this->custom_fields) &&
375 375
                 empty($this->disable_custom_fields))
376 376
             {
377 377
                 $this->setupCustomFields($this->module_dir, false);
378 378
             }
379
-            if(!empty($dictionary[$this->object_name]['optimistic_locking']))
379
+            if (!empty($dictionary[$this->object_name]['optimistic_locking']))
380 380
             {
381
-                $this->optimistic_lock=true;
381
+                $this->optimistic_lock = true;
382 382
             }
383 383
         }
384 384
 
385
-        if($this->bean_implements('ACL') && !empty($GLOBALS['current_user'])){
386
-            $this->acl_fields = (isset($dictionary[$this->object_name]['acl_fields']) && $dictionary[$this->object_name]['acl_fields'] === false)?false:true;
385
+        if ($this->bean_implements('ACL') && !empty($GLOBALS['current_user'])) {
386
+            $this->acl_fields = (isset($dictionary[$this->object_name]['acl_fields']) && $dictionary[$this->object_name]['acl_fields'] === false) ? false : true;
387 387
         }
388 388
         $this->populateDefaultValues();
389 389
     }
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
         if (!isset($this->audit_enabled_fields))
428 428
         {
429 429
 
430
-            $this->audit_enabled_fields=array();
430
+            $this->audit_enabled_fields = array();
431 431
             foreach ($this->field_defs as $field => $properties)
432 432
             {
433 433
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
                 )
438 438
                 {
439 439
 
440
-                    $this->audit_enabled_fields[$field]=$properties;
440
+                    $this->audit_enabled_fields[$field] = $properties;
441 441
                 }
442 442
             }
443 443
 
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
     function create_audit_table()
505 505
     {
506 506
         global $dictionary;
507
-        $table_name=$this->get_audit_table_name();
507
+        $table_name = $this->get_audit_table_name();
508 508
 
509 509
         require('metadata/audit_templateMetaData.php');
510 510
 
511 511
         // Bug: 52583 Need ability to customize template for audit tables
512
-        $custom = 'custom/metadata/audit_templateMetaData_' . $this->getTableName() . '.php';
512
+        $custom = 'custom/metadata/audit_templateMetaData_'.$this->getTableName().'.php';
513 513
         if (file_exists($custom))
514 514
         {
515 515
             require($custom);
@@ -519,14 +519,14 @@  discard block
 block discarded – undo
519 519
         $indices = $dictionary['audit']['indices'];
520 520
 
521 521
         // Renaming template indexes to fit the particular audit table (removed the brittle hard coding)
522
-        foreach($indices as $nr => $properties){
523
-            $indices[$nr]['name'] = 'idx_' . strtolower($this->getTableName()) . '_' . $properties['name'];
522
+        foreach ($indices as $nr => $properties) {
523
+            $indices[$nr]['name'] = 'idx_'.strtolower($this->getTableName()).'_'.$properties['name'];
524 524
         }
525 525
 
526 526
         $engine = null;
527
-        if(isset($dictionary['audit']['engine'])) {
527
+        if (isset($dictionary['audit']['engine'])) {
528 528
             $engine = $dictionary['audit']['engine'];
529
-        } else if(isset($dictionary[$this->getObjectName()]['engine'])) {
529
+        } else if (isset($dictionary[$this->getObjectName()]['engine'])) {
530 530
             $engine = $dictionary[$this->getObjectName()]['engine'];
531 531
         }
532 532
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
      */
546 546
     public function getTableName()
547 547
     {
548
-        if(isset($this->table_name))
548
+        if (isset($this->table_name))
549 549
         {
550 550
             return $this->table_name;
551 551
         }
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
     function getIndices()
580 580
     {
581 581
         global $dictionary;
582
-        if(isset($dictionary[$this->getObjectName()]['indices']))
582
+        if (isset($dictionary[$this->getObjectName()]['indices']))
583 583
         {
584 584
             return $dictionary[$this->getObjectName()]['indices'];
585 585
         }
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
      */
599 599
     function getFieldDefinition($name)
600 600
     {
601
-        if ( !isset($this->field_defs[$name]) )
601
+        if (!isset($this->field_defs[$name]))
602 602
             return false;
603 603
 
604 604
         return $this->field_defs[$name];
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
     function getPrimaryFieldDefinition()
617 617
     {
618 618
         $def = $this->getFieldDefinition("id");
619
-        if(empty($def)) {
619
+        if (empty($def)) {
620 620
             $def = $this->getFieldDefinition(0);
621 621
         }
622 622
         if (empty($def)) {
@@ -639,13 +639,13 @@  discard block
 block discarded – undo
639 639
      */
640 640
     function getFieldValue($name)
641 641
     {
642
-        if (!isset($this->$name)){
642
+        if (!isset($this->$name)) {
643 643
             return FALSE;
644 644
         }
645
-        if($this->$name === TRUE){
645
+        if ($this->$name === TRUE) {
646 646
             return 1;
647 647
         }
648
-        if($this->$name === FALSE){
648
+        if ($this->$name === FALSE) {
649 649
             return 0;
650 650
         }
651 651
         return $this->$name;
@@ -657,17 +657,17 @@  discard block
 block discarded – undo
657 657
      */
658 658
     public function unPopulateDefaultValues()
659 659
     {
660
-        if ( !is_array($this->field_defs) )
660
+        if (!is_array($this->field_defs))
661 661
             return;
662 662
 
663 663
         foreach ($this->field_defs as $field => $value) {
664
-		    if( !empty($this->$field)
664
+		    if (!empty($this->$field)
665 665
                   && ((isset($value['default']) && $this->$field == $value['default']) || (!empty($value['display_default']) && $this->$field == $value['display_default']))
666 666
                     ) {
667 667
                 $this->$field = null;
668 668
                 continue;
669 669
             }
670
-            if(!empty($this->$field) && !empty($value['display_default']) && in_array($value['type'], array('date', 'datetime', 'datetimecombo')) &&
670
+            if (!empty($this->$field) && !empty($value['display_default']) && in_array($value['type'], array('date', 'datetime', 'datetimecombo')) &&
671 671
             $this->$field == $this->parseDateDefault($value['display_default'], ($value['type'] != 'date'))) {
672 672
                 $this->$field = null;
673 673
             }
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
     protected function parseDateDefault($value, $time = false)
685 685
     {
686 686
         global $timedate;
687
-        if($time) {
687
+        if ($time) {
688 688
             $dtAry = explode('&', $value, 2);
689 689
             $dateValue = $timedate->getNow(true)->modify($dtAry[0]);
690
-            if(!empty($dtAry[1])) {
690
+            if (!empty($dtAry[1])) {
691 691
                 $timeValue = $timedate->fromString($dtAry[1]);
692 692
                 $dateValue->setTime($timeValue->hour, $timeValue->min, $timeValue->sec);
693 693
             }
@@ -697,37 +697,37 @@  discard block
 block discarded – undo
697 697
         }
698 698
     }
699 699
 
700
-    function populateDefaultValues($force=false){
701
-        if ( !is_array($this->field_defs) )
700
+    function populateDefaultValues($force = false) {
701
+        if (!is_array($this->field_defs))
702 702
             return;
703
-        foreach($this->field_defs as $field=>$value){
704
-            if((isset($value['default']) || !empty($value['display_default'])) && ($force || empty($this->$field))){
703
+        foreach ($this->field_defs as $field=>$value) {
704
+            if ((isset($value['default']) || !empty($value['display_default'])) && ($force || empty($this->$field))) {
705 705
                 $type = $value['type'];
706 706
 
707
-                switch($type){
707
+                switch ($type) {
708 708
                     case 'date':
709
-                        if(!empty($value['display_default'])){
709
+                        if (!empty($value['display_default'])) {
710 710
                             $this->$field = $this->parseDateDefault($value['display_default']);
711 711
                         }
712 712
                         break;
713 713
                    case 'datetime':
714 714
                    case 'datetimecombo':
715
-                        if(!empty($value['display_default'])){
715
+                        if (!empty($value['display_default'])) {
716 716
                             $this->$field = $this->parseDateDefault($value['display_default'], true);
717 717
                         }
718 718
                         break;
719 719
                     case 'multienum':
720
-                        if(empty($value['default']) && !empty($value['display_default']))
720
+                        if (empty($value['default']) && !empty($value['display_default']))
721 721
                             $this->$field = $value['display_default'];
722 722
                         else
723 723
                             $this->$field = $value['default'];
724 724
                         break;
725 725
                     case 'bool':
726
-                    	if(isset($this->$field)){
726
+                    	if (isset($this->$field)) {
727 727
                     		break;
728 728
                     	}
729 729
                     default:
730
-                        if ( isset($value['default']) && $value['default'] !== '' ) {
730
+                        if (isset($value['default']) && $value['default'] !== '') {
731 731
                             $this->$field = htmlentities($value['default'], ENT_QUOTES, 'UTF-8');
732 732
                         } else {
733 733
                             $this->$field = '';
@@ -755,20 +755,20 @@  discard block
 block discarded – undo
755 755
      *
756 756
      * Internal function, do not override.
757 757
      */
758
-    static function removeRelationshipMeta($key,$db,$tablename,$dictionary,$module_dir)
758
+    static function removeRelationshipMeta($key, $db, $tablename, $dictionary, $module_dir)
759 759
     {
760 760
         //load the module dictionary if not supplied.
761 761
         if ((!isset($dictionary) or empty($dictionary)) && !empty($module_dir))
762 762
         {
763
-            $filename='modules/'. $module_dir . '/vardefs.php';
764
-            if(file_exists($filename))
763
+            $filename = 'modules/'.$module_dir.'/vardefs.php';
764
+            if (file_exists($filename))
765 765
             {
766 766
                 include($filename);
767 767
             }
768 768
         }
769 769
         if (!is_array($dictionary) or !array_key_exists($key, $dictionary))
770 770
         {
771
-            $GLOBALS['log']->fatal("removeRelationshipMeta: Metadata for table ".$tablename. " does not exist");
771
+            $GLOBALS['log']->fatal("removeRelationshipMeta: Metadata for table ".$tablename." does not exist");
772 772
             display_notice("meta data absent for table ".$tablename." keyed to $key ");
773 773
         }
774 774
         else
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
                 $RelationshipDefs = $dictionary[$key]['relationships'];
779 779
                 foreach ($RelationshipDefs as $rel_name)
780 780
                 {
781
-                    Relationship::delete($rel_name,$db);
781
+                    Relationship::delete($rel_name, $db);
782 782
                 }
783 783
             }
784 784
         }
@@ -792,9 +792,9 @@  discard block
 block discarded – undo
792 792
      * @deprecated 4.5.1 - Nov 14, 2006
793 793
      * @static
794 794
     */
795
-    static function remove_relationship_meta($key,$db,$log,$tablename,$dictionary,$module_dir)
795
+    static function remove_relationship_meta($key, $db, $log, $tablename, $dictionary, $module_dir)
796 796
     {
797
-        SugarBean::removeRelationshipMeta($key,$db,$tablename,$dictionary,$module_dir);
797
+        SugarBean::removeRelationshipMeta($key, $db, $tablename, $dictionary, $module_dir);
798 798
     }
799 799
 
800 800
 
@@ -813,14 +813,14 @@  discard block
 block discarded – undo
813 813
      *
814 814
      *  Internal function, do not override.
815 815
      */
816
-    static function createRelationshipMeta($key,$db,$tablename,$dictionary,$module_dir,$iscustom=false)
816
+    static function createRelationshipMeta($key, $db, $tablename, $dictionary, $module_dir, $iscustom = false)
817 817
     {
818 818
         //load the module dictionary if not supplied.
819 819
         if (empty($dictionary) && !empty($module_dir))
820 820
         {
821
-            if($iscustom)
821
+            if ($iscustom)
822 822
             {
823
-                $filename='custom/modules/' . $module_dir . '/Ext/Vardefs/vardefs.ext.php';
823
+                $filename = 'custom/modules/'.$module_dir.'/Ext/Vardefs/vardefs.ext.php';
824 824
             }
825 825
             else
826 826
             {
@@ -829,33 +829,33 @@  discard block
 block discarded – undo
829 829
                     // a very special case for the Employees module
830 830
                     // this must be done because the Employees/vardefs.php does an include_once on
831 831
                     // Users/vardefs.php
832
-                    $filename='modules/Users/vardefs.php';
832
+                    $filename = 'modules/Users/vardefs.php';
833 833
                 }
834 834
                 else
835 835
                 {
836
-                    $filename='modules/'. $module_dir . '/vardefs.php';
836
+                    $filename = 'modules/'.$module_dir.'/vardefs.php';
837 837
                 }
838 838
             }
839 839
 
840
-            if(file_exists($filename))
840
+            if (file_exists($filename))
841 841
             {
842 842
                 include($filename);
843 843
                 // cn: bug 7679 - dictionary entries defined as $GLOBALS['name'] not found
844
-                if(empty($dictionary) || !empty($GLOBALS['dictionary'][$key]))
844
+                if (empty($dictionary) || !empty($GLOBALS['dictionary'][$key]))
845 845
                 {
846 846
                     $dictionary = $GLOBALS['dictionary'];
847 847
                 }
848 848
             }
849 849
             else
850 850
             {
851
-                $GLOBALS['log']->debug("createRelationshipMeta: no metadata file found" . $filename);
851
+                $GLOBALS['log']->debug("createRelationshipMeta: no metadata file found".$filename);
852 852
                 return;
853 853
             }
854 854
         }
855 855
 
856 856
         if (!is_array($dictionary) or !array_key_exists($key, $dictionary))
857 857
         {
858
-            $GLOBALS['log']->fatal("createRelationshipMeta: Metadata for table ".$tablename. " does not exist");
858
+            $GLOBALS['log']->fatal("createRelationshipMeta: Metadata for table ".$tablename." does not exist");
859 859
             display_notice("meta data absent for table ".$tablename." keyed to $key ");
860 860
         }
861 861
         else
@@ -865,23 +865,23 @@  discard block
 block discarded – undo
865 865
 
866 866
                 $RelationshipDefs = $dictionary[$key]['relationships'];
867 867
 
868
-                $delimiter=',';
868
+                $delimiter = ',';
869 869
                 global $beanList;
870
-                $beanList_ucase=array_change_key_case  ( $beanList ,CASE_UPPER);
870
+                $beanList_ucase = array_change_key_case($beanList, CASE_UPPER);
871 871
                 foreach ($RelationshipDefs as $rel_name=>$rel_def)
872 872
                 {
873 873
                     if (isset($rel_def['lhs_module']) and !isset($beanList_ucase[strtoupper($rel_def['lhs_module'])])) {
874
-                        $GLOBALS['log']->debug('skipping orphaned relationship record ' . $rel_name . ' lhs module is missing ' . $rel_def['lhs_module']);
874
+                        $GLOBALS['log']->debug('skipping orphaned relationship record '.$rel_name.' lhs module is missing '.$rel_def['lhs_module']);
875 875
                         continue;
876 876
                     }
877 877
                     if (isset($rel_def['rhs_module']) and !isset($beanList_ucase[strtoupper($rel_def['rhs_module'])])) {
878
-                        $GLOBALS['log']->debug('skipping orphaned relationship record ' . $rel_name . ' rhs module is missing ' . $rel_def['rhs_module']);
878
+                        $GLOBALS['log']->debug('skipping orphaned relationship record '.$rel_name.' rhs module is missing '.$rel_def['rhs_module']);
879 879
                         continue;
880 880
                     }
881 881
 
882 882
 
883 883
                     //check whether relationship exists or not first.
884
-                    if (Relationship::exists($rel_name,$db))
884
+                    if (Relationship::exists($rel_name, $db))
885 885
                     {
886 886
                         $GLOBALS['log']->debug('Skipping, reltionship already exists '.$rel_name);
887 887
                     }
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
                         $seed = BeanFactory::getBean("Relationships");
891 891
                         $keys = array_keys($seed->field_defs);
892 892
                         $toInsert = array();
893
-                        foreach($keys as $key)
893
+                        foreach ($keys as $key)
894 894
                         {
895 895
                             if ($key == "id")
896 896
                             {
@@ -909,10 +909,10 @@  discard block
 block discarded – undo
909 909
 
910 910
 
911 911
                         $column_list = implode(",", array_keys($toInsert));
912
-                        $value_list = "'" . implode("','", array_values($toInsert)) . "'";
912
+                        $value_list = "'".implode("','", array_values($toInsert))."'";
913 913
 
914 914
                         //create the record. todo add error check.
915
-                        $insert_string = "INSERT into relationships (" .$column_list. ") values (".$value_list.")";
915
+                        $insert_string = "INSERT into relationships (".$column_list.") values (".$value_list.")";
916 916
                         $db->query($insert_string, true);
917 917
                     }
918 918
                 }
@@ -931,9 +931,9 @@  discard block
 block discarded – undo
931 931
      * @deprecated 4.5.1 - Nov 14, 2006
932 932
      * @static
933 933
     */
934
-    static function create_relationship_meta($key,&$db,&$log,$tablename,$dictionary,$module_dir)
934
+    static function create_relationship_meta($key, &$db, &$log, $tablename, $dictionary, $module_dir)
935 935
     {
936
-        SugarBean::createRelationshipMeta($key,$db,$tablename,$dictionary,$module_dir);
936
+        SugarBean::createRelationshipMeta($key, $db, $tablename, $dictionary, $module_dir);
937 937
     }
938 938
 
939 939
 
@@ -946,8 +946,8 @@  discard block
 block discarded – undo
946 946
      */
947 947
     public function __clone()
948 948
     {
949
-        if(!empty($this->loaded_relationships)) {
950
-            foreach($this->loaded_relationships as $rel) {
949
+        if (!empty($this->loaded_relationships)) {
950
+            foreach ($this->loaded_relationships as $rel) {
951 951
                 unset($this->$rel);
952 952
             }
953 953
         }
@@ -1021,8 +1021,8 @@  discard block
 block discarded – undo
1021 1021
     function load_relationships()
1022 1022
     {
1023 1023
         $GLOBALS['log']->debug("SugarBean.load_relationships, Loading all relationships of type link.");
1024
-        $linked_fields=$this->get_linked_fields();
1025
-        foreach($linked_fields as $name=>$properties)
1024
+        $linked_fields = $this->get_linked_fields();
1025
+        foreach ($linked_fields as $name=>$properties)
1026 1026
         {
1027 1027
             $this->load_relationship($name);
1028 1028
         }
@@ -1045,13 +1045,13 @@  discard block
 block discarded – undo
1045 1045
      *
1046 1046
      * Internal function, do not override.
1047 1047
      */
1048
-    function get_linked_beans($field_name,$bean_name = '', $order_by = '', $begin_index = 0, $end_index = -1, $deleted=0, $optional_where="")
1048
+    function get_linked_beans($field_name, $bean_name = '', $order_by = '', $begin_index = 0, $end_index = -1, $deleted = 0, $optional_where = "")
1049 1049
     {
1050 1050
         //if bean_name is Case then use aCase
1051
-        if($bean_name=="Case")
1051
+        if ($bean_name == "Case")
1052 1052
             $bean_name = "aCase";
1053 1053
 
1054
-        if($this->load_relationship($field_name)) {
1054
+        if ($this->load_relationship($field_name)) {
1055 1055
             if ($this->$field_name instanceof Link) {
1056 1056
                 // some classes are still based on Link, e.g. TeamSetLink
1057 1057
                 return array_values($this->$field_name->getBeans(new $bean_name(), $order_by, $begin_index, $end_index, $deleted, $optional_where));
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
     function get_linked_fields()
1083 1083
     {
1084 1084
 
1085
-        $linked_fields=array();
1085
+        $linked_fields = array();
1086 1086
 
1087 1087
  //   	require_once('data/Link.php');
1088 1088
 
@@ -1093,9 +1093,9 @@  discard block
 block discarded – undo
1093 1093
         {
1094 1094
             foreach ($fieldDefs as $name=>$properties)
1095 1095
             {
1096
-                if (array_search('link',$properties) === 'type')
1096
+                if (array_search('link', $properties) === 'type')
1097 1097
                 {
1098
-                    $linked_fields[$name]=$properties;
1098
+                    $linked_fields[$name] = $properties;
1099 1099
                 }
1100 1100
             }
1101 1101
         }
@@ -1115,38 +1115,38 @@  discard block
 block discarded – undo
1115 1115
     {
1116 1116
         $importableFields = array();
1117 1117
 
1118
-        $fieldDefs= $this->getFieldDefinitions();
1118
+        $fieldDefs = $this->getFieldDefinitions();
1119 1119
 
1120 1120
         if (!empty($fieldDefs)) {
1121 1121
             foreach ($fieldDefs as $key=>$value_array) {
1122
-                if ( (isset($value_array['importable'])
1122
+                if ((isset($value_array['importable'])
1123 1123
                         && (is_string($value_array['importable']) && $value_array['importable'] == 'false'
1124 1124
                             || is_bool($value_array['importable']) && $value_array['importable'] == false))
1125 1125
                     || (isset($value_array['type']) && $value_array['type'] == 'link')
1126 1126
                     || (isset($value_array['auto_increment'])
1127
-                        && ($value_array['type'] == true || $value_array['type'] == 'true')) ) {
1127
+                        && ($value_array['type'] == true || $value_array['type'] == 'true'))) {
1128 1128
                     // only allow import if we force it
1129 1129
                     if (isset($value_array['importable'])
1130 1130
                         && (is_string($value_array['importable']) && $value_array['importable'] == 'true'
1131 1131
                            || is_bool($value_array['importable']) && $value_array['importable'] == true)) {
1132
-                        $importableFields[$key]=$value_array;
1132
+                        $importableFields[$key] = $value_array;
1133 1133
                     }
1134 1134
                 }
1135 1135
                 else {
1136 1136
 
1137 1137
                     //Expose the cooresponding id field of a relate field if it is only defined as a link so that users can relate records by id during import
1138
-                    if( isset($value_array['type']) && ($value_array['type'] == 'relate') && isset($value_array['id_name']) )
1138
+                    if (isset($value_array['type']) && ($value_array['type'] == 'relate') && isset($value_array['id_name']))
1139 1139
                     {
1140 1140
                         $idField = $value_array['id_name'];
1141
-                        if( isset($fieldDefs[$idField]) && isset($fieldDefs[$idField]['type'] ) && $fieldDefs[$idField]['type'] == 'link' )
1141
+                        if (isset($fieldDefs[$idField]) && isset($fieldDefs[$idField]['type']) && $fieldDefs[$idField]['type'] == 'link')
1142 1142
                         {
1143 1143
                             $tmpFieldDefs = $fieldDefs[$idField];
1144
-                            $tmpFieldDefs['vname'] = translate($value_array['vname'], $this->module_dir) . " " . $GLOBALS['app_strings']['LBL_ID'];
1145
-                            $importableFields[$idField]=$tmpFieldDefs;
1144
+                            $tmpFieldDefs['vname'] = translate($value_array['vname'], $this->module_dir)." ".$GLOBALS['app_strings']['LBL_ID'];
1145
+                            $importableFields[$idField] = $tmpFieldDefs;
1146 1146
                         }
1147 1147
                     }
1148 1148
 
1149
-                    $importableFields[$key]=$value_array;
1149
+                    $importableFields[$key] = $value_array;
1150 1150
                 }
1151 1151
             }
1152 1152
         }
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
     function get_related_fields()
1165 1165
     {
1166 1166
 
1167
-        $related_fields=array();
1167
+        $related_fields = array();
1168 1168
 
1169 1169
 //    	require_once('data/Link.php');
1170 1170
 
@@ -1175,9 +1175,9 @@  discard block
 block discarded – undo
1175 1175
         {
1176 1176
             foreach ($fieldDefs as $name=>$properties)
1177 1177
             {
1178
-                if (array_search('relate',$properties) === 'type')
1178
+                if (array_search('relate', $properties) === 'type')
1179 1179
                 {
1180
-                    $related_fields[$name]=$properties;
1180
+                    $related_fields[$name] = $properties;
1181 1181
                 }
1182 1182
             }
1183 1183
         }
@@ -1195,8 +1195,8 @@  discard block
 block discarded – undo
1195 1195
         $importable_fields = $this->get_importable_fields();
1196 1196
         $required_fields   = array();
1197 1197
 
1198
-        foreach ( $importable_fields as $name => $properties ) {
1199
-            if ( isset($properties['importable']) && is_string($properties['importable']) && $properties['importable'] == 'required' ) {
1198
+        foreach ($importable_fields as $name => $properties) {
1199
+            if (isset($properties['importable']) && is_string($properties['importable']) && $properties['importable'] == 'required') {
1200 1200
                 $required_fields[$name] = $properties;
1201 1201
             }
1202 1202
         }
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
      */
1212 1212
     function delete_linked($id)
1213 1213
     {
1214
-        $linked_fields=$this->get_linked_fields();
1214
+        $linked_fields = $this->get_linked_fields();
1215 1215
         foreach ($linked_fields as $name => $value)
1216 1216
         {
1217 1217
             if ($this->load_relationship($name))
@@ -1237,18 +1237,18 @@  discard block
 block discarded – undo
1237 1237
         $key = $this->getObjectName();
1238 1238
         if (!array_key_exists($key, $dictionary))
1239 1239
         {
1240
-            $GLOBALS['log']->fatal("create_tables: Metadata for table ".$this->table_name. " does not exist");
1240
+            $GLOBALS['log']->fatal("create_tables: Metadata for table ".$this->table_name." does not exist");
1241 1241
             display_notice("meta data absent for table ".$this->table_name." keyed to $key ");
1242 1242
         }
1243 1243
         else
1244 1244
         {
1245
-            if(!$this->db->tableExists($this->table_name))
1245
+            if (!$this->db->tableExists($this->table_name))
1246 1246
             {
1247 1247
                 $this->db->createTable($this);
1248
-                    if($this->bean_implements('ACL')){
1249
-                        if(!empty($this->acltype)){
1248
+                    if ($this->bean_implements('ACL')) {
1249
+                        if (!empty($this->acltype)) {
1250 1250
                             ACLAction::addActions($this->getACLCategory(), $this->acltype);
1251
-                        }else{
1251
+                        } else {
1252 1252
                             ACLAction::addActions($this->getACLCategory());
1253 1253
                         }
1254 1254
                     }
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
             {
1258 1258
                 echo "Table already exists : $this->table_name<br>";
1259 1259
             }
1260
-            if($this->is_AuditEnabled()){
1260
+            if ($this->is_AuditEnabled()) {
1261 1261
                     if (!$this->db->tableExists($this->get_audit_table_name())) {
1262 1262
                         $this->create_audit_table();
1263 1263
                     }
@@ -1278,16 +1278,16 @@  discard block
 block discarded – undo
1278 1278
         $key = $this->getObjectName();
1279 1279
         if (!array_key_exists($key, $dictionary))
1280 1280
         {
1281
-            $GLOBALS['log']->fatal("drop_tables: Metadata for table ".$this->table_name. " does not exist");
1281
+            $GLOBALS['log']->fatal("drop_tables: Metadata for table ".$this->table_name." does not exist");
1282 1282
             echo "meta data absent for table ".$this->table_name."<br>\n";
1283 1283
         } else {
1284
-            if(empty($this->table_name))return;
1284
+            if (empty($this->table_name))return;
1285 1285
             if ($this->db->tableExists($this->table_name))
1286 1286
 
1287 1287
                 $this->db->dropTable($this);
1288
-            if ($this->db->tableExists($this->table_name. '_cstm'))
1288
+            if ($this->db->tableExists($this->table_name.'_cstm'))
1289 1289
             {
1290
-                $this->db->dropTableName($this->table_name. '_cstm');
1290
+                $this->db->dropTableName($this->table_name.'_cstm');
1291 1291
                 DynamicField::deleteCache();
1292 1292
             }
1293 1293
             if ($this->db->tableExists($this->get_audit_table_name())) {
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
      * @param string $module_name setting up custom fields for this module.
1307 1307
      * @param boolean $clean_load Optional, default true, rebuilds the cache if set to true.
1308 1308
      */
1309
-    function setupCustomFields($module_name, $clean_load=true)
1309
+    function setupCustomFields($module_name, $clean_load = true)
1310 1310
     {
1311 1311
         $this->custom_fields = new DynamicField($module_name);
1312 1312
         $this->custom_fields->setup($this);
@@ -1317,17 +1317,17 @@  discard block
 block discarded – undo
1317 1317
     * Cleans char, varchar, text, etc. fields of XSS type materials
1318 1318
     */
1319 1319
     function cleanBean() {
1320
-        foreach($this->field_defs as $key => $def) {
1320
+        foreach ($this->field_defs as $key => $def) {
1321 1321
 
1322 1322
             if (isset($def['type'])) {
1323
-                $type=$def['type'];
1323
+                $type = $def['type'];
1324 1324
             }
1325
-            if(isset($def['dbType']))
1325
+            if (isset($def['dbType']))
1326 1326
                 $type .= $def['dbType'];
1327 1327
 
1328
-            if($def['type'] == 'html' || $def['type'] == 'longhtml') {
1328
+            if ($def['type'] == 'html' || $def['type'] == 'longhtml') {
1329 1329
                 $this->$key = SugarCleaner::cleanHtml($this->$key, true);
1330
-            } elseif((strpos($type, 'char') !== false ||
1330
+            } elseif ((strpos($type, 'char') !== false ||
1331 1331
                 strpos($type, 'text') !== false ||
1332 1332
                 $type == 'enum') &&
1333 1333
                 !empty($this->$key)
@@ -1357,24 +1357,24 @@  discard block
 block discarded – undo
1357 1357
         global $current_user, $action;
1358 1358
 
1359 1359
         $isUpdate = true;
1360
-        if(empty($this->id))
1360
+        if (empty($this->id))
1361 1361
         {
1362 1362
             $isUpdate = false;
1363 1363
         }
1364 1364
 
1365
-		if ( $this->new_with_id == true )
1365
+		if ($this->new_with_id == true)
1366 1366
 		{
1367 1367
 			$isUpdate = false;
1368 1368
 		}
1369
-		if(empty($this->date_modified) || $this->update_date_modified)
1369
+		if (empty($this->date_modified) || $this->update_date_modified)
1370 1370
 		{
1371 1371
 			$this->date_modified = $GLOBALS['timedate']->nowDb();
1372 1372
 		}
1373 1373
 
1374 1374
         $this->_checkOptimisticLocking($action, $isUpdate);
1375 1375
 
1376
-        if(!empty($this->modified_by_name)) $this->old_modified_by_name = $this->modified_by_name;
1377
-        if($this->update_modified_by)
1376
+        if (!empty($this->modified_by_name)) $this->old_modified_by_name = $this->modified_by_name;
1377
+        if ($this->update_modified_by)
1378 1378
         {
1379 1379
             $this->modified_user_id = 1;
1380 1380
 
@@ -1386,18 +1386,18 @@  discard block
 block discarded – undo
1386 1386
         }
1387 1387
         if ($this->deleted != 1)
1388 1388
             $this->deleted = 0;
1389
-        if(!$isUpdate)
1389
+        if (!$isUpdate)
1390 1390
         {
1391 1391
             if (empty($this->date_entered))
1392 1392
             {
1393 1393
                 $this->date_entered = $this->date_modified;
1394 1394
             }
1395
-            if($this->set_created_by == true)
1395
+            if ($this->set_created_by == true)
1396 1396
             {
1397 1397
                 // created by should always be this user
1398 1398
                 $this->created_by = (isset($current_user)) ? $current_user->id : "";
1399 1399
             }
1400
-            if( $this->new_with_id == false)
1400
+            if ($this->new_with_id == false)
1401 1401
             {
1402 1402
                 $this->id = create_guid();
1403 1403
             }
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
             $this->save_relationship_changes($isUpdate);
1416 1416
             $GLOBALS['saving_relationships'] = false;
1417 1417
         }
1418
-        if($isUpdate && !$this->update_date_entered)
1418
+        if ($isUpdate && !$this->update_date_entered)
1419 1419
         {
1420 1420
             unset($this->date_entered);
1421 1421
         }
@@ -1437,7 +1437,7 @@  discard block
 block discarded – undo
1437 1437
             $this->emailAddress->save($this->id, $this->module_dir);
1438 1438
         }
1439 1439
 
1440
-        if(isset($this->custom_fields))
1440
+        if (isset($this->custom_fields))
1441 1441
         {
1442 1442
             $this->custom_fields->bean = $this;
1443 1443
             $this->custom_fields->save($isUpdate);
@@ -1447,12 +1447,12 @@  discard block
 block discarded – undo
1447 1447
         $this->preprocess_fields_on_save();
1448 1448
 
1449 1449
         //construct the SQL to create the audit record if auditing is enabled.
1450
-        $auditDataChanges=array();
1450
+        $auditDataChanges = array();
1451 1451
         if ($this->is_AuditEnabled()) {
1452 1452
             if ($isUpdate && !isset($this->fetched_row)) {
1453 1453
                 $GLOBALS['log']->debug('Auditing: Retrieve was not called, audit record will not be created.');
1454 1454
             } else {
1455
-                $auditDataChanges=$this->db->getAuditDataChanges($this);
1455
+                $auditDataChanges = $this->db->getAuditDataChanges($this);
1456 1456
             }
1457 1457
         }
1458 1458
 
@@ -1468,12 +1468,12 @@  discard block
 block discarded – undo
1468 1468
         {
1469 1469
             foreach ($auditDataChanges as $change)
1470 1470
             {
1471
-                $this->db->save_audit_records($this,$change);
1471
+                $this->db->save_audit_records($this, $change);
1472 1472
             }
1473 1473
         }
1474 1474
 
1475 1475
 
1476
-        if (empty($GLOBALS['resavingRelatedBeans'])){
1476
+        if (empty($GLOBALS['resavingRelatedBeans'])) {
1477 1477
             SugarRelationship::resaveRelatedBeans();
1478 1478
         }
1479 1479
 
@@ -1485,10 +1485,10 @@  discard block
 block discarded – undo
1485 1485
 
1486 1486
 		/* BEGIN - SECURITY GROUPS - inheritance */ 
1487 1487
 		require_once('modules/SecurityGroups/SecurityGroup.php');
1488
-		SecurityGroup::inherit($this,$isUpdate);
1488
+		SecurityGroup::inherit($this, $isUpdate);
1489 1489
 		/* END - SECURITY GROUPS */ 
1490 1490
         //If we aren't in setup mode and we have a current user and module, then we track
1491
-        if(isset($GLOBALS['current_user']) && isset($this->module_dir))
1491
+        if (isset($GLOBALS['current_user']) && isset($this->module_dir))
1492 1492
         {
1493 1493
             $this->track_view($current_user->id, $this->module_dir, 'save');
1494 1494
         }
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
             	AND (modified_user_id != '$modified_user_id' OR date_modified > $date)";
1519 1519
             $result = $this->db->query($query);
1520 1520
 
1521
-            if($this->db->fetchByAssoc($result))
1521
+            if ($this->db->fetchByAssoc($result))
1522 1522
             {
1523 1523
                 return true;
1524 1524
             }
@@ -1554,11 +1554,11 @@  discard block
 block discarded – undo
1554 1554
     {
1555 1555
         global $current_user;
1556 1556
 
1557
-        if(($this->object_name == 'Meeting' || $this->object_name == 'Call') || $notify_user->receive_notifications)
1557
+        if (($this->object_name == 'Meeting' || $this->object_name == 'Call') || $notify_user->receive_notifications)
1558 1558
         {
1559 1559
             $sendToEmail = $notify_user->emailAddress->getPrimaryAddress($notify_user);
1560 1560
             $sendEmail = TRUE;
1561
-            if(empty($sendToEmail)) {
1561
+            if (empty($sendToEmail)) {
1562 1562
                 $GLOBALS['log']->warn("Notifications: no e-mail address set for user {$notify_user->user_name}, cancelling send");
1563 1563
                 $sendEmail = FALSE;
1564 1564
             }
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
             $notify_mail = $this->create_notification_email($notify_user);
1567 1567
             $notify_mail->setMailerForSystem();
1568 1568
 
1569
-            if(empty($admin->settings['notify_send_from_assigning_user'])) {
1569
+            if (empty($admin->settings['notify_send_from_assigning_user'])) {
1570 1570
                 $notify_mail->From = $admin->settings['notify_fromaddress'];
1571 1571
                 $notify_mail->FromName = (empty($admin->settings['notify_fromname'])) ? "" : $admin->settings['notify_fromname'];
1572 1572
             } else {
@@ -1583,31 +1583,31 @@  discard block
 block discarded – undo
1583 1583
            $oe = new OutboundEmail();
1584 1584
             $oe = $oe->getUserMailerSettings($current_user);
1585 1585
             //only send if smtp server is defined
1586
-            if($sendEmail){
1586
+            if ($sendEmail) {
1587 1587
                 $smtpVerified = false;
1588 1588
 
1589 1589
                 //first check the user settings
1590
-                if(!empty($oe->mail_smtpserver)){
1590
+                if (!empty($oe->mail_smtpserver)) {
1591 1591
                     $smtpVerified = true;
1592 1592
                 }
1593 1593
 
1594 1594
                 //if still not verified, check against the system settings
1595
-                if (!$smtpVerified){
1595
+                if (!$smtpVerified) {
1596 1596
                     $oe = $oe->getSystemMailerSettings();
1597
-                    if(!empty($oe->mail_smtpserver)){
1597
+                    if (!empty($oe->mail_smtpserver)) {
1598 1598
                         $smtpVerified = true;
1599 1599
                     }
1600 1600
                 }
1601 1601
                 //if smtp was not verified against user or system, then do not send out email
1602
-                if (!$smtpVerified){
1602
+                if (!$smtpVerified) {
1603 1603
                     $GLOBALS['log']->fatal("Notifications: error sending e-mail, smtp server was not found ");
1604 1604
                     //break out
1605 1605
                     return;
1606 1606
                 }
1607 1607
 
1608
-                if(!$notify_mail->Send()) {
1608
+                if (!$notify_mail->Send()) {
1609 1609
                     $GLOBALS['log']->fatal("Notifications: error sending e-mail (method: {$notify_mail->Mailer}), (error: {$notify_mail->ErrorInfo})");
1610
-                }else{
1610
+                } else {
1611 1611
                     $GLOBALS['log']->info("Notifications: e-mail successfully sent");
1612 1612
                 }
1613 1613
             }
@@ -1636,15 +1636,15 @@  discard block
 block discarded – undo
1636 1636
         $GLOBALS['log']->debug("Notifications: user has e-mail defined");
1637 1637
 
1638 1638
         $notify_mail = new SugarPHPMailer();
1639
-        $notify_mail->AddAddress($notify_address,$locale->translateCharsetMIME(trim($notify_name), 'UTF-8', $OBCharset));
1639
+        $notify_mail->AddAddress($notify_address, $locale->translateCharsetMIME(trim($notify_name), 'UTF-8', $OBCharset));
1640 1640
 
1641
-        if(empty($_SESSION['authenticated_user_language'])) {
1641
+        if (empty($_SESSION['authenticated_user_language'])) {
1642 1642
             $current_language = $sugar_config['default_language'];
1643 1643
         } else {
1644 1644
             $current_language = $_SESSION['authenticated_user_language'];
1645 1645
         }
1646 1646
         $xtpl = new XTemplate(get_notify_template_file($current_language));
1647
-        if($this->module_dir == "Cases") {
1647
+        if ($this->module_dir == "Cases") {
1648 1648
             $template_name = "Case"; //we should use Case, you can refer to the en_us.notify_template.html.
1649 1649
         }
1650 1650
         else {
@@ -1653,23 +1653,23 @@  discard block
 block discarded – undo
1653 1653
 
1654 1654
         $this->current_notify_user = $notify_user;
1655 1655
 
1656
-        if(in_array('set_notification_body', get_class_methods($this))) {
1656
+        if (in_array('set_notification_body', get_class_methods($this))) {
1657 1657
             $xtpl = $this->set_notification_body($xtpl, $this);
1658 1658
         } else {
1659 1659
             $xtpl->assign("OBJECT", translate('LBL_MODULE_NAME'));
1660 1660
             $template_name = "Default";
1661 1661
         }
1662
-        if(!empty($_SESSION["special_notification"]) && $_SESSION["special_notification"]) {
1662
+        if (!empty($_SESSION["special_notification"]) && $_SESSION["special_notification"]) {
1663 1663
             $template_name = $beanList[$this->module_dir].'Special';
1664 1664
         }
1665
-        if($this->special_notification) {
1665
+        if ($this->special_notification) {
1666 1666
             $template_name = $beanList[$this->module_dir].'Special';
1667 1667
         }
1668 1668
         $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
1669 1669
         $xtpl->assign("ASSIGNER", $current_user->name);
1670 1670
         $port = '';
1671 1671
 
1672
-        if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
1672
+        if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
1673 1673
             $port = $_SERVER['SERVER_PORT'];
1674 1674
         }
1675 1675
 
@@ -1679,27 +1679,27 @@  discard block
 block discarded – undo
1679 1679
 
1680 1680
         $httpHost = $_SERVER['HTTP_HOST'];
1681 1681
 
1682
-        if($colon = strpos($httpHost, ':')) {
1683
-            $httpHost    = substr($httpHost, 0, $colon);
1682
+        if ($colon = strpos($httpHost, ':')) {
1683
+            $httpHost = substr($httpHost, 0, $colon);
1684 1684
         }
1685 1685
 
1686 1686
         $parsedSiteUrl = parse_url($sugar_config['site_url']);
1687 1687
         $host = $parsedSiteUrl['host'];
1688
-        if(!isset($parsedSiteUrl['port'])) {
1688
+        if (!isset($parsedSiteUrl['port'])) {
1689 1689
             $parsedSiteUrl['port'] = 80;
1690 1690
         }
1691 1691
 
1692 1692
         $port		= ($parsedSiteUrl['port'] != 80) ? ":".$parsedSiteUrl['port'] : '';
1693 1693
         $path		= !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : "";
1694
-        $cleanUrl	= "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
1694
+        $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
1695 1695
 
1696 1696
         $xtpl->assign("URL", $cleanUrl."/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
1697 1697
         $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
1698 1698
         $xtpl->parse($template_name);
1699
-        $xtpl->parse($template_name . "_Subject");
1699
+        $xtpl->parse($template_name."_Subject");
1700 1700
 
1701 1701
         $notify_mail->Body = from_html(trim($xtpl->text($template_name)));
1702
-        $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
1702
+        $notify_mail->Subject = from_html($xtpl->text($template_name."_Subject"));
1703 1703
 
1704 1704
         // cn: bug 8568 encode notify email in User's outbound email encoding
1705 1705
         $notify_mail->prepForOutbound();
@@ -1762,7 +1762,7 @@  discard block
 block discarded – undo
1762 1762
             // $rel_id and $rel_link are not emty - request is from subpanel
1763 1763
             // $rel_link contains relationship name - checked by call load_relationship
1764 1764
             $isRelationshipLoaded = $this->load_relationship($rel_link);
1765
-            if ($isRelationshipLoaded && !empty($this->$rel_link) && $this->$rel_link->getRelationshipObject() && $this->$rel_link->getRelationshipObject()->getLHSModule() == $this->$rel_link->getRelationshipObject()->getRHSModule() )
1765
+            if ($isRelationshipLoaded && !empty($this->$rel_link) && $this->$rel_link->getRelationshipObject() && $this->$rel_link->getRelationshipObject()->getLHSModule() == $this->$rel_link->getRelationshipObject()->getRHSModule())
1766 1766
             {
1767 1767
                 $new_rel_link = $this->$rel_link->getRelationshipObject()->getLHSLink();
1768 1768
             }
@@ -1802,14 +1802,14 @@  discard block
 block discarded – undo
1802 1802
 
1803 1803
                 if (in_array($id, $exclude)) continue;
1804 1804
 
1805
-                if(!empty($this->$id))
1805
+                if (!empty($this->$id))
1806 1806
                 {
1807 1807
                     // Bug #44930 We do not need to update main related field if it is changed from sub-panel.
1808 1808
                     if ($rel_name == $new_rel_link && $this->$id != $new_rel_id)
1809 1809
                     {
1810 1810
                         $new_rel_id = '';
1811 1811
                     }
1812
-                    $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - adding a relationship record: '.$rel_name . ' = ' . $this->$id);
1812
+                    $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - adding a relationship record: '.$rel_name.' = '.$this->$id);
1813 1813
                     //already related the new relationship id so let's set it to false so we don't add it again using the _REQUEST['relate_i'] mechanism in a later block
1814 1814
                     $this->load_relationship($rel_name);
1815 1815
                     $rel_add = $this->$rel_name->add($this->$id);
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
                 } else {
1821 1821
                     //if before value is not empty then attempt to delete relationship
1822 1822
                     if (!empty($this->rel_fields_before_value[$id])) {
1823
-                        $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - attempting to remove the relationship record, using relationship attribute' . $rel_name);
1823
+                        $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - attempting to remove the relationship record, using relationship attribute'.$rel_name);
1824 1824
                         $this->load_relationship($rel_name);
1825 1825
                         $this->$rel_name->delete($this->id, $this->rel_fields_before_value[$id]);
1826 1826
                     }
@@ -1863,30 +1863,30 @@  discard block
 block discarded – undo
1863 1863
 
1864 1864
                         if (!empty($this->rel_fields_before_value[$idName]) && empty($this->$idName)) {
1865 1865
                             //if before value is not empty then attempt to delete relationship
1866
-                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to remove the relationship record: {$def [ 'link' ]} = {$this->rel_fields_before_value[$def [ 'id_name' ]]}");
1866
+                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to remove the relationship record: {$def ['link']} = {$this->rel_fields_before_value[$def ['id_name']]}");
1867 1867
                             $success = $this->$def ['link']->delete($this->id, $this->rel_fields_before_value[$def ['id_name']]);
1868 1868
                             // just need to make sure it's true and not an array as it's possible to return an array
1869
-                            if($success == true) {
1869
+                            if ($success == true) {
1870 1870
                                 $modified_relationships['remove']['success'][] = $def['link'];
1871 1871
                             } else {
1872 1872
                                 $modified_relationships['remove']['failure'][] = $def['link'];
1873 1873
                             }
1874
-                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to remove the relationship record returned " . var_export($success, true));
1874
+                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to remove the relationship record returned ".var_export($success, true));
1875 1875
                         }
1876 1876
 
1877 1877
                         if (!empty($this->$idName) && is_string($this->$idName)) {
1878
-                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to add a relationship record - {$def [ 'link' ]} = {$this->$def [ 'id_name' ]}");
1878
+                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to add a relationship record - {$def ['link']} = {$this->$def ['id_name']}");
1879 1879
 
1880 1880
                             $success = $this->$linkField->add($this->$idName);
1881 1881
 
1882 1882
                             // just need to make sure it's true and not an array as it's possible to return an array
1883
-                            if($success == true) {
1883
+                            if ($success == true) {
1884 1884
                                 $modified_relationships['add']['success'][] = $linkField;
1885 1885
                             } else {
1886 1886
                                 $modified_relationships['add']['failure'][] = $linkField;
1887 1887
                             }
1888 1888
 
1889
-                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - add a relationship record returned " . var_export($success, true));
1889
+                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - add a relationship record returned ".var_export($success, true));
1890 1890
                         }
1891 1891
                     } else {
1892 1892
                         $GLOBALS['log']->fatal("Failed to load relationship {$linkField} while saving {$this->module_dir}");
@@ -2040,48 +2040,48 @@  discard block
 block discarded – undo
2040 2040
 		global $disable_date_format;
2041 2041
 		global $timedate;
2042 2042
 		if (empty($timedate))
2043
-			$timedate=TimeDate::getInstance();
2043
+			$timedate = TimeDate::getInstance();
2044 2044
 
2045
-		if(empty($this->field_defs))
2045
+		if (empty($this->field_defs))
2046 2046
 		{
2047 2047
 			return;
2048 2048
 		}
2049
-		foreach($this->field_defs as $fieldDef)
2049
+		foreach ($this->field_defs as $fieldDef)
2050 2050
 		{
2051 2051
 			$field = $fieldDef['name'];
2052
-			if(!isset($this->processed_dates_times[$field]))
2052
+			if (!isset($this->processed_dates_times[$field]))
2053 2053
 			{
2054 2054
 				$this->processed_dates_times[$field] = '1';
2055
-				if(empty($this->$field)) continue;
2056
-				if($field == 'date_modified' || $field == 'date_entered')
2055
+				if (empty($this->$field)) continue;
2056
+				if ($field == 'date_modified' || $field == 'date_entered')
2057 2057
 				{
2058 2058
 					$this->$field = $this->db->fromConvert($this->$field, 'datetime');
2059
-					if(empty($disable_date_format)) {
2059
+					if (empty($disable_date_format)) {
2060 2060
 						$this->$field = $timedate->to_display_date_time($this->$field);
2061 2061
 					}
2062 2062
 				}
2063
-				elseif(isset($this->field_name_map[$field]['type']))
2063
+				elseif (isset($this->field_name_map[$field]['type']))
2064 2064
 				{
2065 2065
 					$type = $this->field_name_map[$field]['type'];
2066 2066
 
2067
-					if($type == 'relate'  && isset($this->field_name_map[$field]['custom_module']))
2067
+					if ($type == 'relate' && isset($this->field_name_map[$field]['custom_module']))
2068 2068
 					{
2069 2069
 						$type = $this->field_name_map[$field]['type'];
2070 2070
 					}
2071 2071
 
2072
-					if($type == 'date')
2072
+					if ($type == 'date')
2073 2073
 					{
2074
-						if($this->$field == '0000-00-00')
2074
+						if ($this->$field == '0000-00-00')
2075 2075
 						{
2076 2076
 							$this->$field = '';
2077
-						} elseif(!empty($this->field_name_map[$field]['rel_field']))
2077
+						} elseif (!empty($this->field_name_map[$field]['rel_field']))
2078 2078
 						{
2079 2079
 							$rel_field = $this->field_name_map[$field]['rel_field'];
2080 2080
 
2081
-							if(!empty($this->$rel_field))
2081
+							if (!empty($this->$rel_field))
2082 2082
 							{
2083
-								if(empty($disable_date_format)) {
2084
-									$mergetime = $timedate->merge_date_time($this->$field,$this->$rel_field);
2083
+								if (empty($disable_date_format)) {
2084
+									$mergetime = $timedate->merge_date_time($this->$field, $this->$rel_field);
2085 2085
 									$this->$field = $timedate->to_display_date($mergetime);
2086 2086
 									$this->$rel_field = $timedate->to_display_time($mergetime);
2087 2087
 								}
@@ -2089,36 +2089,36 @@  discard block
 block discarded – undo
2089 2089
 						}
2090 2090
 						else
2091 2091
 						{
2092
-							if(empty($disable_date_format)) {
2092
+							if (empty($disable_date_format)) {
2093 2093
 								$this->$field = $timedate->to_display_date($this->$field, false);
2094 2094
 							}
2095 2095
 						}
2096
-					} elseif($type == 'datetime' || $type == 'datetimecombo')
2096
+					} elseif ($type == 'datetime' || $type == 'datetimecombo')
2097 2097
 					{
2098
-						if($this->$field == '0000-00-00 00:00:00')
2098
+						if ($this->$field == '0000-00-00 00:00:00')
2099 2099
 						{
2100 2100
 							$this->$field = '';
2101 2101
 						}
2102 2102
 						else
2103 2103
 						{
2104
-							if(empty($disable_date_format)) {
2104
+							if (empty($disable_date_format)) {
2105 2105
 								$this->$field = $timedate->to_display_date_time($this->$field, true, true);
2106 2106
 							}
2107 2107
 						}
2108
-					} elseif($type == 'time')
2108
+					} elseif ($type == 'time')
2109 2109
 					{
2110
-						if($this->$field == '00:00:00')
2110
+						if ($this->$field == '00:00:00')
2111 2111
 						{
2112 2112
 							$this->$field = '';
2113 2113
 						} else
2114 2114
 						{
2115 2115
 							//$this->$field = from_db_convert($this->$field, 'time');
2116
-							if(empty($this->field_name_map[$field]['rel_field']) && empty($disable_date_format))
2116
+							if (empty($this->field_name_map[$field]['rel_field']) && empty($disable_date_format))
2117 2117
 							{
2118
-								$this->$field = $timedate->to_display_time($this->$field,true, false);
2118
+								$this->$field = $timedate->to_display_time($this->$field, true, false);
2119 2119
 							}
2120 2120
 						}
2121
-					} elseif($type == 'encrypt' && empty($disable_date_format)){
2121
+					} elseif ($type == 'encrypt' && empty($disable_date_format)) {
2122 2122
 						$this->$field = $this->decrypt_after_retrieve($this->$field);
2123 2123
 					}
2124 2124
 				}
@@ -2172,52 +2172,52 @@  discard block
 block discarded – undo
2172 2172
         static $boolean_false_values = array('off', 'false', '0', 'no');
2173 2173
 
2174 2174
 
2175
-        foreach($this->field_defs as $field=>$def)
2175
+        foreach ($this->field_defs as $field=>$def)
2176 2176
             {
2177
-            if ( !isset($this->$field) ) {
2177
+            if (!isset($this->$field)) {
2178 2178
                 continue;
2179 2179
                 }
2180
-            if ( (isset($def['source'])&&$def['source']=='non-db') || $field == 'deleted' ) {
2180
+            if ((isset($def['source']) && $def['source'] == 'non-db') || $field == 'deleted') {
2181 2181
                 continue;
2182 2182
             }
2183
-            if ( isset($this->fetched_row[$field]) && $this->$field == $this->fetched_row[$field] ) {
2183
+            if (isset($this->fetched_row[$field]) && $this->$field == $this->fetched_row[$field]) {
2184 2184
                 // Don't hand out warnings because the field was untouched between retrieval and saving, most database drivers hand pretty much everything back as strings.
2185 2185
                 continue;
2186 2186
             }
2187 2187
             $reformatted = false;
2188
-            switch($def['type']) {
2188
+            switch ($def['type']) {
2189 2189
                 case 'datetime':
2190 2190
                 case 'datetimecombo':
2191
-                    if(empty($this->$field)) break;
2191
+                    if (empty($this->$field)) break;
2192 2192
                     if ($this->$field == 'NULL') {
2193 2193
                     	$this->$field = '';
2194 2194
                     	break;
2195 2195
                     }
2196
-                    if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/',$this->$field) ) {
2196
+                    if (!preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $this->$field)) {
2197 2197
                         // This appears to be formatted in user date/time
2198 2198
                         $this->$field = $timedate->to_db($this->$field);
2199 2199
                         $reformatted = true;
2200 2200
                     }
2201 2201
                     break;
2202 2202
                 case 'date':
2203
-                    if(empty($this->$field)) break;
2203
+                    if (empty($this->$field)) break;
2204 2204
                     if ($this->$field == 'NULL') {
2205 2205
                     	$this->$field = '';
2206 2206
                     	break;
2207 2207
                     }
2208
-                    if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',$this->$field) ) {
2208
+                    if (!preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $this->$field)) {
2209 2209
                         // This date appears to be formatted in the user's format
2210 2210
                         $this->$field = $timedate->to_db_date($this->$field, false);
2211 2211
                         $reformatted = true;
2212 2212
                     }
2213 2213
                     break;
2214 2214
                 case 'time':
2215
-                    if(empty($this->$field)) break;
2215
+                    if (empty($this->$field)) break;
2216 2216
                     if ($this->$field == 'NULL') {
2217 2217
                     	$this->$field = '';
2218 2218
                     	break;
2219 2219
                     }
2220
-                    if ( preg_match('/(am|pm)/i',$this->$field) ) {
2220
+                    if (preg_match('/(am|pm)/i', $this->$field)) {
2221 2221
                         // This time appears to be formatted in the user's format
2222 2222
                         $this->$field = $timedate->fromUserTime($this->$field)->format(TimeDate::DB_TIME_FORMAT);
2223 2223
                         $reformatted = true;
@@ -2227,10 +2227,10 @@  discard block
 block discarded – undo
2227 2227
                 case 'decimal':
2228 2228
                 case 'currency':
2229 2229
                 case 'float':
2230
-                    if ( $this->$field === '' || $this->$field == NULL || $this->$field == 'NULL') {
2230
+                    if ($this->$field === '' || $this->$field == NULL || $this->$field == 'NULL') {
2231 2231
                         continue;
2232 2232
                     }
2233
-                    if ( is_string($this->$field) ) {
2233
+                    if (is_string($this->$field)) {
2234 2234
                         $this->$field = (float)unformat_number($this->$field);
2235 2235
                         $reformatted = true;
2236 2236
                     }
@@ -2241,10 +2241,10 @@  discard block
 block discarded – undo
2241 2241
                case 'short':
2242 2242
                case 'tinyint':
2243 2243
                case 'int':
2244
-                    if ( $this->$field === '' || $this->$field == NULL || $this->$field == 'NULL') {
2244
+                    if ($this->$field === '' || $this->$field == NULL || $this->$field == 'NULL') {
2245 2245
                         continue;
2246 2246
                     }
2247
-                    if ( is_string($this->$field) ) {
2247
+                    if (is_string($this->$field)) {
2248 2248
                         $this->$field = (int)unformat_number($this->$field);
2249 2249
                         $reformatted = true;
2250 2250
                     }
@@ -2252,9 +2252,9 @@  discard block
 block discarded – undo
2252 2252
                case 'bool':
2253 2253
                    if (empty($this->$field)) {
2254 2254
                        $this->$field = false;
2255
-                   } else if(true === $this->$field || 1 == $this->$field) {
2255
+                   } else if (true === $this->$field || 1 == $this->$field) {
2256 2256
                        $this->$field = true;
2257
-                   } else if(in_array(strval($this->$field), $boolean_false_values)) {
2257
+                   } else if (in_array(strval($this->$field), $boolean_false_values)) {
2258 2258
                        $this->$field = false;
2259 2259
                        $reformatted = true;
2260 2260
                    } else {
@@ -2266,7 +2266,7 @@  discard block
 block discarded – undo
2266 2266
                     $this->$field = $this->encrpyt_before_save($this->$field);
2267 2267
                     break;
2268 2268
             }
2269
-            if ( $reformatted ) {
2269
+            if ($reformatted) {
2270 2270
                 $GLOBALS['log']->deprecated('Formatting correction: '.$this->module_dir.'->'.$field.' had formatting automatically corrected. This will be removed in the future, please upgrade your external code');
2271 2271
             }
2272 2272
         }
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
      *
2286 2286
      * Internal function, do not override.
2287 2287
     */
2288
-    function retrieve($id = -1, $encode=true,$deleted=true)
2288
+    function retrieve($id = -1, $encode = true, $deleted = true)
2289 2289
     {
2290 2290
 
2291 2291
         $custom_logic_arguments['id'] = $id;
@@ -2297,27 +2297,27 @@  discard block
 block discarded – undo
2297 2297
         }
2298 2298
         $custom_join = $this->getCustomJoin();
2299 2299
 
2300
-        $query = "SELECT $this->table_name.*". $custom_join['select']. " FROM $this->table_name ";
2300
+        $query = "SELECT $this->table_name.*".$custom_join['select']." FROM $this->table_name ";
2301 2301
 
2302 2302
         $query .= $custom_join['join'];
2303 2303
         $query .= " WHERE $this->table_name.id = ".$this->db->quoted($id);
2304 2304
         if ($deleted) $query .= " AND $this->table_name.deleted=0";
2305 2305
         $GLOBALS['log']->debug("Retrieve $this->object_name : ".$query);
2306
-        $result = $this->db->limitQuery($query,0,1,true, "Retrieving record by id $this->table_name:$id found ");
2307
-        if(empty($result))
2306
+        $result = $this->db->limitQuery($query, 0, 1, true, "Retrieving record by id $this->table_name:$id found ");
2307
+        if (empty($result))
2308 2308
         {
2309 2309
             return null;
2310 2310
         }
2311 2311
 
2312 2312
         $row = $this->db->fetchByAssoc($result, $encode);
2313
-        if(empty($row))
2313
+        if (empty($row))
2314 2314
         {
2315 2315
             return null;
2316 2316
         }
2317 2317
 
2318 2318
         //make copy of the fetched row for construction of audit record and for business logic/workflow
2319 2319
         $row = $this->convertRow($row);
2320
-        $this->fetched_row=$row;
2320
+        $this->fetched_row = $row;
2321 2321
         $this->populateFromRow($row);
2322 2322
 
2323 2323
         // fix defect #52438. implement the same logic as sugar_currency_format
@@ -2326,16 +2326,16 @@  discard block
 block discarded – undo
2326 2326
 
2327 2327
         global $module, $action;
2328 2328
         //Just to get optimistic locking working for this release
2329
-        if($this->optimistic_lock && $module == $this->module_dir && $action =='EditView' )
2329
+        if ($this->optimistic_lock && $module == $this->module_dir && $action == 'EditView')
2330 2330
         {
2331
-            $_SESSION['o_lock_id']= $id;
2332
-            $_SESSION['o_lock_dm']= $this->date_modified;
2331
+            $_SESSION['o_lock_id'] = $id;
2332
+            $_SESSION['o_lock_dm'] = $this->date_modified;
2333 2333
             $_SESSION['o_lock_on'] = $this->object_name;
2334 2334
         }
2335 2335
         $this->processed_dates_times = array();
2336 2336
         $this->check_date_relationships_load();
2337 2337
 
2338
-        if(isset($this->custom_fields))
2338
+        if (isset($this->custom_fields))
2339 2339
         {
2340 2340
             $this->custom_fields->fill_relationships();
2341 2341
         }
@@ -2346,23 +2346,23 @@  discard block
 block discarded – undo
2346 2346
 // save related fields values for audit
2347 2347
          foreach ($this->get_related_fields() as $rel_field_name)
2348 2348
          {
2349
-             if (! empty($this->$rel_field_name['name']))
2349
+             if (!empty($this->$rel_field_name['name']))
2350 2350
              {
2351 2351
                  $this->fetched_rel_row[$rel_field_name['name']] = $this->$rel_field_name['name'];
2352 2352
              }
2353 2353
          }
2354 2354
         //make a copy of fields in the relationship_fields array. These field values will be used to
2355 2355
         //clear relationship.
2356
-        foreach ( $this->field_defs as $key => $def )
2356
+        foreach ($this->field_defs as $key => $def)
2357 2357
         {
2358
-            if ($def [ 'type' ] == 'relate' && isset ( $def [ 'id_name'] ) && isset ( $def [ 'link'] ) && isset ( $def[ 'save' ])) {
2358
+            if ($def ['type'] == 'relate' && isset ($def ['id_name']) && isset ($def ['link']) && isset ($def['save'])) {
2359 2359
                 if (isset($this->$key)) {
2360
-                    $this->rel_fields_before_value[$key]=$this->$key;
2361
-                    if (isset($this->$def [ 'id_name']))
2362
-                        $this->rel_fields_before_value[$def [ 'id_name']]=$this->$def [ 'id_name'];
2360
+                    $this->rel_fields_before_value[$key] = $this->$key;
2361
+                    if (isset($this->$def ['id_name']))
2362
+                        $this->rel_fields_before_value[$def ['id_name']] = $this->$def ['id_name'];
2363 2363
                 }
2364 2364
                 else
2365
-                    $this->rel_fields_before_value[$key]=null;
2365
+                    $this->rel_fields_before_value[$key] = null;
2366 2366
            }
2367 2367
         }
2368 2368
         if (isset($this->relationship_fields) && is_array($this->relationship_fields))
@@ -2370,9 +2370,9 @@  discard block
 block discarded – undo
2370 2370
             foreach ($this->relationship_fields as $rel_id=>$rel_name)
2371 2371
             {
2372 2372
                 if (isset($this->$rel_id))
2373
-                    $this->rel_fields_before_value[$rel_id]=$this->$rel_id;
2373
+                    $this->rel_fields_before_value[$rel_id] = $this->$rel_id;
2374 2374
                 else
2375
-                    $this->rel_fields_before_value[$rel_id]=null;
2375
+                    $this->rel_fields_before_value[$rel_id] = null;
2376 2376
             }
2377 2377
         }
2378 2378
 
@@ -2395,16 +2395,16 @@  discard block
 block discarded – undo
2395 2395
      */
2396 2396
     function populateFromRow($row)
2397 2397
     {
2398
-        $nullvalue='';
2399
-        foreach($this->field_defs as $field=>$field_value)
2398
+        $nullvalue = '';
2399
+        foreach ($this->field_defs as $field=>$field_value)
2400 2400
         {
2401
-            if($field == 'user_preferences' && $this->module_dir == 'Users')
2401
+            if ($field == 'user_preferences' && $this->module_dir == 'Users')
2402 2402
                 continue;
2403
-            if(isset($row[$field]))
2403
+            if (isset($row[$field]))
2404 2404
             {
2405 2405
                 $this->$field = $row[$field];
2406
-                $owner = $field . '_owner';
2407
-                if(!empty($row[$owner])){
2406
+                $owner = $field.'_owner';
2407
+                if (!empty($row[$owner])) {
2408 2408
                     $this->$owner = $row[$owner];
2409 2409
                 }
2410 2410
             }
@@ -2446,48 +2446,48 @@  discard block
 block discarded – undo
2446 2446
     function create_list_count_query($query)
2447 2447
     {
2448 2448
         // remove the 'order by' clause which is expected to be at the end of the query
2449
-        $pattern = '/\sORDER BY.*/is';  // ignores the case
2449
+        $pattern = '/\sORDER BY.*/is'; // ignores the case
2450 2450
         $replacement = '';
2451 2451
         $query = preg_replace($pattern, $replacement, $query);
2452 2452
         //handle distinct clause
2453 2453
         $star = '*';
2454
-        if(substr_count(strtolower($query), 'distinct')){
2455
-            if (!empty($this->seed) && !empty($this->seed->table_name ))
2456
-                $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2454
+        if (substr_count(strtolower($query), 'distinct')) {
2455
+            if (!empty($this->seed) && !empty($this->seed->table_name))
2456
+                $star = 'DISTINCT '.$this->seed->table_name.'.id';
2457 2457
             else
2458
-                $star = 'DISTINCT ' . $this->table_name . '.id';
2458
+                $star = 'DISTINCT '.$this->table_name.'.id';
2459 2459
 
2460 2460
         }
2461 2461
 
2462 2462
         // change the select expression to 'count(*)'
2463
-        $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is';  // ignores the case
2464
-        $replacement = 'SELECT count(' . $star . ') c FROM ';
2463
+        $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is'; // ignores the case
2464
+        $replacement = 'SELECT count('.$star.') c FROM ';
2465 2465
 
2466 2466
         //if the passed query has union clause then replace all instances of the pattern.
2467 2467
         //this is very rare. I have seen this happening only from projects module.
2468 2468
         //in addition to this added a condition that has  union clause and uses
2469 2469
         //sub-selects.
2470
-        if (strstr($query," UNION ALL ") !== false) {
2470
+        if (strstr($query, " UNION ALL ") !== false) {
2471 2471
 
2472 2472
             //separate out all the queries.
2473
-            $union_qs=explode(" UNION ALL ", $query);
2473
+            $union_qs = explode(" UNION ALL ", $query);
2474 2474
             foreach ($union_qs as $key=>$union_query) {
2475 2475
                 $star = '*';
2476 2476
                 preg_match($pattern, $union_query, $matches);
2477 2477
                 if (!empty($matches)) {
2478 2478
                     if (stristr($matches[0], "distinct")) {
2479
-                        if (!empty($this->seed) && !empty($this->seed->table_name ))
2480
-                            $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2479
+                        if (!empty($this->seed) && !empty($this->seed->table_name))
2480
+                            $star = 'DISTINCT '.$this->seed->table_name.'.id';
2481 2481
                         else
2482
-                            $star = 'DISTINCT ' . $this->table_name . '.id';
2482
+                            $star = 'DISTINCT '.$this->table_name.'.id';
2483 2483
                     }
2484 2484
                 } // if
2485
-                $replacement = 'SELECT count(' . $star . ') c FROM ';
2486
-                $union_qs[$key] = preg_replace($pattern, $replacement, $union_query,1);
2485
+                $replacement = 'SELECT count('.$star.') c FROM ';
2486
+                $union_qs[$key] = preg_replace($pattern, $replacement, $union_query, 1);
2487 2487
             }
2488
-            $modified_select_query=implode(" UNION ALL ",$union_qs);
2488
+            $modified_select_query = implode(" UNION ALL ", $union_qs);
2489 2489
         } else {
2490
-            $modified_select_query = preg_replace($pattern, $replacement, $query,1);
2490
+            $modified_select_query = preg_replace($pattern, $replacement, $query, 1);
2491 2491
         }
2492 2492
 
2493 2493
 
@@ -2510,15 +2510,15 @@  discard block
 block discarded – undo
2510 2510
     * Internal function, do not override.
2511 2511
     *
2512 2512
     */
2513
-    function get_list($order_by = "", $where = "", $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $singleSelect=false, $select_fields = array())
2513
+    function get_list($order_by = "", $where = "", $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0, $singleSelect = false, $select_fields = array())
2514 2514
     {
2515 2515
         $GLOBALS['log']->debug("get_list:  order_by = '$order_by' and where = '$where' and limit = '$limit'");
2516
-        if(isset($_SESSION['show_deleted']))
2516
+        if (isset($_SESSION['show_deleted']))
2517 2517
         {
2518 2518
             $show_deleted = 1;
2519 2519
         }
2520 2520
 
2521
-        if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
2521
+        if ($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list'))
2522 2522
         {
2523 2523
             global $current_user;
2524 2524
             $owner_where = $this->getOwnerWhere($current_user->id);
@@ -2526,15 +2526,15 @@  discard block
 block discarded – undo
2526 2526
             //rrs - because $this->getOwnerWhere() can return '' we need to be sure to check for it and
2527 2527
             //handle it properly else you could get into a situation where you are create a where stmt like
2528 2528
             //WHERE .. AND ''
2529
-            if(!empty($owner_where)){
2530
-                if(empty($where)){
2529
+            if (!empty($owner_where)) {
2530
+                if (empty($where)) {
2531 2531
                     $where = $owner_where;
2532
-                }else{
2533
-                    $where .= ' AND '.  $owner_where;
2532
+                } else {
2533
+                    $where .= ' AND '.$owner_where;
2534 2534
                 }
2535 2535
             }
2536 2536
         }
2537
-        $query = $this->create_new_list_query($order_by, $where,$select_fields,array(), $show_deleted,'',false,null,$singleSelect);
2537
+        $query = $this->create_new_list_query($order_by, $where, $select_fields, array(), $show_deleted, '', false, null, $singleSelect);
2538 2538
         return $this->process_list_query($query, $row_offset, $limit, $max, $where);
2539 2539
     }
2540 2540
 
@@ -2580,9 +2580,9 @@  discard block
 block discarded – undo
2580 2580
 
2581 2581
                 if (empty($field_defs['table']) && !$suppress_table_name) {
2582 2582
                     if ($source == 'db') {
2583
-                        $list_column[0] = $bean_queried->table_name . '.' . $list_column[0] ;
2583
+                        $list_column[0] = $bean_queried->table_name.'.'.$list_column[0];
2584 2584
                     } elseif ($source == 'custom_fields') {
2585
-                        $list_column[0] = $bean_queried->table_name . '_cstm.' . $list_column[0] ;
2585
+                        $list_column[0] = $bean_queried->table_name.'_cstm.'.$list_column[0];
2586 2586
                     }
2587 2587
                 }
2588 2588
 
@@ -2636,49 +2636,49 @@  discard block
 block discarded – undo
2636 2636
     *
2637 2637
     * Internal function, do not override.
2638 2638
     */
2639
-    function get_detail($order_by = "", $where = "",  $offset = 0, $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0)
2639
+    function get_detail($order_by = "", $where = "", $offset = 0, $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0)
2640 2640
     {
2641 2641
         $GLOBALS['log']->debug("get_detail:  order_by = '$order_by' and where = '$where' and limit = '$limit' and offset = '$offset'");
2642
-        if(isset($_SESSION['show_deleted']))
2642
+        if (isset($_SESSION['show_deleted']))
2643 2643
         {
2644 2644
             $show_deleted = 1;
2645 2645
         }
2646 2646
 
2647
-        if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
2647
+        if ($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list'))
2648 2648
         {
2649 2649
             global $current_user;
2650 2650
             $owner_where = $this->getOwnerWhere($current_user->id);
2651 2651
 
2652
-            if(empty($where))
2652
+            if (empty($where))
2653 2653
             {
2654 2654
                 $where = $owner_where;
2655 2655
             }
2656 2656
             else
2657 2657
             {
2658
-                $where .= ' AND '.  $owner_where;
2658
+                $where .= ' AND '.$owner_where;
2659 2659
             }
2660 2660
         }
2661 2661
 
2662 2662
 		/* BEGIN - SECURITY GROUPS */
2663
-    	if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
2663
+    	if ($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list'))
2664 2664
     	{
2665 2665
 			require_once('modules/SecurityGroups/SecurityGroup.php');
2666 2666
     		global $current_user;
2667 2667
     		$owner_where = $this->getOwnerWhere($current_user->id);
2668
-    		$group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
2669
-	    	if(!empty($owner_where)){
2670
-				if(empty($where))
2668
+    		$group_where = SecurityGroup::getGroupWhere($this->table_name, $this->module_dir, $current_user->id);
2669
+	    	if (!empty($owner_where)) {
2670
+				if (empty($where))
2671 2671
 	    		{
2672
-	    			$where = " (".  $owner_where." or ".$group_where.") ";
2672
+	    			$where = " (".$owner_where." or ".$group_where.") ";
2673 2673
 	    		} else {
2674
-	    			$where .= " AND (".  $owner_where." or ".$group_where.") ";
2674
+	    			$where .= " AND (".$owner_where." or ".$group_where.") ";
2675 2675
 	    		}
2676 2676
 			} else {
2677
-				$where .= ' AND '.  $group_where;
2677
+				$where .= ' AND '.$group_where;
2678 2678
 			}
2679 2679
     	}
2680 2680
     	/* END - SECURITY GROUPS */
2681
-        $query = $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted, $offset);
2681
+        $query = $this->create_new_list_query($order_by, $where, array(), array(), $show_deleted, $offset);
2682 2682
 
2683 2683
         //Add Limit and Offset to query
2684 2684
         //$query .= " LIMIT 1 OFFSET $offset";
@@ -2697,13 +2697,13 @@  discard block
 block discarded – undo
2697 2697
     *
2698 2698
     * Internal function, do not override.
2699 2699
     */
2700
-    function get_related_list($child_seed,$related_field_name, $order_by = "", $where = "",
2701
-    $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0)
2700
+    function get_related_list($child_seed, $related_field_name, $order_by = "", $where = "",
2701
+    $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0)
2702 2702
     {
2703 2703
         global $layout_edit_mode;
2704 2704
         $query_array = array();
2705 2705
 
2706
-        if(isset($layout_edit_mode) && $layout_edit_mode)
2706
+        if (isset($layout_edit_mode) && $layout_edit_mode)
2707 2707
         {
2708 2708
             $response = array();
2709 2709
             $child_seed->assign_display_fields($child_seed->module_dir);
@@ -2715,7 +2715,7 @@  discard block
 block discarded – undo
2715 2715
             return $response;
2716 2716
         }
2717 2717
         $GLOBALS['log']->debug("get_related_list:  order_by = '$order_by' and where = '$where' and limit = '$limit'");
2718
-        if(isset($_SESSION['show_deleted']))
2718
+        if (isset($_SESSION['show_deleted']))
2719 2719
         {
2720 2720
             $show_deleted = 1;
2721 2721
         }
@@ -2734,22 +2734,22 @@  discard block
 block discarded – undo
2734 2734
         }
2735 2735
 
2736 2736
         $entire_where = $query_array['where'];
2737
-        if(!empty($where))
2737
+        if (!empty($where))
2738 2738
         {
2739
-            if(empty($entire_where))
2739
+            if (empty($entire_where))
2740 2740
             {
2741
-                $entire_where = ' WHERE ' . $where;
2741
+                $entire_where = ' WHERE '.$where;
2742 2742
             }
2743 2743
             else
2744 2744
             {
2745
-                $entire_where .= ' AND ' . $where;
2745
+                $entire_where .= ' AND '.$where;
2746 2746
             }
2747 2747
         }
2748 2748
 
2749
-        $query = 'SELECT '.$child_seed->table_name.'.* ' . $query_array['from'] . ' ' . $entire_where;
2750
-        if(!empty($order_by))
2749
+        $query = 'SELECT '.$child_seed->table_name.'.* '.$query_array['from'].' '.$entire_where;
2750
+        if (!empty($order_by))
2751 2751
         {
2752
-            $query .= " ORDER BY " . $order_by;
2752
+            $query .= " ORDER BY ".$order_by;
2753 2753
         }
2754 2754
 
2755 2755
         return $child_seed->process_list_query($query, $row_offset, $limit, $max, $where);
@@ -2760,27 +2760,27 @@  discard block
 block discarded – undo
2760 2760
     {
2761 2761
         global $layout_edit_mode, $beanFiles, $beanList;
2762 2762
         $subqueries = array();
2763
-        foreach($subpanel_list as $this_subpanel)
2763
+        foreach ($subpanel_list as $this_subpanel)
2764 2764
         {
2765
-            if(!$this_subpanel->isDatasourceFunction() || ($this_subpanel->isDatasourceFunction()
2765
+            if (!$this_subpanel->isDatasourceFunction() || ($this_subpanel->isDatasourceFunction()
2766 2766
                 && isset($this_subpanel->_instance_properties['generate_select'])
2767
-                && $this_subpanel->_instance_properties['generate_select']==true))
2767
+                && $this_subpanel->_instance_properties['generate_select'] == true))
2768 2768
             {
2769 2769
                 //the custom query function must return an array with
2770 2770
                 if ($this_subpanel->isDatasourceFunction()) {
2771 2771
                     $shortcut_function_name = $this_subpanel->get_data_source_name();
2772
-                    $parameters=$this_subpanel->get_function_parameters();
2772
+                    $parameters = $this_subpanel->get_function_parameters();
2773 2773
                     if (!empty($parameters))
2774 2774
                     {
2775 2775
                         //if the import file function is set, then import the file to call the custom function from
2776
-                        if (is_array($parameters)  && isset($parameters['import_function_file'])){
2776
+                        if (is_array($parameters) && isset($parameters['import_function_file'])) {
2777 2777
                             //this call may happen multiple times, so only require if function does not exist
2778
-                            if(!function_exists($shortcut_function_name)){
2778
+                            if (!function_exists($shortcut_function_name)) {
2779 2779
                                 require_once($parameters['import_function_file']);
2780 2780
                             }
2781 2781
                             //call function from required file
2782 2782
                             $query_array = $shortcut_function_name($parameters);
2783
-                        }else{
2783
+                        } else {
2784 2784
                             //call function from parent bean
2785 2785
                             $query_array = $parentbean->$shortcut_function_name($parameters);
2786 2786
                         }
@@ -2789,9 +2789,9 @@  discard block
 block discarded – undo
2789 2789
                     {
2790 2790
                         $query_array = $parentbean->$shortcut_function_name();
2791 2791
                     }
2792
-                }  else {
2792
+                } else {
2793 2793
                     $related_field_name = $this_subpanel->get_data_source_name();
2794
-                    if (!$parentbean->load_relationship($related_field_name)){
2794
+                    if (!$parentbean->load_relationship($related_field_name)) {
2795 2795
                         unset ($parentbean->$related_field_name);
2796 2796
                         continue;
2797 2797
                     }
@@ -2800,15 +2800,15 @@  discard block
 block discarded – undo
2800 2800
                 $table_where = preg_replace('/^\s*WHERE/i', '', $this_subpanel->get_where());
2801 2801
                 $where_definition = preg_replace('/^\s*WHERE/i', '', $query_array['where']);
2802 2802
 
2803
-                if(!empty($table_where))
2803
+                if (!empty($table_where))
2804 2804
                 {
2805
-                    if(empty($where_definition))
2805
+                    if (empty($where_definition))
2806 2806
                     {
2807 2807
                         $where_definition = $table_where;
2808 2808
                     }
2809 2809
                     else
2810 2810
                     {
2811
-                        $where_definition .= ' AND ' . $table_where;
2811
+                        $where_definition .= ' AND '.$table_where;
2812 2812
                     }
2813 2813
                 }
2814 2814
 
@@ -2823,21 +2823,21 @@  discard block
 block discarded – undo
2823 2823
 
2824 2824
 
2825 2825
                 $list_fields = $this_subpanel->get_list_fields();
2826
-                foreach($list_fields as $list_key=>$list_field)
2826
+                foreach ($list_fields as $list_key=>$list_field)
2827 2827
                 {
2828
-                    if(isset($list_field['usage']) && $list_field['usage'] == 'display_only')
2828
+                    if (isset($list_field['usage']) && $list_field['usage'] == 'display_only')
2829 2829
                     {
2830 2830
                         unset($list_fields[$list_key]);
2831 2831
                     }
2832 2832
                 }
2833 2833
 
2834 2834
 
2835
-                if(!$subpanel_def->isCollection() && isset($list_fields[$order_by]) && isset($submodule->field_defs[$order_by])&& (!isset($submodule->field_defs[$order_by]['source']) || $submodule->field_defs[$order_by]['source'] == 'db'))
2835
+                if (!$subpanel_def->isCollection() && isset($list_fields[$order_by]) && isset($submodule->field_defs[$order_by]) && (!isset($submodule->field_defs[$order_by]['source']) || $submodule->field_defs[$order_by]['source'] == 'db'))
2836 2836
                 {
2837
-                    $order_by = $submodule->table_name .'.'. $order_by;
2837
+                    $order_by = $submodule->table_name.'.'.$order_by;
2838 2838
                 }
2839 2839
                 $table_name = $this_subpanel->table_name;
2840
-                $panel_name=$this_subpanel->name;
2840
+                $panel_name = $this_subpanel->name;
2841 2841
                 $params = array();
2842 2842
                 $params['distinct'] = $this_subpanel->distinct_query();
2843 2843
 
@@ -2848,7 +2848,7 @@  discard block
 block discarded – undo
2848 2848
                 // use single select in case when sorting by relate field
2849 2849
                 $singleSelect = $submodule->is_relate_field($order_by);
2850 2850
 
2851
-                $subquery = $submodule->create_new_list_query('',$subwhere ,$list_fields,$params, 0,'', true,$parentbean, $singleSelect);
2851
+                $subquery = $submodule->create_new_list_query('', $subwhere, $list_fields, $params, 0, '', true, $parentbean, $singleSelect);
2852 2852
 
2853 2853
                 $subquery['select'] = $subquery['select']." , '$panel_name' panel_name ";
2854 2854
                 $subquery['from'] = $subquery['from'].$query_array['join'];
@@ -2880,27 +2880,27 @@  discard block
 block discarded – undo
2880 2880
      *
2881 2881
      * Internal Function, do not overide.
2882 2882
      */
2883
-    static function get_union_related_list($parentbean, $order_by = "", $sort_order='', $where = "",
2884
-    $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $subpanel_def)
2883
+    static function get_union_related_list($parentbean, $order_by = "", $sort_order = '', $where = "",
2884
+    $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0, $subpanel_def)
2885 2885
     {
2886 2886
         $secondary_queries = array();
2887 2887
         global $layout_edit_mode, $beanFiles, $beanList;
2888 2888
 
2889
-        if(isset($_SESSION['show_deleted']))
2889
+        if (isset($_SESSION['show_deleted']))
2890 2890
         {
2891 2891
             $show_deleted = 1;
2892 2892
         }
2893 2893
         $final_query = '';
2894 2894
         $final_query_rows = '';
2895
-        $subpanel_list=array();
2895
+        $subpanel_list = array();
2896 2896
         if ($subpanel_def->isCollection())
2897 2897
         {
2898 2898
             $subpanel_def->load_sub_subpanels();
2899
-            $subpanel_list=$subpanel_def->sub_subpanels;
2899
+            $subpanel_list = $subpanel_def->sub_subpanels;
2900 2900
         }
2901 2901
         else
2902 2902
         {
2903
-            $subpanel_list[]=$subpanel_def;
2903
+            $subpanel_list[] = $subpanel_def;
2904 2904
         }
2905 2905
 
2906 2906
         $first = true;
@@ -2909,36 +2909,36 @@  discard block
 block discarded – undo
2909 2909
         //The second loop merges the queries and forces them to select the same number of columns
2910 2910
         //All columns in a sub-subpanel group must have the same aliases
2911 2911
         //If the subpanel is a datasource function, it can't be a collection so we just poll that function for the and return that
2912
-        foreach($subpanel_list as $this_subpanel)
2912
+        foreach ($subpanel_list as $this_subpanel)
2913 2913
         {
2914
-            if($this_subpanel->isDatasourceFunction() && empty($this_subpanel->_instance_properties['generate_select']))
2914
+            if ($this_subpanel->isDatasourceFunction() && empty($this_subpanel->_instance_properties['generate_select']))
2915 2915
             {
2916 2916
                 $shortcut_function_name = $this_subpanel->get_data_source_name();
2917
-                $parameters=$this_subpanel->get_function_parameters();
2917
+                $parameters = $this_subpanel->get_function_parameters();
2918 2918
                 if (!empty($parameters))
2919 2919
                 {
2920 2920
                     //if the import file function is set, then import the file to call the custom function from
2921
-                    if (is_array($parameters)  && isset($parameters['import_function_file'])){
2921
+                    if (is_array($parameters) && isset($parameters['import_function_file'])) {
2922 2922
                         //this call may happen multiple times, so only require if function does not exist
2923
-                        if(!function_exists($shortcut_function_name)){
2923
+                        if (!function_exists($shortcut_function_name)) {
2924 2924
                             require_once($parameters['import_function_file']);
2925 2925
                         }
2926 2926
                         //call function from required file
2927
-                        $tmp_final_query =  $shortcut_function_name($parameters);
2928
-                    }else{
2927
+                        $tmp_final_query = $shortcut_function_name($parameters);
2928
+                    } else {
2929 2929
                         //call function from parent bean
2930
-                        $tmp_final_query =  $parentbean->$shortcut_function_name($parameters);
2930
+                        $tmp_final_query = $parentbean->$shortcut_function_name($parameters);
2931 2931
                     }
2932 2932
                 } else {
2933 2933
                     $tmp_final_query = $parentbean->$shortcut_function_name();
2934 2934
                 }
2935
-                if(!$first)
2935
+                if (!$first)
2936 2936
                     {
2937
-                        $final_query_rows .= ' UNION ALL ( '.$parentbean->create_list_count_query($tmp_final_query, $parameters) . ' )';
2938
-                        $final_query .= ' UNION ALL ( '.$tmp_final_query . ' )';
2937
+                        $final_query_rows .= ' UNION ALL ( '.$parentbean->create_list_count_query($tmp_final_query, $parameters).' )';
2938
+                        $final_query .= ' UNION ALL ( '.$tmp_final_query.' )';
2939 2939
                     } else {
2940
-                        $final_query_rows = '(' . $parentbean->create_list_count_query($tmp_final_query, $parameters) . ')';
2941
-                        $final_query = '(' . $tmp_final_query . ')';
2940
+                        $final_query_rows = '('.$parentbean->create_list_count_query($tmp_final_query, $parameters).')';
2941
+                        $final_query = '('.$tmp_final_query.')';
2942 2942
                         $first = false;
2943 2943
                     }
2944 2944
                 }
@@ -2948,10 +2948,10 @@  discard block
 block discarded – undo
2948 2948
         {
2949 2949
             $subqueries = SugarBean::build_sub_queries_for_union($subpanel_list, $subpanel_def, $parentbean, $order_by);
2950 2950
             $all_fields = array();
2951
-            foreach($subqueries as $i => $subquery)
2951
+            foreach ($subqueries as $i => $subquery)
2952 2952
             {
2953 2953
                 $query_fields = $GLOBALS['db']->getSelectFieldsFromQuery($subquery['select']);
2954
-                foreach($query_fields as $field => $select)
2954
+                foreach ($query_fields as $field => $select)
2955 2955
                 {
2956 2956
                     if (!in_array($field, $all_fields))
2957 2957
                         $all_fields[] = $field;
@@ -2960,10 +2960,10 @@  discard block
 block discarded – undo
2960 2960
             }
2961 2961
             $first = true;
2962 2962
             //Now ensure the queries have the same set of fields in the same order.
2963
-            foreach($subqueries as $subquery)
2963
+            foreach ($subqueries as $subquery)
2964 2964
             {
2965 2965
                 $subquery['select'] = "SELECT";
2966
-                foreach($all_fields as $field)
2966
+                foreach ($all_fields as $field)
2967 2967
                 {
2968 2968
                     if (!isset($subquery['query_fields'][$field]))
2969 2969
                     {
@@ -2974,56 +2974,56 @@  discard block
 block discarded – undo
2974 2974
                         $subquery['select'] .= " {$subquery['query_fields'][$field]},";
2975 2975
                     }
2976 2976
                 }
2977
-                $subquery['select'] = substr($subquery['select'], 0 , strlen($subquery['select']) - 1);
2977
+                $subquery['select'] = substr($subquery['select'], 0, strlen($subquery['select']) - 1);
2978 2978
                 //Put the query into the final_query
2979
-                $query =  $subquery['select'] . " " . $subquery['from'] . " " . $subquery['where'];
2980
-                if(!$first)
2979
+                $query = $subquery['select']." ".$subquery['from']." ".$subquery['where'];
2980
+                if (!$first)
2981 2981
                 {
2982
-                    $query = ' UNION ALL ( '.$query . ' )';
2982
+                    $query = ' UNION ALL ( '.$query.' )';
2983 2983
                     $final_query_rows .= " UNION ALL ";
2984 2984
                 } else {
2985
-                    $query = '(' . $query . ')';
2985
+                    $query = '('.$query.')';
2986 2986
                     $first = false;
2987 2987
                 }
2988 2988
                 $query_array = $subquery['query_array'];
2989
-                $select_position=strpos($query_array['select'],"SELECT");
2990
-                $distinct_position=strpos($query_array['select'],"DISTINCT");
2989
+                $select_position = strpos($query_array['select'], "SELECT");
2990
+                $distinct_position = strpos($query_array['select'], "DISTINCT");
2991 2991
                 if (!empty($subquery['params']['distinct']) && !empty($subpanel_def->table_name))
2992 2992
                 {
2993
-                    $query_rows = "( SELECT count(DISTINCT ". $subpanel_def->table_name . ".id)".  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
2993
+                    $query_rows = "( SELECT count(DISTINCT ".$subpanel_def->table_name.".id)".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
2994 2994
                 }
2995
-                elseif ($select_position !== false && $distinct_position!= false)
2995
+                elseif ($select_position !== false && $distinct_position != false)
2996 2996
                 {
2997
-                    $query_rows = "( ".substr_replace($query_array['select'],"SELECT count(",$select_position,6). ")" .  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
2997
+                    $query_rows = "( ".substr_replace($query_array['select'], "SELECT count(", $select_position, 6).")".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
2998 2998
                 }
2999 2999
                 else
3000 3000
                 {
3001 3001
                     //resort to default behavior.
3002
-                    $query_rows = "( SELECT count(*)".  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
3002
+                    $query_rows = "( SELECT count(*)".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
3003 3003
                 }
3004
-                if(!empty($subquery['secondary_select']))
3004
+                if (!empty($subquery['secondary_select']))
3005 3005
                 {
3006 3006
 
3007
-                    $subquerystring= $subquery['secondary_select'] . $subquery['secondary_from'].$query_array['join']. $subquery['where'];
3007
+                    $subquerystring = $subquery['secondary_select'].$subquery['secondary_from'].$query_array['join'].$subquery['where'];
3008 3008
                     if (!empty($subquery['secondary_where']))
3009 3009
                     {
3010 3010
                         if (empty($subquery['where']))
3011 3011
                         {
3012
-                            $subquerystring.=" WHERE " .$subquery['secondary_where'];
3012
+                            $subquerystring .= " WHERE ".$subquery['secondary_where'];
3013 3013
                         }
3014 3014
                         else
3015 3015
                         {
3016
-                            $subquerystring.=" AND " .$subquery['secondary_where'];
3016
+                            $subquerystring .= " AND ".$subquery['secondary_where'];
3017 3017
                         }
3018 3018
                     }
3019
-                    $secondary_queries[]=$subquerystring;
3019
+                    $secondary_queries[] = $subquerystring;
3020 3020
                 }
3021 3021
                 $final_query .= $query;
3022 3022
                 $final_query_rows .= $query_rows;
3023 3023
             }
3024 3024
         }
3025 3025
 
3026
-        if(!empty($order_by))
3026
+        if (!empty($order_by))
3027 3027
         {
3028 3028
             $isCollection = $subpanel_def->isCollection();
3029 3029
             if ($isCollection) {
@@ -3037,20 +3037,20 @@  discard block
 block discarded – undo
3037 3037
             }
3038 3038
 
3039 3039
             if (!empty($sort_order)) {
3040
-                $order_by .= ' ' . $sort_order;
3040
+                $order_by .= ' '.$sort_order;
3041 3041
             }
3042 3042
 
3043 3043
             $order_by = $parentbean->process_order_by($order_by, $submodule, $suppress_table_name);
3044 3044
             if (!empty($order_by)) {
3045
-                $final_query .= ' ORDER BY ' . $order_by;
3045
+                $final_query .= ' ORDER BY '.$order_by;
3046 3046
             }
3047 3047
         }
3048 3048
 
3049 3049
 
3050
-        if(isset($layout_edit_mode) && $layout_edit_mode)
3050
+        if (isset($layout_edit_mode) && $layout_edit_mode)
3051 3051
         {
3052 3052
             $response = array();
3053
-            if(!empty($submodule))
3053
+            if (!empty($submodule))
3054 3054
             {
3055 3055
                 $submodule->assign_display_fields($submodule->module_dir);
3056 3056
                 $response['list'] = array($submodule);
@@ -3067,7 +3067,7 @@  discard block
 block discarded – undo
3067 3067
             return $response;
3068 3068
         }
3069 3069
 
3070
-        return $parentbean->process_union_list_query($parentbean, $final_query, $row_offset, $limit, $max, '',$subpanel_def, $final_query_rows, $secondary_queries);
3070
+        return $parentbean->process_union_list_query($parentbean, $final_query, $row_offset, $limit, $max, '', $subpanel_def, $final_query_rows, $secondary_queries);
3071 3071
     }
3072 3072
 
3073 3073
 
@@ -3079,14 +3079,14 @@  discard block
 block discarded – undo
3079 3079
     * @param boolean $check_dates. defaults to false
3080 3080
     * @param int $show_deleted show deleted records. defaults to 0
3081 3081
     */
3082
-    function get_full_list($order_by = "", $where = "", $check_dates=false, $show_deleted = 0)
3082
+    function get_full_list($order_by = "", $where = "", $check_dates = false, $show_deleted = 0)
3083 3083
     {
3084 3084
         $GLOBALS['log']->debug("get_full_list:  order_by = '$order_by' and where = '$where'");
3085
-        if(isset($_SESSION['show_deleted']))
3085
+        if (isset($_SESSION['show_deleted']))
3086 3086
         {
3087 3087
             $show_deleted = 1;
3088 3088
         }
3089
-        $query = $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted);
3089
+        $query = $this->create_new_list_query($order_by, $where, array(), array(), $show_deleted);
3090 3090
         return $this->process_full_list_query($query, $check_dates);
3091 3091
     }
3092 3092
 
@@ -3106,29 +3106,29 @@  discard block
 block discarded – undo
3106 3106
      * @param boolean $singleSelect Optional, default false.
3107 3107
      * @return String select query string, optionally an array value will be returned if $return_array= true.
3108 3108
      */
3109
-	function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false, $ifListForExport = false)
3109
+	function create_new_list_query($order_by, $where, $filter = array(), $params = array(), $show_deleted = 0, $join_type = '', $return_array = false, $parentbean = null, $singleSelect = false, $ifListForExport = false)
3110 3110
     {
3111 3111
         global $beanFiles, $beanList;
3112 3112
         $selectedFields = array();
3113 3113
         $secondarySelectedFields = array();
3114 3114
         $ret_array = array();
3115 3115
         $distinct = '';
3116
-        if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
3116
+        if ($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list'))
3117 3117
         {
3118 3118
             global $current_user;
3119 3119
             $owner_where = $this->getOwnerWhere($current_user->id);
3120
-            if(empty($where))
3120
+            if (empty($where))
3121 3121
             {
3122 3122
                 $where = $owner_where;
3123 3123
             }
3124 3124
             else
3125 3125
             {
3126
-                $where .= ' AND '.  $owner_where;
3126
+                $where .= ' AND '.$owner_where;
3127 3127
             }
3128 3128
         }
3129 3129
 		/* BEGIN - SECURITY GROUPS */
3130 3130
     	global $current_user, $sugar_config;
3131
-    	if($this->module_dir == 'Users' && !is_admin($current_user)
3131
+    	if ($this->module_dir == 'Users' && !is_admin($current_user)
3132 3132
 				&& isset($sugar_config['securitysuite_filter_user_list'])
3133 3133
 				&& $sugar_config['securitysuite_filter_user_list'] == true
3134 3134
     	) {
@@ -3136,36 +3136,36 @@  discard block
 block discarded – undo
3136 3136
     		global $current_user;
3137 3137
     		$group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
3138 3138
     		//$group_where = "user_name = 'admin'";
3139
-    		if(empty($where))
3139
+    		if (empty($where))
3140 3140
     		{
3141 3141
     			$where = " (".$group_where.") ";
3142 3142
     		} else {
3143 3143
     			$where .= " AND (".$group_where.") ";
3144 3144
     		}
3145 3145
     	} else
3146
-    	if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
3146
+    	if ($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list'))
3147 3147
     	{
3148 3148
 			require_once('modules/SecurityGroups/SecurityGroup.php');
3149 3149
     		global $current_user;
3150 3150
     		$owner_where = $this->getOwnerWhere($current_user->id);
3151
-    		$group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
3152
-	    	if(!empty($owner_where)){
3153
-				if(empty($where))
3151
+    		$group_where = SecurityGroup::getGroupWhere($this->table_name, $this->module_dir, $current_user->id);
3152
+	    	if (!empty($owner_where)) {
3153
+				if (empty($where))
3154 3154
 	    		{
3155
-	    			$where = " (".  $owner_where." or ".$group_where.") ";
3155
+	    			$where = " (".$owner_where." or ".$group_where.") ";
3156 3156
 	    		} else {
3157
-	    			$where .= " AND (".  $owner_where." or ".$group_where.") ";
3157
+	    			$where .= " AND (".$owner_where." or ".$group_where.") ";
3158 3158
 	    		}
3159 3159
 			} else {
3160
-				$where .= ' AND '.  $group_where;
3160
+				$where .= ' AND '.$group_where;
3161 3161
 			}
3162 3162
     	}
3163 3163
     	/* END - SECURITY GROUPS */
3164
-        if(!empty($params['distinct']))
3164
+        if (!empty($params['distinct']))
3165 3165
         {
3166 3166
             $distinct = ' DISTINCT ';
3167 3167
         }
3168
-        if(empty($filter))
3168
+        if (empty($filter))
3169 3169
         {
3170 3170
             $ret_array['select'] = " SELECT $distinct $this->table_name.* ";
3171 3171
         }
@@ -3175,21 +3175,21 @@  discard block
 block discarded – undo
3175 3175
         }
3176 3176
         $ret_array['from'] = " FROM $this->table_name ";
3177 3177
         $ret_array['from_min'] = $ret_array['from'];
3178
-        $ret_array['secondary_from'] = $ret_array['from'] ;
3178
+        $ret_array['secondary_from'] = $ret_array['from'];
3179 3179
         $ret_array['where'] = '';
3180 3180
         $ret_array['order_by'] = '';
3181 3181
         //secondary selects are selects that need to be run after the primary query to retrieve additional info on main
3182
-        if($singleSelect)
3182
+        if ($singleSelect)
3183 3183
         {
3184
-            $ret_array['secondary_select']=& $ret_array['select'];
3184
+            $ret_array['secondary_select'] = & $ret_array['select'];
3185 3185
             $ret_array['secondary_from'] = & $ret_array['from'];
3186 3186
         }
3187 3187
         else
3188 3188
         {
3189 3189
             $ret_array['secondary_select'] = '';
3190 3190
         }
3191
-        $custom_join = $this->getCustomJoin( empty($filter)? true: $filter );
3192
-        if((!isset($params['include_custom_fields']) || $params['include_custom_fields']))
3191
+        $custom_join = $this->getCustomJoin(empty($filter) ? true : $filter);
3192
+        if ((!isset($params['include_custom_fields']) || $params['include_custom_fields']))
3193 3193
         {
3194 3194
             $ret_array['select'] .= $custom_join['select'];
3195 3195
         }
@@ -3205,43 +3205,43 @@  discard block
 block discarded – undo
3205 3205
         }
3206 3206
 
3207 3207
         $joined_tables = array();
3208
-        if(!empty($params['joined_tables']))
3208
+        if (!empty($params['joined_tables']))
3209 3209
         {
3210
-            foreach($params['joined_tables'] as $table)
3210
+            foreach ($params['joined_tables'] as $table)
3211 3211
             {
3212 3212
                 $joined_tables[$table] = 1;
3213 3213
             }
3214 3214
         }
3215 3215
 
3216
-        if(!empty($filter))
3216
+        if (!empty($filter))
3217 3217
         {
3218 3218
             $filterKeys = array_keys($filter);
3219
-            if(is_numeric($filterKeys[0]))
3219
+            if (is_numeric($filterKeys[0]))
3220 3220
             {
3221 3221
                 $fields = array();
3222
-                foreach($filter as $field)
3222
+                foreach ($filter as $field)
3223 3223
                 {
3224 3224
                     $field = strtolower($field);
3225 3225
                     //remove out id field so we don't duplicate it
3226
-                    if ( $field == 'id' && !empty($filter) ) {
3226
+                    if ($field == 'id' && !empty($filter)) {
3227 3227
                         continue;
3228 3228
                     }
3229
-                    if(isset($this->field_defs[$field]))
3229
+                    if (isset($this->field_defs[$field]))
3230 3230
                     {
3231
-                        $fields[$field]= $this->field_defs[$field];
3231
+                        $fields[$field] = $this->field_defs[$field];
3232 3232
                     }
3233 3233
                     else
3234 3234
                     {
3235 3235
                         $fields[$field] = array('force_exists'=>true);
3236 3236
                     }
3237 3237
                 }
3238
-            }else{
3239
-                $fields = 	$filter;
3238
+            } else {
3239
+                $fields = $filter;
3240 3240
             }
3241 3241
         }
3242 3242
         else
3243 3243
         {
3244
-            $fields = 	$this->field_defs;
3244
+            $fields = $this->field_defs;
3245 3245
         }
3246 3246
 
3247 3247
         $used_join_key = array();
@@ -3249,7 +3249,7 @@  discard block
 block discarded – undo
3249 3249
 	//walk through the fields and for every relationship field add their relationship_info field
3250 3250
 	//relationshipfield-aliases are resolved in SugarBean::create_new_list_query through their relationship_info field
3251 3251
 	$addrelate = array();
3252
-	foreach($fields as $field=>$value)
3252
+	foreach ($fields as $field=>$value)
3253 3253
 	{
3254 3254
 		if (isset($this->field_defs[$field]) && isset($this->field_defs[$field]['source']) && 
3255 3255
 			$this->field_defs[$field]['source'] == 'non-db')
@@ -3258,27 +3258,27 @@  discard block
 block discarded – undo
3258 3258
 			if ($addrelatefield)
3259 3259
 				$addrelate[$addrelatefield] = true;
3260 3260
 		}
3261
-		if(!empty($this->field_defs[$field]['id_name'])){
3261
+		if (!empty($this->field_defs[$field]['id_name'])) {
3262 3262
 			$addrelate[$this->field_defs[$field]['id_name']] = true;
3263 3263
 		}
3264 3264
 	}
3265 3265
 
3266 3266
 	$fields = array_merge($addrelate, $fields);
3267 3267
 
3268
-        foreach($fields as $field=>$value)
3268
+        foreach ($fields as $field=>$value)
3269 3269
         {
3270 3270
             //alias is used to alias field names
3271
-            $alias='';
3272
-            if 	(isset($value['alias']))
3271
+            $alias = '';
3272
+            if (isset($value['alias']))
3273 3273
             {
3274
-                $alias =' as ' . $value['alias'] . ' ';
3274
+                $alias = ' as '.$value['alias'].' ';
3275 3275
             }
3276 3276
 
3277
-            if(empty($this->field_defs[$field]) || !empty($value['force_blank']) )
3277
+            if (empty($this->field_defs[$field]) || !empty($value['force_blank']))
3278 3278
             {
3279
-                if(!empty($filter) && isset($filter[$field]['force_exists']) && $filter[$field]['force_exists'])
3279
+                if (!empty($filter) && isset($filter[$field]['force_exists']) && $filter[$field]['force_exists'])
3280 3280
                 {
3281
-                    if ( isset($filter[$field]['force_default']) )
3281
+                    if (isset($filter[$field]['force_default']))
3282 3282
                         $ret_array['select'] .= ", {$filter[$field]['force_default']} $field ";
3283 3283
                     else
3284 3284
                     //spaces are a fix for length issue problem with unions.  The union only returns the maximum number of characters from the first select statement.
@@ -3310,14 +3310,14 @@  discard block
 block discarded – undo
3310 3310
                 	continue;
3311 3311
             }
3312 3312
 
3313
-            if(  (!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter) ))
3313
+            if ((!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter)))
3314 3314
             {
3315 3315
                 $ret_array['select'] .= ", $this->table_name.$field $alias";
3316 3316
                 $selectedFields["$this->table_name.$field"] = true;
3317
-            } else if(  (!isset($data['source']) || $data['source'] == 'custom_fields') && (!empty($alias) || !empty($filter) )) {
3317
+            } else if ((!isset($data['source']) || $data['source'] == 'custom_fields') && (!empty($alias) || !empty($filter))) {
3318 3318
                 //add this column only if it has NOT already been added to select statement string
3319
-                $colPos = strpos($ret_array['select'],"$this->table_name"."_cstm".".$field");
3320
-                if(!$colPos || $colPos<0)
3319
+                $colPos = strpos($ret_array['select'], "$this->table_name"."_cstm".".$field");
3320
+                if (!$colPos || $colPos < 0)
3321 3321
                 {
3322 3322
                     $ret_array['select'] .= ", $this->table_name"."_cstm".".$field $alias";
3323 3323
                 }
@@ -3325,22 +3325,22 @@  discard block
 block discarded – undo
3325 3325
                 $selectedFields["$this->table_name.$field"] = true;
3326 3326
             }
3327 3327
 
3328
-            if($data['type'] != 'relate' && isset($data['db_concat_fields']))
3328
+            if ($data['type'] != 'relate' && isset($data['db_concat_fields']))
3329 3329
             {
3330
-                $ret_array['select'] .= ", " . $this->db->concat($this->table_name, $data['db_concat_fields']) . " as $field";
3330
+                $ret_array['select'] .= ", ".$this->db->concat($this->table_name, $data['db_concat_fields'])." as $field";
3331 3331
                 $selectedFields[$this->db->concat($this->table_name, $data['db_concat_fields'])] = true;
3332 3332
             }
3333 3333
             //Custom relate field or relate fields built in module builder which have no link field associated.
3334 3334
             if ($data['type'] == 'relate' && (isset($data['custom_module']) || isset($data['ext2']))) {
3335
-                $joinTableAlias = 'jt' . $jtcount;
3335
+                $joinTableAlias = 'jt'.$jtcount;
3336 3336
                 $relateJoinInfo = $this->custom_fields->getRelateJoin($data, $joinTableAlias, false);
3337 3337
                 $ret_array['select'] .= $relateJoinInfo['select'];
3338 3338
                 $ret_array['from'] .= $relateJoinInfo['from'];
3339 3339
                 //Replace any references to the relationship in the where clause with the new alias
3340 3340
                 //If the link isn't set, assume that search used the local table for the field
3341 3341
                 $searchTable = isset($data['link']) ? $relateJoinInfo['rel_table'] : $this->table_name;
3342
-                $field_name = $relateJoinInfo['rel_table'] . '.' . !empty($data['name'])?$data['name']:'name';
3343
-                $where = preg_replace('/(^|[\s(])' . $field_name . '/' , '${1}' . $relateJoinInfo['name_field'], $where);
3342
+                $field_name = $relateJoinInfo['rel_table'].'.'.!empty($data['name']) ? $data['name'] : 'name';
3343
+                $where = preg_replace('/(^|[\s(])'.$field_name.'/', '${1}'.$relateJoinInfo['name_field'], $where);
3344 3344
                 $jtcount++;
3345 3345
             }
3346 3346
             //Parent Field
@@ -3348,7 +3348,7 @@  discard block
 block discarded – undo
3348 3348
                 //See if we need to join anything by inspecting the where clause
3349 3349
                 $match = preg_match('/(^|[\s(])parent_(\w+)_(\w+)\.name/', $where, $matches);
3350 3350
                 if ($match) {
3351
-                    $joinTableAlias = 'jt' . $jtcount;
3351
+                    $joinTableAlias = 'jt'.$jtcount;
3352 3352
                     $joinModule = $matches[2];
3353 3353
                     $joinTable = $matches[3];
3354 3354
                     $localTable = $this->table_name;
@@ -3362,7 +3362,7 @@  discard block
 block discarded – undo
3362 3362
                     if (isset($rel_mod->field_defs['name']))
3363 3363
                     {
3364 3364
                         $name_field_def = $rel_mod->field_defs['name'];
3365
-                        if(isset($name_field_def['db_concat_fields']))
3365
+                        if (isset($name_field_def['db_concat_fields']))
3366 3366
                         {
3367 3367
                             $nameField = $this->db->concat($joinTableAlias, $name_field_def['db_concat_fields']);
3368 3368
                         }
@@ -3371,7 +3371,7 @@  discard block
 block discarded – undo
3371 3371
                     $ret_array['from'] .= " LEFT JOIN $joinTable $joinTableAlias
3372 3372
                         ON $localTable.{$data['id_name']} = $joinTableAlias.id";
3373 3373
                     //Replace any references to the relationship in the where clause with the new alias
3374
-                    $where = preg_replace('/(^|[\s(])parent_' . $joinModule . '_' . $joinTable . '\.name/', '${1}' . $nameField, $where);
3374
+                    $where = preg_replace('/(^|[\s(])parent_'.$joinModule.'_'.$joinTable.'\.name/', '${1}'.$nameField, $where);
3375 3375
                     $jtcount++;
3376 3376
                 }
3377 3377
             }
@@ -3379,10 +3379,10 @@  discard block
 block discarded – undo
3379 3379
             if ($this->is_relate_field($field))
3380 3380
             {
3381 3381
                 $this->load_relationship($data['link']);
3382
-                if(!empty($this->$data['link']))
3382
+                if (!empty($this->$data['link']))
3383 3383
                 {
3384 3384
                     $params = array();
3385
-                    if(empty($join_type))
3385
+                    if (empty($join_type))
3386 3386
                     {
3387 3387
                         $params['join_type'] = ' LEFT JOIN ';
3388 3388
                     }
@@ -3390,22 +3390,22 @@  discard block
 block discarded – undo
3390 3390
                     {
3391 3391
                         $params['join_type'] = $join_type;
3392 3392
                     }
3393
-                    if(isset($data['join_name']))
3393
+                    if (isset($data['join_name']))
3394 3394
                     {
3395 3395
                         $params['join_table_alias'] = $data['join_name'];
3396 3396
                     }
3397 3397
                     else
3398 3398
                     {
3399
-                        $params['join_table_alias']	= 'jt' . $jtcount;
3399
+                        $params['join_table_alias'] = 'jt'.$jtcount;
3400 3400
 
3401 3401
                     }
3402
-                    if(isset($data['join_link_name']))
3402
+                    if (isset($data['join_link_name']))
3403 3403
                     {
3404 3404
                         $params['join_table_link_alias'] = $data['join_link_name'];
3405 3405
                     }
3406 3406
                     else
3407 3407
                     {
3408
-                        $params['join_table_link_alias'] = 'jtl' . $jtcount;
3408
+                        $params['join_table_link_alias'] = 'jtl'.$jtcount;
3409 3409
                     }
3410 3410
                     $join_primary = !isset($data['join_primary']) || $data['join_primary'];
3411 3411
 
@@ -3418,126 +3418,126 @@  discard block
 block discarded – undo
3418 3418
 					global $beanFiles, $beanList;
3419 3419
                     // °3/21/2014 FIX NS-TEAM - Relationship fields could not be displayed in subpanels
3420 3420
                     //if($data['rname'] && !empty($beanFiles[$beanList[$rel_module]])) {
3421
-                    if(isset($data['rname']) && $data['rname'] == 'name' && !empty($beanFiles[$beanList[$rel_module]])) {
3421
+                    if (isset($data['rname']) && $data['rname'] == 'name' && !empty($beanFiles[$beanList[$rel_module]])) {
3422 3422
 
3423 3423
 						//create an instance of the related bean
3424 3424
 						require_once($beanFiles[$beanList[$rel_module]]);
3425 3425
 						$rel_mod = new $beanList[$rel_module]();
3426 3426
 						//if bean has first and last name fields, then name should be concatenated
3427
-						if(isset($rel_mod->field_name_map['first_name']) && isset($rel_mod->field_name_map['last_name'])){
3427
+						if (isset($rel_mod->field_name_map['first_name']) && isset($rel_mod->field_name_map['last_name'])) {
3428 3428
 								$data['db_concat_fields'] = array(0=>'first_name', 1=>'last_name');
3429 3429
 						}
3430 3430
 					}
3431 3431
 
3432 3432
 
3433
-    				if($join['type'] == 'many-to-many')
3433
+    				if ($join['type'] == 'many-to-many')
3434 3434
     				{
3435
-    					if(empty($ret_array['secondary_select']))
3435
+    					if (empty($ret_array['secondary_select']))
3436 3436
     					{
3437 3437
     						$ret_array['secondary_select'] = " SELECT $this->table_name.id ref_id  ";
3438 3438
 
3439
-                            if(!empty($beanFiles[$beanList[$rel_module]]) && $join_primary)
3439
+                            if (!empty($beanFiles[$beanList[$rel_module]]) && $join_primary)
3440 3440
                             {
3441 3441
                                 require_once($beanFiles[$beanList[$rel_module]]);
3442 3442
                                 $rel_mod = new $beanList[$rel_module]();
3443
-                                if(isset($rel_mod->field_defs['assigned_user_id']))
3443
+                                if (isset($rel_mod->field_defs['assigned_user_id']))
3444 3444
                                 {
3445
-                                    $ret_array['secondary_select'].= " , ".	$params['join_table_alias'] . ".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3445
+                                    $ret_array['secondary_select'] .= " , ".$params['join_table_alias'].".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3446 3446
                                 }
3447 3447
                                 else
3448 3448
                                 {
3449
-                                    if(isset($rel_mod->field_defs['created_by']))
3449
+                                    if (isset($rel_mod->field_defs['created_by']))
3450 3450
                                     {
3451
-                                        $ret_array['secondary_select'].= " , ".	$params['join_table_alias'] . ".created_by {$field}_owner , '$rel_module' {$field}_mod";
3451
+                                        $ret_array['secondary_select'] .= " , ".$params['join_table_alias'].".created_by {$field}_owner , '$rel_module' {$field}_mod";
3452 3452
                                     }
3453 3453
                                 }
3454 3454
                             }
3455 3455
                         }
3456 3456
 
3457
-                        if(isset($data['db_concat_fields']))
3457
+                        if (isset($data['db_concat_fields']))
3458 3458
                         {
3459
-                            $ret_array['secondary_select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3459
+                            $ret_array['secondary_select'] .= ' , '.$this->db->concat($params['join_table_alias'], $data['db_concat_fields']).' '.$field;
3460 3460
                         }
3461 3461
                         else
3462 3462
                         {
3463
-                            if(!isset($data['relationship_fields']))
3463
+                            if (!isset($data['relationship_fields']))
3464 3464
                             {
3465
-                                $ret_array['secondary_select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3465
+                                $ret_array['secondary_select'] .= ' , '.$params['join_table_alias'].'.'.$data['rname'].' '.$field;
3466 3466
                             }
3467 3467
                         }
3468
-                        if(!$singleSelect)
3468
+                        if (!$singleSelect)
3469 3469
                         {
3470 3470
                             $ret_array['select'] .= ", '                                                                                                                                                                                                                                                              ' $field ";
3471 3471
                         }
3472
-                        $count_used =0;
3473
-                        foreach($used_join_key as $used_key) {
3474
-                            if($used_key == $join['rel_key']) $count_used++;
3472
+                        $count_used = 0;
3473
+                        foreach ($used_join_key as $used_key) {
3474
+                            if ($used_key == $join['rel_key']) $count_used++;
3475 3475
                         }
3476
-                        if($count_used <= 1) {//27416, the $ret_array['secondary_select'] should always generate, regardless the dbtype
3476
+                        if ($count_used <= 1) {//27416, the $ret_array['secondary_select'] should always generate, regardless the dbtype
3477 3477
                             // add rel_key only if it was not aready added
3478
-                            if(!$singleSelect)
3478
+                            if (!$singleSelect)
3479 3479
                             {
3480
-                                $ret_array['select'] .= ", '                                    '  " . $join['rel_key'] . ' ';
3480
+                                $ret_array['select'] .= ", '                                    '  ".$join['rel_key'].' ';
3481 3481
                             }
3482
-                            $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $join['rel_key'] .' ' . $join['rel_key'];
3482
+                            $ret_array['secondary_select'] .= ', '.$params['join_table_link_alias'].'.'.$join['rel_key'].' '.$join['rel_key'];
3483 3483
                         }
3484
-                        if(isset($data['relationship_fields']))
3484
+                        if (isset($data['relationship_fields']))
3485 3485
                         {
3486
-                            foreach($data['relationship_fields'] as $r_name=>$alias_name)
3486
+                            foreach ($data['relationship_fields'] as $r_name=>$alias_name)
3487 3487
                             {
3488
-                                if(!empty( $secondarySelectedFields[$alias_name]))continue;
3489
-                                $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $r_name .' ' . $alias_name;
3488
+                                if (!empty($secondarySelectedFields[$alias_name]))continue;
3489
+                                $ret_array['secondary_select'] .= ', '.$params['join_table_link_alias'].'.'.$r_name.' '.$alias_name;
3490 3490
                                 $secondarySelectedFields[$alias_name] = true;
3491 3491
                             }
3492 3492
                         }
3493
-                        if(!$table_joined)
3493
+                        if (!$table_joined)
3494 3494
                         {
3495
-                            $ret_array['secondary_from'] .= ' ' . $join['join']. ' AND ' . $params['join_table_alias'].'.deleted=0';
3495
+                            $ret_array['secondary_from'] .= ' '.$join['join'].' AND '.$params['join_table_alias'].'.deleted=0';
3496 3496
                             if (isset($data['link_type']) && $data['link_type'] == 'relationship_info' && ($parentbean instanceOf SugarBean))
3497 3497
                             {
3498
-                                $ret_array['secondary_where'] = $params['join_table_link_alias'] . '.' . $join['rel_key']. "='" .$parentbean->id . "'";
3498
+                                $ret_array['secondary_where'] = $params['join_table_link_alias'].'.'.$join['rel_key']."='".$parentbean->id."'";
3499 3499
                             }
3500 3500
                         }
3501 3501
                     }
3502 3502
                     else
3503 3503
                     {
3504
-                        if(isset($data['db_concat_fields']))
3504
+                        if (isset($data['db_concat_fields']))
3505 3505
                         {
3506
-                            $ret_array['select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3506
+                            $ret_array['select'] .= ' , '.$this->db->concat($params['join_table_alias'], $data['db_concat_fields']).' '.$field;
3507 3507
                         }
3508 3508
                         else
3509 3509
                         {
3510
-                            $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3510
+                            $ret_array['select'] .= ' , '.$params['join_table_alias'].'.'.$data['rname'].' '.$field;
3511 3511
                         }
3512
-                        if(isset($data['additionalFields'])){
3513
-                            foreach($data['additionalFields'] as $k=>$v){
3512
+                        if (isset($data['additionalFields'])) {
3513
+                            foreach ($data['additionalFields'] as $k=>$v) {
3514 3514
                                 if (!empty($data['id_name']) && $data['id_name'] == $v && !empty($fields[$data['id_name']])) {
3515 3515
                                     continue;
3516 3516
                                 }
3517
-                                $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $k . ' ' . $v;
3517
+                                $ret_array['select'] .= ' , '.$params['join_table_alias'].'.'.$k.' '.$v;
3518 3518
                             }
3519 3519
                         }
3520
-                        if(!$table_joined)
3520
+                        if (!$table_joined)
3521 3521
                         {
3522
-                            $ret_array['from'] .= ' ' . $join['join']. ' AND ' . $params['join_table_alias'].'.deleted=0';
3523
-                            if(!empty($beanList[$rel_module]) && !empty($beanFiles[$beanList[$rel_module]]))
3522
+                            $ret_array['from'] .= ' '.$join['join'].' AND '.$params['join_table_alias'].'.deleted=0';
3523
+                            if (!empty($beanList[$rel_module]) && !empty($beanFiles[$beanList[$rel_module]]))
3524 3524
                             {
3525 3525
                                 require_once($beanFiles[$beanList[$rel_module]]);
3526 3526
                                 $rel_mod = new $beanList[$rel_module]();
3527
-                                if(isset($value['target_record_key']) && !empty($filter))
3527
+                                if (isset($value['target_record_key']) && !empty($filter))
3528 3528
                                 {
3529 3529
                                     $selectedFields[$this->table_name.'.'.$value['target_record_key']] = true;
3530 3530
                                     $ret_array['select'] .= " , $this->table_name.{$value['target_record_key']} ";
3531 3531
                                 }
3532
-                                if(isset($rel_mod->field_defs['assigned_user_id']))
3532
+                                if (isset($rel_mod->field_defs['assigned_user_id']))
3533 3533
                                 {
3534
-                                    $ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.assigned_user_id ' .  $field . '_owner';
3534
+                                    $ret_array['select'] .= ' , '.$params['join_table_alias'].'.assigned_user_id '.$field.'_owner';
3535 3535
                                 }
3536 3536
                                 else
3537 3537
                                 {
3538
-                                    $ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.created_by ' .  $field . '_owner';
3538
+                                    $ret_array['select'] .= ' , '.$params['join_table_alias'].'.created_by '.$field.'_owner';
3539 3539
                                 }
3540
-                                $ret_array['select'] .= "  , '".$rel_module  ."' " .  $field . '_mod';
3540
+                                $ret_array['select'] .= "  , '".$rel_module."' ".$field.'_mod';
3541 3541
 
3542 3542
                             }
3543 3543
                         }
@@ -3545,65 +3545,65 @@  discard block
 block discarded – undo
3545 3545
                     // To fix SOAP stuff where we are trying to retrieve all the accounts data where accounts.id = ..
3546 3546
                     // and this code changes accounts to jt4 as there is a self join with the accounts table.
3547 3547
                     //Martin fix #27494
3548
-                    if(isset($data['db_concat_fields'])){
3548
+                    if (isset($data['db_concat_fields'])) {
3549 3549
                     	$buildWhere = false;
3550
-                        if(in_array('first_name', $data['db_concat_fields']) && in_array('last_name', $data['db_concat_fields']))
3550
+                        if (in_array('first_name', $data['db_concat_fields']) && in_array('last_name', $data['db_concat_fields']))
3551 3551
                     	{
3552 3552
                      	   $exp = '/\(\s*?'.$data['name'].'.*?\%\'\s*?\)/';
3553
-                    	   if(preg_match($exp, $where, $matches))
3553
+                    	   if (preg_match($exp, $where, $matches))
3554 3554
                     	   {
3555 3555
                     	   	  $search_expression = $matches[0];
3556 3556
                     	   	  //Create three search conditions - first + last, first, last
3557
-                    	   	  $first_name_search = str_replace($data['name'], $params['join_table_alias'] . '.first_name', $search_expression);
3558
-                    	   	  $last_name_search = str_replace($data['name'], $params['join_table_alias'] . '.last_name', $search_expression);
3557
+                    	   	  $first_name_search = str_replace($data['name'], $params['join_table_alias'].'.first_name', $search_expression);
3558
+                    	   	  $last_name_search = str_replace($data['name'], $params['join_table_alias'].'.last_name', $search_expression);
3559 3559
 							  $full_name_search = str_replace($data['name'], $this->db->concat($params['join_table_alias'], $data['db_concat_fields']), $search_expression);
3560 3560
 							  $buildWhere = true;
3561
-							  $where = str_replace($search_expression, '(' . $full_name_search . ' OR ' . $first_name_search . ' OR ' . $last_name_search . ')', $where);
3561
+							  $where = str_replace($search_expression, '('.$full_name_search.' OR '.$first_name_search.' OR '.$last_name_search.')', $where);
3562 3562
                     	   }
3563 3563
                     	}
3564 3564
 
3565
-                    	if(!$buildWhere)
3565
+                    	if (!$buildWhere)
3566 3566
                     	{
3567 3567
 	                       $db_field = $this->db->concat($params['join_table_alias'], $data['db_concat_fields']);
3568 3568
 	                       $where = preg_replace('/'.$data['name'].'/', $db_field, $where);
3569 3569
 
3570 3570
 				// For relationship fields replace their alias by the corresponsding link table and r_name
3571
-				if(isset($data['relationship_fields']))
3572
-					foreach($data['relationship_fields'] as $r_name=>$alias_name)
3571
+				if (isset($data['relationship_fields']))
3572
+					foreach ($data['relationship_fields'] as $r_name=>$alias_name)
3573 3573
 					{
3574 3574
 						$db_field = $this->db->concat($params['join_table_link_alias'], $r_name);
3575
-						$where = preg_replace('/' . $alias_name . '/', $db_field, $where);
3575
+						$where = preg_replace('/'.$alias_name.'/', $db_field, $where);
3576 3576
 					}
3577 3577
                     	}
3578
-                    }else{
3579
-                        $where = preg_replace('/(^|[\s(])' . $data['name'] . '/', '${1}' . $params['join_table_alias'] . '.'.$data['rname'], $where);
3578
+                    } else {
3579
+                        $where = preg_replace('/(^|[\s(])'.$data['name'].'/', '${1}'.$params['join_table_alias'].'.'.$data['rname'], $where);
3580 3580
 
3581 3581
 			// For relationship fields replace their alias by the corresponsding link table and r_name
3582
-			if(isset($data['relationship_fields']))
3583
-				foreach($data['relationship_fields'] as $r_name=>$alias_name)
3584
-					$where = preg_replace('/(^|[\s(])' . $alias_name . '/', '${1}' . $params['join_table_link_alias'] . '.'.$r_name, $where);
3582
+			if (isset($data['relationship_fields']))
3583
+				foreach ($data['relationship_fields'] as $r_name=>$alias_name)
3584
+					$where = preg_replace('/(^|[\s(])'.$alias_name.'/', '${1}'.$params['join_table_link_alias'].'.'.$r_name, $where);
3585 3585
                     }
3586
-                    if(!$table_joined)
3586
+                    if (!$table_joined)
3587 3587
                     {
3588
-                        $joined_tables[$params['join_table_alias']]=1;
3589
-                        $joined_tables[$params['join_table_link_alias']]=1;
3588
+                        $joined_tables[$params['join_table_alias']] = 1;
3589
+                        $joined_tables[$params['join_table_link_alias']] = 1;
3590 3590
                     }
3591 3591
 
3592 3592
                     $jtcount++;
3593 3593
                 }
3594 3594
             }
3595 3595
         }
3596
-        if(!empty($filter))
3596
+        if (!empty($filter))
3597 3597
         {
3598
-            if(isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id']))
3598
+            if (isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id']))
3599 3599
             {
3600 3600
                 $ret_array['select'] .= ", $this->table_name.assigned_user_id ";
3601 3601
             }
3602
-            else if(isset($this->field_defs['created_by']) &&  empty($selectedFields[$this->table_name.'.created_by']))
3602
+            else if (isset($this->field_defs['created_by']) && empty($selectedFields[$this->table_name.'.created_by']))
3603 3603
             {
3604 3604
                 $ret_array['select'] .= ", $this->table_name.created_by ";
3605 3605
             }
3606
-            if(isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name.'.system_id']))
3606
+            if (isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name.'.system_id']))
3607 3607
             {
3608 3608
                 $ret_array['select'] .= ", $this->table_name.system_id ";
3609 3609
             }
@@ -3611,21 +3611,21 @@  discard block
 block discarded – undo
3611 3611
         }
3612 3612
 
3613 3613
 	if ($ifListForExport) {
3614
-		if(isset($this->field_defs['email1'])) {
3615
-			$ret_array['select'].= " ,email_addresses.email_address email1";
3616
-			$ret_array['from'].= " LEFT JOIN email_addr_bean_rel on {$this->table_name}.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='{$this->module_dir}' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ";
3614
+		if (isset($this->field_defs['email1'])) {
3615
+			$ret_array['select'] .= " ,email_addresses.email_address email1";
3616
+			$ret_array['from'] .= " LEFT JOIN email_addr_bean_rel on {$this->table_name}.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module='{$this->module_dir}' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ";
3617 3617
 		}
3618 3618
 	}
3619 3619
 
3620 3620
         $where_auto = '1=1';
3621
-        if($show_deleted == 0)
3621
+        if ($show_deleted == 0)
3622 3622
         {
3623 3623
             $where_auto = "$this->table_name.deleted=0";
3624
-        }else if($show_deleted == 1)
3624
+        } else if ($show_deleted == 1)
3625 3625
         {
3626 3626
             $where_auto = "$this->table_name.deleted=1";
3627 3627
         }
3628
-        if($where != "")
3628
+        if ($where != "")
3629 3629
             $ret_array['where'] = " where ($where) AND $where_auto";
3630 3630
         else
3631 3631
             $ret_array['where'] = " where $where_auto";
@@ -3633,21 +3633,21 @@  discard block
 block discarded – undo
3633 3633
         //make call to process the order by clause
3634 3634
         $order_by = $this->process_order_by($order_by);
3635 3635
         if (!empty($order_by)) {
3636
-            $ret_array['order_by'] = " ORDER BY " . $order_by;
3636
+            $ret_array['order_by'] = " ORDER BY ".$order_by;
3637 3637
         }
3638
-        if($singleSelect)
3638
+        if ($singleSelect)
3639 3639
         {
3640 3640
             unset($ret_array['secondary_where']);
3641 3641
             unset($ret_array['secondary_from']);
3642 3642
             unset($ret_array['secondary_select']);
3643 3643
         }
3644 3644
 
3645
-        if($return_array)
3645
+        if ($return_array)
3646 3646
         {
3647 3647
             return $ret_array;
3648 3648
         }
3649 3649
 
3650
-        return  $ret_array['select'] . $ret_array['from'] . $ret_array['where']. $ret_array['order_by'];
3650
+        return  $ret_array['select'].$ret_array['from'].$ret_array['where'].$ret_array['order_by'];
3651 3651
     }
3652 3652
 
3653 3653
 	// Check if field is defined through a relationship_info field, add this field when not present 
@@ -3656,7 +3656,7 @@  discard block
 block discarded – undo
3656 3656
 		foreach ($this->field_defs as $field_def => $value)
3657 3657
 		{
3658 3658
 			if (isset($value['relationship_fields']) && 
3659
-				in_array($field, $value['relationship_fields']) )
3659
+				in_array($field, $value['relationship_fields']))
3660 3660
 				return $field_def;
3661 3661
 		}
3662 3662
 
@@ -3676,13 +3676,13 @@  discard block
 block discarded – undo
3676 3676
         global $beanList, $beanFiles;
3677 3677
         $templates = array();
3678 3678
         $parent_child_map = array();
3679
-        foreach($type_info as $children_info)
3679
+        foreach ($type_info as $children_info)
3680 3680
         {
3681
-            foreach($children_info as $child_info)
3681
+            foreach ($children_info as $child_info)
3682 3682
             {
3683
-                if($child_info['type'] == 'parent')
3683
+                if ($child_info['type'] == 'parent')
3684 3684
                 {
3685
-                    if(empty($templates[$child_info['parent_type']]))
3685
+                    if (empty($templates[$child_info['parent_type']]))
3686 3686
                     {
3687 3687
                         //Test emails will have an invalid parent_type, don't try to load the non-existent parent bean
3688 3688
                         if ($child_info['parent_type'] == 'test') {
@@ -3690,7 +3690,7 @@  discard block
 block discarded – undo
3690 3690
                         }
3691 3691
                         $class = $beanList[$child_info['parent_type']];
3692 3692
                         // Added to avoid error below; just silently fail and write message to log
3693
-                        if ( empty($beanFiles[$class]) ) {
3693
+                        if (empty($beanFiles[$class])) {
3694 3694
                             $GLOBALS['log']->error($this->object_name.'::retrieve_parent_fields() - cannot load class "'.$class.'", skip loading.');
3695 3695
                             continue;
3696 3696
                         }
@@ -3698,30 +3698,30 @@  discard block
 block discarded – undo
3698 3698
                         $templates[$child_info['parent_type']] = new $class();
3699 3699
                     }
3700 3700
 
3701
-                    if(empty($queries[$child_info['parent_type']]))
3701
+                    if (empty($queries[$child_info['parent_type']]))
3702 3702
                     {
3703 3703
                         $queries[$child_info['parent_type']] = "SELECT id ";
3704 3704
                         $field_def = $templates[$child_info['parent_type']]->field_defs['name'];
3705
-                        if(isset($field_def['db_concat_fields']))
3705
+                        if (isset($field_def['db_concat_fields']))
3706 3706
                         {
3707
-                            $queries[$child_info['parent_type']] .= ' , ' . $this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']) . ' parent_name';
3707
+                            $queries[$child_info['parent_type']] .= ' , '.$this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']).' parent_name';
3708 3708
                         }
3709 3709
                         else
3710 3710
                         {
3711 3711
                             $queries[$child_info['parent_type']] .= ' , name parent_name';
3712 3712
                         }
3713
-                        if(isset($templates[$child_info['parent_type']]->field_defs['assigned_user_id']))
3713
+                        if (isset($templates[$child_info['parent_type']]->field_defs['assigned_user_id']))
3714 3714
                         {
3715
-                            $queries[$child_info['parent_type']] .= ", assigned_user_id parent_name_owner , '{$child_info['parent_type']}' parent_name_mod";;
3716
-                        }else if(isset($templates[$child_info['parent_type']]->field_defs['created_by']))
3715
+                            $queries[$child_info['parent_type']] .= ", assigned_user_id parent_name_owner , '{$child_info['parent_type']}' parent_name_mod"; ;
3716
+                        } else if (isset($templates[$child_info['parent_type']]->field_defs['created_by']))
3717 3717
                         {
3718 3718
                             $queries[$child_info['parent_type']] .= ", created_by parent_name_owner, '{$child_info['parent_type']}' parent_name_mod";
3719 3719
                         }
3720
-                        $queries[$child_info['parent_type']] .= " FROM " . $templates[$child_info['parent_type']]->table_name ." WHERE id IN ('{$child_info['parent_id']}'";
3720
+                        $queries[$child_info['parent_type']] .= " FROM ".$templates[$child_info['parent_type']]->table_name." WHERE id IN ('{$child_info['parent_id']}'";
3721 3721
                     }
3722 3722
                     else
3723 3723
                     {
3724
-                        if(empty($parent_child_map[$child_info['parent_id']]))
3724
+                        if (empty($parent_child_map[$child_info['parent_id']]))
3725 3725
                         $queries[$child_info['parent_type']] .= " ,'{$child_info['parent_id']}'";
3726 3726
                     }
3727 3727
                     $parent_child_map[$child_info['parent_id']][] = $child_info['child_id'];
@@ -3729,21 +3729,21 @@  discard block
 block discarded – undo
3729 3729
             }
3730 3730
         }
3731 3731
         $results = array();
3732
-        foreach($queries as $query)
3732
+        foreach ($queries as $query)
3733 3733
         {
3734
-            $result = $this->db->query($query . ')');
3735
-            while($row = $this->db->fetchByAssoc($result))
3734
+            $result = $this->db->query($query.')');
3735
+            while ($row = $this->db->fetchByAssoc($result))
3736 3736
             {
3737 3737
                 $results[$row['id']] = $row;
3738 3738
             }
3739 3739
         }
3740 3740
 
3741 3741
         $child_results = array();
3742
-        foreach($parent_child_map as $parent_key=>$parent_child)
3742
+        foreach ($parent_child_map as $parent_key=>$parent_child)
3743 3743
         {
3744
-            foreach($parent_child as $child)
3744
+            foreach ($parent_child as $child)
3745 3745
             {
3746
-                if(isset( $results[$parent_key]))
3746
+                if (isset($results[$parent_key]))
3747 3747
                 {
3748 3748
                     $child_results[$child] = $results[$parent_key];
3749 3749
                 }
@@ -3763,7 +3763,7 @@  discard block
 block discarded – undo
3763 3763
      * @param string $where Optional, additional filter criteria.
3764 3764
      * @return array Fetched data
3765 3765
      */
3766
-    function process_list_query($query, $row_offset, $limit= -1, $max_per_page = -1, $where = '')
3766
+    function process_list_query($query, $row_offset, $limit = -1, $max_per_page = -1, $where = '')
3767 3767
     {
3768 3768
         global $sugar_config;
3769 3769
         $db = DBManagerFactory::getInstance('listviews');
@@ -3772,33 +3772,33 @@  discard block
 block discarded – undo
3772 3772
         */
3773 3773
         $toEnd = strval($row_offset) == 'end';
3774 3774
         $GLOBALS['log']->debug("process_list_query: ".$query);
3775
-        if($max_per_page == -1)
3775
+        if ($max_per_page == -1)
3776 3776
         {
3777
-            $max_per_page 	= $sugar_config['list_max_entries_per_page'];
3777
+            $max_per_page = $sugar_config['list_max_entries_per_page'];
3778 3778
         }
3779 3779
         // Check to see if we have a count query available.
3780
-        if(empty($sugar_config['disable_count_query']) || $toEnd)
3780
+        if (empty($sugar_config['disable_count_query']) || $toEnd)
3781 3781
         {
3782 3782
             $count_query = $this->create_list_count_query($query);
3783
-            if(!empty($count_query) && (empty($limit) || $limit == -1))
3783
+            if (!empty($count_query) && (empty($limit) || $limit == -1))
3784 3784
             {
3785 3785
                 // We have a count query.  Run it and get the results.
3786 3786
                 $result = $db->query($count_query, true, "Error running count query for $this->object_name List: ");
3787 3787
                 $assoc = $db->fetchByAssoc($result);
3788
-                if(!empty($assoc['c']))
3788
+                if (!empty($assoc['c']))
3789 3789
                 {
3790 3790
                     $rows_found = $assoc['c'];
3791 3791
                     $limit = $sugar_config['list_max_entries_per_page'];
3792 3792
                 }
3793
-                if( $toEnd)
3793
+                if ($toEnd)
3794 3794
                 {
3795
-                    $row_offset = (floor(($rows_found -1) / $limit)) * $limit;
3795
+                    $row_offset = (floor(($rows_found - 1) / $limit)) * $limit;
3796 3796
                 }
3797 3797
             }
3798 3798
         }
3799 3799
         else
3800 3800
         {
3801
-            if((empty($limit) || $limit == -1))
3801
+            if ((empty($limit) || $limit == -1))
3802 3802
             {
3803 3803
                 $limit = $max_per_page + 1;
3804 3804
                 $max_per_page = $limit;
@@ -3806,17 +3806,17 @@  discard block
 block discarded – undo
3806 3806
 
3807 3807
         }
3808 3808
 
3809
-        if(empty($row_offset))
3809
+        if (empty($row_offset))
3810 3810
         {
3811 3811
             $row_offset = 0;
3812 3812
         }
3813
-        if(!empty($limit) && $limit != -1 && $limit != -99)
3813
+        if (!empty($limit) && $limit != -1 && $limit != -99)
3814 3814
         {
3815
-            $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $this->object_name list: ");
3815
+            $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $this->object_name list: ");
3816 3816
         }
3817 3817
         else
3818 3818
         {
3819
-            $result = $db->query($query,true,"Error retrieving $this->object_name list: ");
3819
+            $result = $db->query($query, true, "Error retrieving $this->object_name list: ");
3820 3820
         }
3821 3821
 
3822 3822
         $list = Array();
@@ -3839,21 +3839,21 @@  discard block
 block discarded – undo
3839 3839
                 /** @var SugarBean $temp */
3840 3840
                 $temp = new $class();
3841 3841
 
3842
-                foreach($this->field_defs as $field=>$value)
3842
+                foreach ($this->field_defs as $field=>$value)
3843 3843
                 {
3844 3844
                     if (isset($row[$field]))
3845 3845
                     {
3846 3846
                         $temp->$field = $row[$field];
3847
-                        $owner_field = $field . '_owner';
3848
-                        if(isset($row[$owner_field]))
3847
+                        $owner_field = $field.'_owner';
3848
+                        if (isset($row[$owner_field]))
3849 3849
                         {
3850 3850
                             $temp->$owner_field = $row[$owner_field];
3851 3851
                         }
3852 3852
 
3853 3853
                         $GLOBALS['log']->debug("$temp->object_name({$row['id']}): ".$field." = ".$temp->$field);
3854
-                    }else if (isset($row[$this->table_name .'.'.$field]))
3854
+                    } else if (isset($row[$this->table_name.'.'.$field]))
3855 3855
                     {
3856
-                        $temp->$field = $row[$this->table_name .'.'.$field];
3856
+                        $temp->$field = $row[$this->table_name.'.'.$field];
3857 3857
                     }
3858 3858
                     else
3859 3859
                     {
@@ -3863,7 +3863,7 @@  discard block
 block discarded – undo
3863 3863
 
3864 3864
                 $temp->check_date_relationships_load();
3865 3865
                 $temp->fill_in_additional_list_fields();
3866
-                if($temp->hasCustomFields()) $temp->custom_fields->fill_relationships();
3866
+                if ($temp->hasCustomFields()) $temp->custom_fields->fill_relationships();
3867 3867
                 $temp->call_custom_logic("process_record");
3868 3868
 
3869 3869
                 // fix defect #44206. implement the same logic as sugar_currency_format
@@ -3873,17 +3873,17 @@  discard block
 block discarded – undo
3873 3873
 
3874 3874
                 $index++;
3875 3875
             }
3876
-        if(!empty($sugar_config['disable_count_query']) && !empty($limit))
3876
+        if (!empty($sugar_config['disable_count_query']) && !empty($limit))
3877 3877
         {
3878 3878
 
3879 3879
             $rows_found = $row_offset + count($list);
3880 3880
 
3881
-            if(!$toEnd)
3881
+            if (!$toEnd)
3882 3882
             {
3883 3883
                 $next_offset--;
3884 3884
                 $previous_offset++;
3885 3885
             }
3886
-        } else if(!isset($rows_found)){
3886
+        } else if (!isset($rows_found)) {
3887 3887
             $rows_found = $row_offset + count($list);
3888 3888
         }
3889 3889
 
@@ -3892,7 +3892,7 @@  discard block
 block discarded – undo
3892 3892
         $response['row_count'] = $rows_found;
3893 3893
         $response['next_offset'] = $next_offset;
3894 3894
         $response['previous_offset'] = $previous_offset;
3895
-        $response['current_offset'] = $row_offset ;
3895
+        $response['current_offset'] = $row_offset;
3896 3896
         return $response;
3897 3897
     }
3898 3898
 
@@ -3904,18 +3904,18 @@  discard block
 block discarded – undo
3904 3904
      * @param boolean $is_count_query Optional, Default false, set to true if passed query is a count query.
3905 3905
      * @return int count of rows found
3906 3906
     */
3907
-    function _get_num_rows_in_query($query, $is_count_query=false)
3907
+    function _get_num_rows_in_query($query, $is_count_query = false)
3908 3908
     {
3909 3909
         $num_rows_in_query = 0;
3910 3910
         if (!$is_count_query)
3911 3911
         {
3912 3912
             $count_query = SugarBean::create_list_count_query($query);
3913 3913
         } else
3914
-            $count_query=$query;
3914
+            $count_query = $query;
3915 3915
 
3916 3916
         $result = $this->db->query($count_query, true, "Error running count query for $this->object_name List: ");
3917 3917
         $row_num = 0;
3918
-        while($row = $this->db->fetchByAssoc($result, true))
3918
+        while ($row = $this->db->fetchByAssoc($result, true))
3919 3919
         {
3920 3920
             $num_rows_in_query += current($row);
3921 3921
         }
@@ -3940,7 +3940,7 @@  discard block
 block discarded – undo
3940 3940
      * @return array Fetched data.
3941 3941
      */
3942 3942
     function process_union_list_query($parent_bean, $query,
3943
-    $row_offset, $limit= -1, $max_per_page = -1, $where = '', $subpanel_def, $query_row_count='', $secondary_queries = array())
3943
+    $row_offset, $limit = -1, $max_per_page = -1, $where = '', $subpanel_def, $query_row_count = '', $secondary_queries = array())
3944 3944
 
3945 3945
     {
3946 3946
         $db = DBManagerFactory::getInstance('listviews');
@@ -3949,52 +3949,52 @@  discard block
 block discarded – undo
3949 3949
         */
3950 3950
         $toEnd = strval($row_offset) == 'end';
3951 3951
         global $sugar_config;
3952
-        $use_count_query=false;
3953
-        $processing_collection=$subpanel_def->isCollection();
3952
+        $use_count_query = false;
3953
+        $processing_collection = $subpanel_def->isCollection();
3954 3954
 
3955 3955
         $GLOBALS['log']->debug("process_union_list_query: ".$query);
3956
-        if($max_per_page == -1)
3956
+        if ($max_per_page == -1)
3957 3957
         {
3958
-            $max_per_page 	= $sugar_config['list_max_entries_per_subpanel'];
3958
+            $max_per_page = $sugar_config['list_max_entries_per_subpanel'];
3959 3959
         }
3960
-        if(empty($query_row_count))
3960
+        if (empty($query_row_count))
3961 3961
         {
3962 3962
             $query_row_count = $query;
3963 3963
         }
3964
-        $distinct_position=strpos($query_row_count,"DISTINCT");
3964
+        $distinct_position = strpos($query_row_count, "DISTINCT");
3965 3965
 
3966
-        if ($distinct_position!= false)
3966
+        if ($distinct_position != false)
3967 3967
         {
3968
-            $use_count_query=true;
3968
+            $use_count_query = true;
3969 3969
         }
3970 3970
         $performSecondQuery = true;
3971
-        if(empty($sugar_config['disable_count_query']) || $toEnd)
3971
+        if (empty($sugar_config['disable_count_query']) || $toEnd)
3972 3972
         {
3973
-            $rows_found = $this->_get_num_rows_in_query($query_row_count,$use_count_query);
3974
-            if($rows_found < 1)
3973
+            $rows_found = $this->_get_num_rows_in_query($query_row_count, $use_count_query);
3974
+            if ($rows_found < 1)
3975 3975
             {
3976 3976
                 $performSecondQuery = false;
3977 3977
             }
3978
-            if(!empty($rows_found) && (empty($limit) || $limit == -1))
3978
+            if (!empty($rows_found) && (empty($limit) || $limit == -1))
3979 3979
             {
3980 3980
                 $limit = $sugar_config['list_max_entries_per_subpanel'];
3981 3981
             }
3982
-            if( $toEnd)
3982
+            if ($toEnd)
3983 3983
             {
3984
-                $row_offset = (floor(($rows_found -1) / $limit)) * $limit;
3984
+                $row_offset = (floor(($rows_found - 1) / $limit)) * $limit;
3985 3985
 
3986 3986
             }
3987 3987
         }
3988 3988
         else
3989 3989
         {
3990
-            if((empty($limit) || $limit == -1))
3990
+            if ((empty($limit) || $limit == -1))
3991 3991
             {
3992 3992
                 $limit = $max_per_page + 1;
3993 3993
                 $max_per_page = $limit;
3994 3994
             }
3995 3995
         }
3996 3996
 
3997
-        if(empty($row_offset))
3997
+        if (empty($row_offset))
3998 3998
         {
3999 3999
             $row_offset = 0;
4000 4000
         }
@@ -4002,15 +4002,15 @@  discard block
 block discarded – undo
4002 4002
         $previous_offset = $row_offset - $max_per_page;
4003 4003
         $next_offset = $row_offset + $max_per_page;
4004 4004
 
4005
-        if($performSecondQuery)
4005
+        if ($performSecondQuery)
4006 4006
         {
4007
-            if(!empty($limit) && $limit != -1 && $limit != -99)
4007
+            if (!empty($limit) && $limit != -1 && $limit != -99)
4008 4008
             {
4009
-                $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $parent_bean->object_name list: ");
4009
+                $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $parent_bean->object_name list: ");
4010 4010
             }
4011 4011
             else
4012 4012
             {
4013
-                $result = $db->query($query,true,"Error retrieving $this->object_name list: ");
4013
+                $result = $db->query($query, true, "Error retrieving $this->object_name list: ");
4014 4014
             }
4015 4015
                 //use -99 to return all
4016 4016
 
@@ -4020,22 +4020,22 @@  discard block
 block discarded – undo
4020 4020
 
4021 4021
                 $post_retrieve = array();
4022 4022
                 $isFirstTime = true;
4023
-                while($row)
4023
+                while ($row)
4024 4024
                 {
4025 4025
                     $function_fields = array();
4026
-                    if(($index < $row_offset + $max_per_page || $max_per_page == -99))
4026
+                    if (($index < $row_offset + $max_per_page || $max_per_page == -99))
4027 4027
                     {
4028 4028
                         if ($processing_collection)
4029 4029
                         {
4030
-                            $current_bean =$subpanel_def->sub_subpanels[$row['panel_name']]->template_instance;
4031
-                            if(!$isFirstTime)
4030
+                            $current_bean = $subpanel_def->sub_subpanels[$row['panel_name']]->template_instance;
4031
+                            if (!$isFirstTime)
4032 4032
                             {
4033 4033
                                 $class = get_class($subpanel_def->sub_subpanels[$row['panel_name']]->template_instance);
4034 4034
                                 $current_bean = new $class();
4035 4035
                             }
4036 4036
                         } else {
4037
-                            $current_bean=$subpanel_def->template_instance;
4038
-                            if(!$isFirstTime)
4037
+                            $current_bean = $subpanel_def->template_instance;
4038
+                            if (!$isFirstTime)
4039 4039
                             {
4040 4040
                                 $class = get_class($subpanel_def->template_instance);
4041 4041
                                 $current_bean = new $class();
@@ -4045,9 +4045,9 @@  discard block
 block discarded – undo
4045 4045
                         //set the panel name in the bean instance.
4046 4046
                         if (isset($row['panel_name']))
4047 4047
                         {
4048
-                            $current_bean->panel_name=$row['panel_name'];
4048
+                            $current_bean->panel_name = $row['panel_name'];
4049 4049
                         }
4050
-                        foreach($current_bean->field_defs as $field=>$value)
4050
+                        foreach ($current_bean->field_defs as $field=>$value)
4051 4051
                         {
4052 4052
 
4053 4053
                             if (isset($row[$field]))
@@ -4055,60 +4055,60 @@  discard block
 block discarded – undo
4055 4055
                                 $current_bean->$field = $this->convertField($row[$field], $value);
4056 4056
                                 unset($row[$field]);
4057 4057
                             }
4058
-                            else if (isset($row[$this->table_name .'.'.$field]))
4058
+                            else if (isset($row[$this->table_name.'.'.$field]))
4059 4059
                             {
4060
-                                $current_bean->$field = $this->convertField($row[$this->table_name .'.'.$field], $value);
4061
-                                unset($row[$this->table_name .'.'.$field]);
4060
+                                $current_bean->$field = $this->convertField($row[$this->table_name.'.'.$field], $value);
4061
+                                unset($row[$this->table_name.'.'.$field]);
4062 4062
                             }
4063 4063
                             else
4064 4064
                             {
4065 4065
                                 $current_bean->$field = "";
4066 4066
                                 unset($row[$field]);
4067 4067
                             }
4068
-                            if(isset($value['source']) && $value['source'] == 'function')
4068
+                            if (isset($value['source']) && $value['source'] == 'function')
4069 4069
                             {
4070
-                                $function_fields[]=$field;
4070
+                                $function_fields[] = $field;
4071 4071
                             }
4072 4072
                         }
4073
-                        foreach($row as $key=>$value)
4073
+                        foreach ($row as $key=>$value)
4074 4074
                         {
4075 4075
                             $current_bean->$key = $value;
4076 4076
                         }
4077
-                        foreach($function_fields as $function_field)
4077
+                        foreach ($function_fields as $function_field)
4078 4078
                         {
4079 4079
                             $value = $current_bean->field_defs[$function_field];
4080 4080
                             $can_execute = true;
4081 4081
                             $execute_params = array();
4082 4082
                             $execute_function = array();
4083
-                            if(!empty($value['function_class']))
4083
+                            if (!empty($value['function_class']))
4084 4084
                             {
4085
-                                $execute_function[] = 	$value['function_class'];
4086
-                                $execute_function[] = 	$value['function_name'];
4085
+                                $execute_function[] = $value['function_class'];
4086
+                                $execute_function[] = $value['function_name'];
4087 4087
                             }
4088 4088
                             else
4089 4089
                             {
4090
-                                $execute_function	= $value['function_name'];
4090
+                                $execute_function = $value['function_name'];
4091 4091
                             }
4092
-                            foreach($value['function_params'] as $param )
4092
+                            foreach ($value['function_params'] as $param)
4093 4093
                             {
4094
-                                if (empty($value['function_params_source']) or $value['function_params_source']=='parent')
4094
+                                if (empty($value['function_params_source']) or $value['function_params_source'] == 'parent')
4095 4095
                                 {
4096
-                                    if(empty($this->$param))
4096
+                                    if (empty($this->$param))
4097 4097
                                     {
4098 4098
                                         $can_execute = false;
4099
-                                    } else if($param == '$this') {
4099
+                                    } else if ($param == '$this') {
4100 4100
                                         $execute_params[] = $this;
4101 4101
                                     }
4102 4102
                                     else
4103 4103
                                     {
4104 4104
                                         $execute_params[] = $this->$param;
4105 4105
                                     }
4106
-                                } else if ($value['function_params_source']=='this')
4106
+                                } else if ($value['function_params_source'] == 'this')
4107 4107
                                 {
4108
-                                    if(empty($current_bean->$param))
4108
+                                    if (empty($current_bean->$param))
4109 4109
                                     {
4110 4110
                                         $can_execute = false;
4111
-                                    } else if($param == '$this') {
4111
+                                    } else if ($param == '$this') {
4112 4112
                                         $execute_params[] = $current_bean;
4113 4113
                                     }
4114 4114
                                     else
@@ -4122,18 +4122,18 @@  discard block
 block discarded – undo
4122 4122
                                 }
4123 4123
 
4124 4124
                             }
4125
-                            if($can_execute)
4125
+                            if ($can_execute)
4126 4126
                             {
4127
-                                if(!empty($value['function_require']))
4127
+                                if (!empty($value['function_require']))
4128 4128
                                 {
4129 4129
                                     require_once($value['function_require']);
4130 4130
                                 }
4131 4131
                                 $current_bean->$function_field = call_user_func_array($execute_function, $execute_params);
4132 4132
                             }
4133 4133
                         }
4134
-                        if(!empty($current_bean->parent_type) && !empty($current_bean->parent_id))
4134
+                        if (!empty($current_bean->parent_type) && !empty($current_bean->parent_id))
4135 4135
                         {
4136
-                            if(!isset($post_retrieve[$current_bean->parent_type]))
4136
+                            if (!isset($post_retrieve[$current_bean->parent_type]))
4137 4137
                             {
4138 4138
                                 $post_retrieve[$current_bean->parent_type] = array();
4139 4139
                             }
@@ -4147,22 +4147,22 @@  discard block
 block discarded – undo
4147 4147
                     $row = $db->fetchByAssoc($result);
4148 4148
                 }
4149 4149
             //now handle retrieving many-to-many relationships
4150
-            if(!empty($list))
4150
+            if (!empty($list))
4151 4151
             {
4152
-                foreach($secondary_queries as $query2)
4152
+                foreach ($secondary_queries as $query2)
4153 4153
                 {
4154 4154
                     $result2 = $db->query($query2);
4155 4155
 
4156 4156
                     $row2 = $db->fetchByAssoc($result2);
4157
-                    while($row2)
4157
+                    while ($row2)
4158 4158
                     {
4159 4159
                         $id_ref = $row2['ref_id'];
4160 4160
 
4161
-                        if(isset($list[$id_ref]))
4161
+                        if (isset($list[$id_ref]))
4162 4162
                         {
4163
-                            foreach($row2 as $r2key=>$r2value)
4163
+                            foreach ($row2 as $r2key=>$r2value)
4164 4164
                             {
4165
-                                if($r2key != 'ref_id')
4165
+                                if ($r2key != 'ref_id')
4166 4166
                                 {
4167 4167
                                     $list[$id_ref]->$r2key = $r2value;
4168 4168
                                 }
@@ -4174,7 +4174,7 @@  discard block
 block discarded – undo
4174 4174
 
4175 4175
             }
4176 4176
 
4177
-            if(isset($post_retrieve))
4177
+            if (isset($post_retrieve))
4178 4178
             {
4179 4179
                 $parent_fields = $this->retrieve_parent_fields($post_retrieve);
4180 4180
             }
@@ -4182,16 +4182,16 @@  discard block
 block discarded – undo
4182 4182
             {
4183 4183
                 $parent_fields = array();
4184 4184
             }
4185
-            if(!empty($sugar_config['disable_count_query']) && !empty($limit))
4185
+            if (!empty($sugar_config['disable_count_query']) && !empty($limit))
4186 4186
             {
4187 4187
             	//C.L. Bug 43535 - Use the $index value to set the $rows_found value here
4188 4188
                 $rows_found = isset($index) ? $index : $row_offset + count($list);
4189 4189
 
4190
-                if(count($list) >= $limit)
4190
+                if (count($list) >= $limit)
4191 4191
                 {
4192 4192
                     array_pop($list);
4193 4193
                 }
4194
-                if(!$toEnd)
4194
+                if (!$toEnd)
4195 4195
                 {
4196 4196
                     $next_offset--;
4197 4197
                     $previous_offset++;
@@ -4200,7 +4200,7 @@  discard block
 block discarded – undo
4200 4200
         }
4201 4201
         else
4202 4202
         {
4203
-            $row_found 	= 0;
4203
+            $row_found = 0;
4204 4204
             $parent_fields = array();
4205 4205
         }
4206 4206
         $response = array();
@@ -4209,7 +4209,7 @@  discard block
 block discarded – undo
4209 4209
         $response['row_count'] = $rows_found;
4210 4210
         $response['next_offset'] = $next_offset;
4211 4211
         $response['previous_offset'] = $previous_offset;
4212
-        $response['current_offset'] = $row_offset ;
4212
+        $response['current_offset'] = $row_offset;
4213 4213
         $response['query'] = $query;
4214 4214
 
4215 4215
         return $response;
@@ -4229,35 +4229,35 @@  discard block
 block discarded – undo
4229 4229
      * @return array Fetched data.
4230 4230
      *
4231 4231
      */
4232
-    function process_detail_query($query, $row_offset, $limit= -1, $max_per_page = -1, $where = '', $offset = 0)
4232
+    function process_detail_query($query, $row_offset, $limit = -1, $max_per_page = -1, $where = '', $offset = 0)
4233 4233
     {
4234 4234
         global $sugar_config;
4235 4235
         $GLOBALS['log']->debug("process_detail_query: ".$query);
4236
-        if($max_per_page == -1)
4236
+        if ($max_per_page == -1)
4237 4237
         {
4238
-            $max_per_page 	= $sugar_config['list_max_entries_per_page'];
4238
+            $max_per_page = $sugar_config['list_max_entries_per_page'];
4239 4239
         }
4240 4240
 
4241 4241
         // Check to see if we have a count query available.
4242 4242
         $count_query = $this->create_list_count_query($query);
4243 4243
 
4244
-        if(!empty($count_query) && (empty($limit) || $limit == -1))
4244
+        if (!empty($count_query) && (empty($limit) || $limit == -1))
4245 4245
         {
4246 4246
             // We have a count query.  Run it and get the results.
4247 4247
             $result = $this->db->query($count_query, true, "Error running count query for $this->object_name List: ");
4248 4248
             $assoc = $this->db->fetchByAssoc($result);
4249
-            if(!empty($assoc['c']))
4249
+            if (!empty($assoc['c']))
4250 4250
             {
4251 4251
                 $total_rows = $assoc['c'];
4252 4252
             }
4253 4253
         }
4254 4254
 
4255
-        if(empty($row_offset))
4255
+        if (empty($row_offset))
4256 4256
         {
4257 4257
             $row_offset = 0;
4258 4258
         }
4259 4259
 
4260
-        $result = $this->db->limitQuery($query, $offset, 1, true,"Error retrieving $this->object_name list: ");
4260
+        $result = $this->db->limitQuery($query, $offset, 1, true, "Error retrieving $this->object_name list: ");
4261 4261
 
4262 4262
         $previous_offset = $row_offset - $max_per_page;
4263 4263
         $next_offset = $row_offset + $max_per_page;
@@ -4268,7 +4268,7 @@  discard block
 block discarded – undo
4268 4268
         $response = Array();
4269 4269
         $response['bean'] = $this;
4270 4270
         if (empty($total_rows))
4271
-            $total_rows=0;
4271
+            $total_rows = 0;
4272 4272
         $response['row_count'] = $total_rows;
4273 4273
         $response['next_offset'] = $next_offset;
4274 4274
         $response['previous_offset'] = $previous_offset;
@@ -4285,12 +4285,12 @@  discard block
 block discarded – undo
4285 4285
      * @return array Fetched data.
4286 4286
      *
4287 4287
      */
4288
-    function process_full_list_query($query, $check_date=false)
4288
+    function process_full_list_query($query, $check_date = false)
4289 4289
     {
4290 4290
 
4291 4291
         $GLOBALS['log']->debug("process_full_list_query: query is ".$query);
4292 4292
         $result = $this->db->query($query, false);
4293
-        $GLOBALS['log']->debug("process_full_list_query: result is ".print_r($result,true));
4293
+        $GLOBALS['log']->debug("process_full_list_query: result is ".print_r($result, true));
4294 4294
         $class = get_class($this);
4295 4295
         $isFirstTime = true;
4296 4296
         $bean = new $class();
@@ -4299,13 +4299,13 @@  discard block
 block discarded – undo
4299 4299
         while (($row = $bean->db->fetchByAssoc($result)) != null)
4300 4300
         {
4301 4301
             $row = $this->convertRow($row);
4302
-            if(!$isFirstTime)
4302
+            if (!$isFirstTime)
4303 4303
             {
4304 4304
                 $bean = new $class();
4305 4305
             }
4306 4306
             $isFirstTime = false;
4307 4307
 
4308
-            foreach($bean->field_defs as $field=>$value)
4308
+            foreach ($bean->field_defs as $field=>$value)
4309 4309
             {
4310 4310
                 if (isset($row[$field]))
4311 4311
                 {
@@ -4317,7 +4317,7 @@  discard block
 block discarded – undo
4317 4317
                     $bean->$field = '';
4318 4318
                 }
4319 4319
             }
4320
-            if($check_date)
4320
+            if ($check_date)
4321 4321
             {
4322 4322
                 $bean->processed_dates_times = array();
4323 4323
                 $bean->check_date_relationships_load();
@@ -4342,10 +4342,10 @@  discard block
 block discarded – undo
4342 4342
     * @param string $current_module - String value of the module being processed.
4343 4343
     * @param string $current_view - String value of the current view
4344 4344
 	*/
4345
-	function track_view($user_id, $current_module, $current_view='')
4345
+	function track_view($user_id, $current_module, $current_view = '')
4346 4346
 	{
4347 4347
 	    $trackerManager = TrackerManager::getInstance();
4348
-		if($monitor = $trackerManager->getMonitor('tracker')){
4348
+		if ($monitor = $trackerManager->getMonitor('tracker')) {
4349 4349
 	        $monitor->setValue('date_modified', $GLOBALS['timedate']->nowDb());
4350 4350
 	        $monitor->setValue('user_id', $user_id);
4351 4351
 	        $monitor->setValue('module_name', $current_module);
@@ -4374,8 +4374,8 @@  discard block
 block discarded – undo
4374 4374
     * account for instance.  This method is only used for populating extra fields
4375 4375
     * in lists.
4376 4376
     */
4377
-    function fill_in_additional_list_fields(){
4378
-        if(!empty($this->field_defs['parent_name']) && empty($this->parent_name)){
4377
+    function fill_in_additional_list_fields() {
4378
+        if (!empty($this->field_defs['parent_name']) && empty($this->parent_name)) {
4379 4379
             $this->fill_in_additional_parent_fields();
4380 4380
         }
4381 4381
     }
@@ -4389,17 +4389,17 @@  discard block
 block discarded – undo
4389 4389
     */
4390 4390
     function fill_in_additional_detail_fields()
4391 4391
     {
4392
-        if(!empty($this->field_defs['assigned_user_name']) && !empty($this->assigned_user_id)){
4392
+        if (!empty($this->field_defs['assigned_user_name']) && !empty($this->assigned_user_id)) {
4393 4393
 
4394 4394
             $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
4395 4395
 
4396 4396
         }
4397
-		if(!empty($this->field_defs['created_by']) && !empty($this->created_by))
4397
+		if (!empty($this->field_defs['created_by']) && !empty($this->created_by))
4398 4398
 		$this->created_by_name = get_assigned_user_name($this->created_by);
4399
-		if(!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4399
+		if (!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4400 4400
 		$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
4401 4401
 
4402
-		if(!empty($this->field_defs['parent_name'])){
4402
+		if (!empty($this->field_defs['parent_name'])) {
4403 4403
 			$this->fill_in_additional_parent_fields();
4404 4404
 		}
4405 4405
     }
@@ -4410,17 +4410,17 @@  discard block
 block discarded – undo
4410 4410
     */
4411 4411
     function fill_in_additional_parent_fields() {
4412 4412
 
4413
-        if(!empty($this->parent_id) && !empty($this->last_parent_id) && $this->last_parent_id == $this->parent_id){
4413
+        if (!empty($this->parent_id) && !empty($this->last_parent_id) && $this->last_parent_id == $this->parent_id) {
4414 4414
             return false;
4415
-        }else{
4415
+        } else {
4416 4416
             $this->parent_name = '';
4417 4417
         }
4418
-        if(!empty($this->parent_type)) {
4418
+        if (!empty($this->parent_type)) {
4419 4419
             $this->last_parent_id = $this->parent_id;
4420 4420
             $this->getRelatedFields($this->parent_type, $this->parent_id, array('name'=>'parent_name', 'document_name' => 'parent_document_name', 'first_name'=>'parent_first_name', 'last_name'=>'parent_last_name'));
4421
-            if(!empty($this->parent_first_name) || !empty($this->parent_last_name) ){
4421
+            if (!empty($this->parent_first_name) || !empty($this->parent_last_name)) {
4422 4422
                 $this->parent_name = $GLOBALS['locale']->getLocaleFormattedName($this->parent_first_name, $this->parent_last_name);
4423
-            } else if(!empty($this->parent_document_name)){
4423
+            } else if (!empty($this->parent_document_name)) {
4424 4424
                 $this->parent_name = $this->parent_document_name;
4425 4425
             }
4426 4426
         }
@@ -4430,7 +4430,7 @@  discard block
 block discarded – undo
4430 4430
      * Fill in a link field
4431 4431
      */
4432 4432
 
4433
-    function fill_in_link_field( $linkFieldName , $def)
4433
+    function fill_in_link_field($linkFieldName, $def)
4434 4434
     {
4435 4435
         $idField = $linkFieldName;
4436 4436
         //If the id_name provided really was an ID, don't try to load it as a link. Use the normal link
@@ -4440,8 +4440,8 @@  discard block
 block discarded – undo
4440 4440
         }
4441 4441
         if ($this->load_relationship($linkFieldName))
4442 4442
         {
4443
-            $list=$this->$linkFieldName->get();
4444
-            $this->$idField = '' ; // match up with null value in $this->populateFromRow()
4443
+            $list = $this->$linkFieldName->get();
4444
+            $this->$idField = ''; // match up with null value in $this->populateFromRow()
4445 4445
             if (!empty($list))
4446 4446
                 $this->$idField = $list[0];
4447 4447
         }
@@ -4450,22 +4450,22 @@  discard block
 block discarded – undo
4450 4450
     /**
4451 4451
     * Fill in fields where type = relate
4452 4452
     */
4453
-    function fill_in_relationship_fields(){
4453
+    function fill_in_relationship_fields() {
4454 4454
         global $fill_in_rel_depth;
4455
-        if(empty($fill_in_rel_depth) || $fill_in_rel_depth < 0)
4455
+        if (empty($fill_in_rel_depth) || $fill_in_rel_depth < 0)
4456 4456
             $fill_in_rel_depth = 0;
4457 4457
 
4458
-        if($fill_in_rel_depth > 1)
4458
+        if ($fill_in_rel_depth > 1)
4459 4459
             return;
4460 4460
 
4461 4461
         $fill_in_rel_depth++;
4462 4462
 
4463
-        foreach($this->field_defs as $field)
4463
+        foreach ($this->field_defs as $field)
4464 4464
         {
4465
-            if(0 == strcmp($field['type'],'relate') && !empty($field['module']))
4465
+            if (0 == strcmp($field['type'], 'relate') && !empty($field['module']))
4466 4466
             {
4467 4467
                 $name = $field['name'];
4468
-                if(empty($this->$name))
4468
+                if (empty($this->$name))
4469 4469
                 {
4470 4470
                     // set the value of this relate field in this bean ($this->$field['name']) to the value of the 'name' field in the related module for the record identified by the value of $this->$field['id_name']
4471 4471
                     $related_module = $field['module'];
@@ -4475,11 +4475,11 @@  discard block
 block discarded – undo
4475 4475
                     {
4476 4476
                        $this->fill_in_link_field($id_name, $field);
4477 4477
                     }
4478
-                    if(!empty($this->$id_name) && ( $this->object_name != $related_module || ( $this->object_name == $related_module && $this->$id_name != $this->id ))){
4479
-                        if(isset($GLOBALS['beanList'][ $related_module])){
4478
+                    if (!empty($this->$id_name) && ($this->object_name != $related_module || ($this->object_name == $related_module && $this->$id_name != $this->id))) {
4479
+                        if (isset($GLOBALS['beanList'][$related_module])) {
4480 4480
                             $class = $GLOBALS['beanList'][$related_module];
4481 4481
 
4482
-                            if(!empty($this->$id_name) && file_exists($GLOBALS['beanFiles'][$class]) && isset($this->$name)){
4482
+                            if (!empty($this->$id_name) && file_exists($GLOBALS['beanFiles'][$class]) && isset($this->$name)) {
4483 4483
                                 require_once($GLOBALS['beanFiles'][$class]);
4484 4484
                                 $mod = new $class();
4485 4485
 
@@ -4496,17 +4496,17 @@  discard block
 block discarded – undo
4496 4496
                             }
4497 4497
                         }
4498 4498
                     }
4499
-                    if(!empty($this->$id_name) && isset($this->$name))
4499
+                    if (!empty($this->$id_name) && isset($this->$name))
4500 4500
                     {
4501
-                        if(!isset($field['additionalFields']))
4501
+                        if (!isset($field['additionalFields']))
4502 4502
                            $field['additionalFields'] = array();
4503
-                        if(!empty($field['rname']))
4503
+                        if (!empty($field['rname']))
4504 4504
                         {
4505
-                            $field['additionalFields'][$field['rname']]= $name;
4505
+                            $field['additionalFields'][$field['rname']] = $name;
4506 4506
                         }
4507 4507
                         else
4508 4508
                         {
4509
-                            $field['additionalFields']['name']= $name;
4509
+                            $field['additionalFields']['name'] = $name;
4510 4510
                         }
4511 4511
                         $this->getRelatedFields($related_module, $this->$id_name, $field['additionalFields']);
4512 4512
                     }
@@ -4536,7 +4536,7 @@  discard block
 block discarded – undo
4536 4536
 		global $current_user;
4537 4537
 		$date_modified = $GLOBALS['timedate']->nowDb();
4538 4538
         $id = $this->db->quote($id);
4539
-		if(isset($_SESSION['show_deleted']))
4539
+		if (isset($_SESSION['show_deleted']))
4540 4540
 		{
4541 4541
 			$this->mark_undeleted($id);
4542 4542
 		}
@@ -4547,7 +4547,7 @@  discard block
 block discarded – undo
4547 4547
 			$this->call_custom_logic("before_delete", $custom_logic_arguments);
4548 4548
             $this->deleted = 1;
4549 4549
             $this->mark_relationships_deleted($id);
4550
-            if ( isset($this->field_defs['modified_user_id']) ) {
4550
+            if (isset($this->field_defs['modified_user_id'])) {
4551 4551
                 if (!empty($current_user)) {
4552 4552
                     $this->modified_user_id = $current_user->id;
4553 4553
                 } else {
@@ -4557,7 +4557,7 @@  discard block
 block discarded – undo
4557 4557
             } else {
4558 4558
                 $query = "UPDATE $this->table_name set deleted=1 , date_modified = '$date_modified' where id='$id'";
4559 4559
             }
4560
-            $this->db->query($query, true,"Error marking record deleted: ");
4560
+            $this->db->query($query, true, "Error marking record deleted: ");
4561 4561
 
4562 4562
             SugarRelationship::resaveRelatedBeans();
4563 4563
 
@@ -4585,8 +4585,8 @@  discard block
 block discarded – undo
4585 4585
         $this->call_custom_logic("before_restore", $custom_logic_arguments);
4586 4586
 
4587 4587
 		$date_modified = $GLOBALS['timedate']->nowDb();
4588
-		$query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='" . $this->db->quote($id) ."'";
4589
-		$this->db->query($query, true,"Error marking record undeleted: ");
4588
+		$query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='".$this->db->quote($id)."'";
4589
+		$this->db->query($query, true, "Error marking record undeleted: ");
4590 4590
 
4591 4591
         $this->restoreFiles();
4592 4592
 
@@ -4639,19 +4639,19 @@  discard block
 block discarded – undo
4639 4639
 
4640 4640
         $directory = $this->deleteFileDirectory();
4641 4641
 
4642
-        $isCreated = sugar_is_dir('upload://deleted/' . $directory);
4642
+        $isCreated = sugar_is_dir('upload://deleted/'.$directory);
4643 4643
         if (!$isCreated) {
4644
-            sugar_mkdir('upload://deleted/' . $directory, 0777, true);
4645
-            $isCreated = sugar_is_dir('upload://deleted/' . $directory);
4644
+            sugar_mkdir('upload://deleted/'.$directory, 0777, true);
4645
+            $isCreated = sugar_is_dir('upload://deleted/'.$directory);
4646 4646
         }
4647 4647
         if (!$isCreated) {
4648 4648
             return false;
4649 4649
         }
4650 4650
 
4651 4651
         foreach ($files as $file) {
4652
-            if (file_exists('upload://' . $file)) {
4653
-                if (!sugar_rename('upload://' . $file, 'upload://deleted/' . $directory . '/' . $file)) {
4654
-                    $GLOBALS['log']->error('Could not move file ' . $file . ' to deleted directory');
4652
+            if (file_exists('upload://'.$file)) {
4653
+                if (!sugar_rename('upload://'.$file, 'upload://deleted/'.$directory.'/'.$file)) {
4654
+                    $GLOBALS['log']->error('Could not move file '.$file.' to deleted directory');
4655 4655
                 }
4656 4656
             }
4657 4657
         }
@@ -4671,7 +4671,7 @@  discard block
 block discarded – undo
4671 4671
         }
4672 4672
         if (empty($record['id'])) {
4673 4673
             $record['id'] = $db->quoted(create_guid());
4674
-            $db->query('INSERT INTO cron_remove_documents (' . implode(', ', array_keys($record)) . ') VALUES(' . implode(', ', $record) . ')');
4674
+            $db->query('INSERT INTO cron_remove_documents ('.implode(', ', array_keys($record)).') VALUES('.implode(', ', $record).')');
4675 4675
         } else {
4676 4676
             $db->query("UPDATE cron_remove_documents SET date_modified={$record['date_modified']} WHERE id={$record['id']}");
4677 4677
         }
@@ -4700,9 +4700,9 @@  discard block
 block discarded – undo
4700 4700
         $directory = $this->deleteFileDirectory();
4701 4701
 
4702 4702
         foreach ($files as $file) {
4703
-            if (sugar_is_file('upload://deleted/' . $directory . '/' . $file)) {
4704
-                if (!sugar_rename('upload://deleted/' . $directory . '/' . $file, 'upload://' . $file)) {
4705
-                    $GLOBALS['log']->error('Could not move file ' . $directory . '/' . $file . ' from deleted directory');
4703
+            if (sugar_is_file('upload://deleted/'.$directory.'/'.$file)) {
4704
+                if (!sugar_rename('upload://deleted/'.$directory.'/'.$file, 'upload://'.$file)) {
4705
+                    $GLOBALS['log']->error('Could not move file '.$directory.'/'.$file.' from deleted directory');
4706 4706
                 }
4707 4707
             }
4708 4708
         }
@@ -4711,7 +4711,7 @@  discard block
 block discarded – undo
4711 4711
          * @var DBManager $db
4712 4712
          */
4713 4713
         global $db;
4714
-        $db->query('DELETE FROM cron_remove_documents WHERE bean_id=' . $db->quoted($this->id));
4714
+        $db->query('DELETE FROM cron_remove_documents WHERE bean_id='.$db->quoted($this->id));
4715 4715
 
4716 4716
         return true;
4717 4717
     }
@@ -4799,9 +4799,9 @@  discard block
 block discarded – undo
4799 4799
         $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
4800 4800
         $db = DBManagerFactory::getInstance('listviews');
4801 4801
 
4802
-        if(!empty($row_offset) && $row_offset != 0 && !empty($limit) && $limit != -1)
4802
+        if (!empty($row_offset) && $row_offset != 0 && !empty($limit) && $limit != -1)
4803 4803
         {
4804
-            $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $template->object_name list: ");
4804
+            $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $template->object_name list: ");
4805 4805
         }
4806 4806
         else
4807 4807
         {
@@ -4811,16 +4811,16 @@  discard block
 block discarded – undo
4811 4811
         $list = Array();
4812 4812
         $isFirstTime = true;
4813 4813
         $class = get_class($template);
4814
-        while($row = $this->db->fetchByAssoc($result))
4814
+        while ($row = $this->db->fetchByAssoc($result))
4815 4815
         {
4816
-            if(!$isFirstTime)
4816
+            if (!$isFirstTime)
4817 4817
             {
4818 4818
                 $template = new $class();
4819 4819
             }
4820 4820
             $isFirstTime = false;
4821 4821
             $record = $template->retrieve($row['id']);
4822 4822
 
4823
-            if($record != null)
4823
+            if ($record != null)
4824 4824
             {
4825 4825
                 // this copies the object into the array
4826 4826
                 $list[] = $template;
@@ -4838,12 +4838,12 @@  discard block
 block discarded – undo
4838 4838
     * @param string $query - the query that should be executed to build the list
4839 4839
     * @param object $template - The object that should be used to copy the records.
4840 4840
     */
4841
-  function build_related_list_where($query, &$template, $where='', $in='', $order_by, $limit='', $row_offset = 0)
4841
+  function build_related_list_where($query, &$template, $where = '', $in = '', $order_by, $limit = '', $row_offset = 0)
4842 4842
   {
4843 4843
     $db = DBManagerFactory::getInstance('listviews');
4844 4844
     // No need to do an additional query
4845 4845
     $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
4846
-    if(empty($in) && !empty($query))
4846
+    if (empty($in) && !empty($query))
4847 4847
     {
4848 4848
         $idList = $this->build_related_in($query);
4849 4849
         $in = $idList['in'];
@@ -4859,19 +4859,19 @@  discard block
 block discarded – undo
4859 4859
     $query .= $custom_join['join'];
4860 4860
 
4861 4861
     $query .= " WHERE deleted=0 AND id IN $in";
4862
-    if(!empty($where))
4862
+    if (!empty($where))
4863 4863
     {
4864 4864
         $query .= " AND $where";
4865 4865
     }
4866 4866
 
4867 4867
 
4868
-    if(!empty($order_by))
4868
+    if (!empty($order_by))
4869 4869
     {
4870 4870
         $query .= "ORDER BY $order_by";
4871 4871
     }
4872 4872
     if (!empty($limit))
4873 4873
     {
4874
-        $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $this->object_name list: ");
4874
+        $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $this->object_name list: ");
4875 4875
     }
4876 4876
     else
4877 4877
     {
@@ -4883,16 +4883,16 @@  discard block
 block discarded – undo
4883 4883
     $class = get_class($template);
4884 4884
 
4885 4885
     $disable_security_flag = ($template->disable_row_level_security) ? true : false;
4886
-    while($row = $db->fetchByAssoc($result))
4886
+    while ($row = $db->fetchByAssoc($result))
4887 4887
     {
4888
-        if(!$isFirstTime)
4888
+        if (!$isFirstTime)
4889 4889
         {
4890 4890
             $template = new $class();
4891 4891
             $template->disable_row_level_security = $disable_security_flag;
4892 4892
         }
4893 4893
         $isFirstTime = false;
4894 4894
         $record = $template->retrieve($row['id']);
4895
-        if($record != null)
4895
+        if ($record != null)
4896 4896
         {
4897 4897
             // this copies the object into the array
4898 4898
             $list[] = $template;
@@ -4913,22 +4913,22 @@  discard block
 block discarded – undo
4913 4913
         $idList = array();
4914 4914
         $result = $this->db->query($query, true);
4915 4915
         $ids = '';
4916
-        while($row = $this->db->fetchByAssoc($result))
4916
+        while ($row = $this->db->fetchByAssoc($result))
4917 4917
         {
4918 4918
             $idList[] = $row['id'];
4919
-            if(empty($ids))
4919
+            if (empty($ids))
4920 4920
             {
4921
-                $ids = "('" . $row['id'] . "'";
4921
+                $ids = "('".$row['id']."'";
4922 4922
             }
4923 4923
             else
4924 4924
             {
4925
-                $ids .= ",'" . $row['id'] . "'";
4925
+                $ids .= ",'".$row['id']."'";
4926 4926
             }
4927 4927
         }
4928
-        if(empty($ids))
4928
+        if (empty($ids))
4929 4929
         {
4930 4930
             $ids = "('')";
4931
-        }else{
4931
+        } else {
4932 4932
             $ids .= ')';
4933 4933
         }
4934 4934
 
@@ -4954,16 +4954,16 @@  discard block
 block discarded – undo
4954 4954
         $list = Array();
4955 4955
         $isFirstTime = true;
4956 4956
         $class = get_class($template);
4957
-        while($row = $this->db->fetchByAssoc($result))
4957
+        while ($row = $this->db->fetchByAssoc($result))
4958 4958
         {
4959 4959
             // Create a blank copy
4960 4960
             $copy = $template;
4961
-            if(!$isFirstTime)
4961
+            if (!$isFirstTime)
4962 4962
             {
4963 4963
                 $copy = new $class();
4964 4964
             }
4965 4965
             $isFirstTime = false;
4966
-            foreach($field_list as $field)
4966
+            foreach ($field_list as $field)
4967 4967
             {
4968 4968
                 // Copy the relevant fields
4969 4969
                 $copy->$field = $row[$field];
@@ -4995,14 +4995,14 @@  discard block
 block discarded – undo
4995 4995
 
4996 4996
         $return_array = Array();
4997 4997
         global $app_list_strings, $mod_strings;
4998
-        foreach($this->field_defs as $field=>$value){
4998
+        foreach ($this->field_defs as $field=>$value) {
4999 4999
 
5000
-            if(isset($this->$field)){
5000
+            if (isset($this->$field)) {
5001 5001
 
5002 5002
                 // cn: bug 12270 - sensitive fields being passed arbitrarily in listViews
5003
-                if(isset($sensitiveFields[$field]))
5003
+                if (isset($sensitiveFields[$field]))
5004 5004
                     continue;
5005
-                if(!isset($cache[$field]))
5005
+                if (!isset($cache[$field]))
5006 5006
                     $cache[$field] = strtoupper($field);
5007 5007
 
5008 5008
                 //Fields hidden by Dependent Fields
@@ -5012,30 +5012,30 @@  discard block
 block discarded – undo
5012 5012
                 }
5013 5013
                 //cn: if $field is a _dom, detect and return VALUE not KEY
5014 5014
                 //cl: empty function check for meta-data enum types that have values loaded from a function
5015
-                else if (((!empty($value['type']) && ($value['type'] == 'enum' || $value['type'] == 'radioenum') ))  && empty($value['function'])){
5016
-                    if(!empty($value['options']) && !empty($app_list_strings[$value['options']][$this->$field])){
5015
+                else if (((!empty($value['type']) && ($value['type'] == 'enum' || $value['type'] == 'radioenum'))) && empty($value['function'])) {
5016
+                    if (!empty($value['options']) && !empty($app_list_strings[$value['options']][$this->$field])) {
5017 5017
                         $return_array[$cache[$field]] = $app_list_strings[$value['options']][$this->$field];
5018 5018
                     }
5019 5019
                     //nsingh- bug 21672. some modules such as manufacturers, Releases do not have a listing for select fields in the $app_list_strings. Must also check $mod_strings to localize.
5020
-                    elseif(!empty($value['options']) && !empty($mod_strings[$value['options']][$this->$field]))
5020
+                    elseif (!empty($value['options']) && !empty($mod_strings[$value['options']][$this->$field]))
5021 5021
                     {
5022 5022
                         $return_array[$cache[$field]] = $mod_strings[$value['options']][$this->$field];
5023 5023
                     }
5024
-                    else{
5024
+                    else {
5025 5025
                         $return_array[$cache[$field]] = $this->$field;
5026 5026
                     }
5027 5027
                     //end bug 21672
5028 5028
 // tjy: no need to do this str_replace as the changes in 29994 for ListViewGeneric.tpl for translation handle this now
5029 5029
 //				}elseif(!empty($value['type']) && $value['type'] == 'multienum'&& empty($value['function'])){
5030 5030
 //					$return_array[strtoupper($field)] = str_replace('^,^', ', ', $this->$field );
5031
-                }elseif(!empty($value['custom_module']) && $value['type'] != 'currency'){
5031
+                }elseif (!empty($value['custom_module']) && $value['type'] != 'currency') {
5032 5032
 //					$this->format_field($value);
5033 5033
                     $return_array[$cache[$field]] = $this->$field;
5034
-                }else{
5034
+                } else {
5035 5035
                     $return_array[$cache[$field]] = $this->$field;
5036 5036
                 }
5037 5037
                 // handle "Assigned User Name"
5038
-                if($field == 'assigned_user_name'){
5038
+                if ($field == 'assigned_user_name') {
5039 5039
                     $return_array['ASSIGNED_USER_NAME'] = get_assigned_user_name($this->assigned_user_id);
5040 5040
                 }
5041 5041
             }
@@ -5057,7 +5057,7 @@  discard block
 block discarded – undo
5057 5057
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
5058 5058
      * @return string The WHERE clause
5059 5059
      */
5060
-    function get_where($fields_array, $deleted=true)
5060
+    function get_where($fields_array, $deleted = true)
5061 5061
     {
5062 5062
         $where_clause = "";
5063 5063
         foreach ($fields_array as $name=>$value)
@@ -5067,10 +5067,10 @@  discard block
 block discarded – undo
5067 5067
             }
5068 5068
             $name = $this->db->getValidDBName($name);
5069 5069
 
5070
-            $where_clause .= "$name = ".$this->db->quoted($value,false);
5070
+            $where_clause .= "$name = ".$this->db->quoted($value, false);
5071 5071
         }
5072
-        if(!empty($where_clause)) {
5073
-            if($deleted) {
5072
+        if (!empty($where_clause)) {
5073
+            if ($deleted) {
5074 5074
                 return "WHERE $where_clause AND deleted=0";
5075 5075
             } else {
5076 5076
                 return "WHERE $where_clause";
@@ -5090,24 +5090,24 @@  discard block
 block discarded – undo
5090 5090
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
5091 5091
      * @return object Instance of this bean with fetched data.
5092 5092
      */
5093
-    function retrieve_by_string_fields($fields_array, $encode=true, $deleted=true)
5093
+    function retrieve_by_string_fields($fields_array, $encode = true, $deleted = true)
5094 5094
     {
5095 5095
         $where_clause = $this->get_where($fields_array, $deleted);
5096 5096
         $custom_join = $this->getCustomJoin();
5097
-        $query = "SELECT $this->table_name.*". $custom_join['select']. " FROM $this->table_name " . $custom_join['join'];
5097
+        $query = "SELECT $this->table_name.*".$custom_join['select']." FROM $this->table_name ".$custom_join['join'];
5098 5098
         $query .= " $where_clause";
5099 5099
         $GLOBALS['log']->debug("Retrieve $this->object_name: ".$query);
5100 5100
         //requireSingleResult has been deprecated.
5101 5101
         //$result = $this->db->requireSingleResult($query, true, "Retrieving record $where_clause:");
5102
-        $result = $this->db->limitQuery($query,0,1,true, "Retrieving record $where_clause:");
5102
+        $result = $this->db->limitQuery($query, 0, 1, true, "Retrieving record $where_clause:");
5103 5103
 
5104 5104
 
5105
-        if( empty($result))
5105
+        if (empty($result))
5106 5106
         {
5107 5107
             return null;
5108 5108
         }
5109 5109
         $row = $this->db->fetchByAssoc($result, $encode);
5110
-        if(empty($row))
5110
+        if (empty($row))
5111 5111
         {
5112 5112
             return null;
5113 5113
         }
@@ -5134,7 +5134,7 @@  discard block
 block discarded – undo
5134 5134
     {
5135 5135
         foreach ($this->special_functions as $func_name)
5136 5136
         {
5137
-            if ( method_exists($this,$func_name) )
5137
+            if (method_exists($this, $func_name))
5138 5138
             {
5139 5139
                 $this->$func_name();
5140 5140
             }
@@ -5149,52 +5149,52 @@  discard block
 block discarded – undo
5149 5149
     {
5150 5150
     }
5151 5151
 
5152
-    function getRelatedFields($module, $id, $fields, $return_array = false){
5153
-        if(empty($GLOBALS['beanList'][$module]))return '';
5152
+    function getRelatedFields($module, $id, $fields, $return_array = false) {
5153
+        if (empty($GLOBALS['beanList'][$module]))return '';
5154 5154
         $object = BeanFactory::getObjectName($module);
5155 5155
 
5156 5156
         VardefManager::loadVardef($module, $object);
5157
-        if(empty($GLOBALS['dictionary'][$object]['table']))return '';
5157
+        if (empty($GLOBALS['dictionary'][$object]['table']))return '';
5158 5158
         $table = $GLOBALS['dictionary'][$object]['table'];
5159
-        $query  = 'SELECT id';
5160
-        foreach($fields as $field=>$alias){
5161
-            if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])){
5162
-                $query .= ' ,' .$this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']) .  ' as ' . $alias ;
5163
-            }else if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
5159
+        $query = 'SELECT id';
5160
+        foreach ($fields as $field=>$alias) {
5161
+            if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])) {
5162
+                $query .= ' ,'.$this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']).' as '.$alias;
5163
+            } else if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
5164 5164
                 (empty($GLOBALS['dictionary'][$object]['fields'][$field]['source']) ||
5165 5165
                 $GLOBALS['dictionary'][$object]['fields'][$field]['source'] != "non-db"))
5166 5166
             {
5167
-                $query .= ' ,' .$table . '.' . $field . ' as ' . $alias;
5167
+                $query .= ' ,'.$table.'.'.$field.' as '.$alias;
5168 5168
             }
5169
-            if(!$return_array)$this->$alias = '';
5169
+            if (!$return_array)$this->$alias = '';
5170 5170
         }
5171
-        if($query == 'SELECT id' || empty($id)){
5171
+        if ($query == 'SELECT id' || empty($id)) {
5172 5172
             return '';
5173 5173
         }
5174 5174
 
5175 5175
 
5176
-        if(isset($GLOBALS['dictionary'][$object]['fields']['assigned_user_id']))
5176
+        if (isset($GLOBALS['dictionary'][$object]['fields']['assigned_user_id']))
5177 5177
         {
5178
-            $query .= " , ".	$table  . ".assigned_user_id owner";
5178
+            $query .= " , ".$table.".assigned_user_id owner";
5179 5179
 
5180 5180
         }
5181
-        else if(isset($GLOBALS['dictionary'][$object]['fields']['created_by']))
5181
+        else if (isset($GLOBALS['dictionary'][$object]['fields']['created_by']))
5182 5182
         {
5183
-            $query .= " , ".	$table . ".created_by owner";
5183
+            $query .= " , ".$table.".created_by owner";
5184 5184
 
5185 5185
         }
5186
-        $query .=  ' FROM ' . $table . ' WHERE deleted=0 AND id=';
5187
-        $result = $GLOBALS['db']->query($query . "'$id'" );
5186
+        $query .= ' FROM '.$table.' WHERE deleted=0 AND id=';
5187
+        $result = $GLOBALS['db']->query($query."'$id'");
5188 5188
         $row = $GLOBALS['db']->fetchByAssoc($result);
5189
-        if($return_array){
5189
+        if ($return_array) {
5190 5190
             return $row;
5191 5191
         }
5192
-        $owner = (empty($row['owner']))?'':$row['owner'];
5193
-        foreach($fields as $alias){
5194
-            $this->$alias = (!empty($row[$alias]))? $row[$alias]: '';
5195
-            $alias = $alias  .'_owner';
5192
+        $owner = (empty($row['owner'])) ? '' : $row['owner'];
5193
+        foreach ($fields as $alias) {
5194
+            $this->$alias = (!empty($row[$alias])) ? $row[$alias] : '';
5195
+            $alias = $alias.'_owner';
5196 5196
             $this->$alias = $owner;
5197
-            $a_mod = $alias  .'_mod';
5197
+            $a_mod = $alias.'_mod';
5198 5198
             $this->$a_mod = $module;
5199 5199
         }
5200 5200
 
@@ -5210,39 +5210,39 @@  discard block
 block discarded – undo
5210 5210
     function assign_display_fields($currentModule)
5211 5211
     {
5212 5212
         global $timedate;
5213
-        foreach($this->column_fields as $field)
5213
+        foreach ($this->column_fields as $field)
5214 5214
         {
5215
-            if(isset($this->field_name_map[$field]) && empty($this->$field))
5215
+            if (isset($this->field_name_map[$field]) && empty($this->$field))
5216 5216
             {
5217
-                if($this->field_name_map[$field]['type'] != 'date' && $this->field_name_map[$field]['type'] != 'enum')
5217
+                if ($this->field_name_map[$field]['type'] != 'date' && $this->field_name_map[$field]['type'] != 'enum')
5218 5218
                 $this->$field = $field;
5219
-                if($this->field_name_map[$field]['type'] == 'date')
5219
+                if ($this->field_name_map[$field]['type'] == 'date')
5220 5220
                 {
5221 5221
                     $this->$field = $timedate->to_display_date('1980-07-09');
5222 5222
                 }
5223
-                if($this->field_name_map[$field]['type'] == 'enum')
5223
+                if ($this->field_name_map[$field]['type'] == 'enum')
5224 5224
                 {
5225 5225
                     $dom = $this->field_name_map[$field]['options'];
5226 5226
                     global $current_language, $app_list_strings;
5227 5227
                     $mod_strings = return_module_language($current_language, $currentModule);
5228 5228
 
5229
-                    if(isset($mod_strings[$dom]))
5229
+                    if (isset($mod_strings[$dom]))
5230 5230
                     {
5231 5231
                         $options = $mod_strings[$dom];
5232
-                        foreach($options as $key=>$value)
5232
+                        foreach ($options as $key=>$value)
5233 5233
                         {
5234
-                            if(!empty($key) && empty($this->$field ))
5234
+                            if (!empty($key) && empty($this->$field))
5235 5235
                             {
5236 5236
                                 $this->$field = $key;
5237 5237
                             }
5238 5238
                         }
5239 5239
                     }
5240
-                    if(isset($app_list_strings[$dom]))
5240
+                    if (isset($app_list_strings[$dom]))
5241 5241
                     {
5242 5242
                         $options = $app_list_strings[$dom];
5243
-                        foreach($options as $key=>$value)
5243
+                        foreach ($options as $key=>$value)
5244 5244
                         {
5245
-                            if(!empty($key) && empty($this->$field ))
5245
+                            if (!empty($key) && empty($this->$field))
5246 5246
                             {
5247 5247
                                 $this->$field = $key;
5248 5248
                             }
@@ -5259,61 +5259,61 @@  discard block
 block discarded – undo
5259 5259
     * 	RELATIONSHIP HANDLING
5260 5260
     */
5261 5261
 
5262
-    function set_relationship($table, $relate_values, $check_duplicates = true,$do_update=false,$data_values=null)
5262
+    function set_relationship($table, $relate_values, $check_duplicates = true, $do_update = false, $data_values = null)
5263 5263
     {
5264 5264
         $where = '';
5265 5265
 
5266 5266
 		// make sure there is a date modified
5267 5267
 		$date_modified = $this->db->convert("'".$GLOBALS['timedate']->nowDb()."'", 'datetime');
5268 5268
 
5269
-        $row=null;
5270
-        if($check_duplicates)
5269
+        $row = null;
5270
+        if ($check_duplicates)
5271 5271
         {
5272 5272
             $query = "SELECT * FROM $table ";
5273 5273
             $where = "WHERE deleted = '0'  ";
5274
-            foreach($relate_values as $name=>$value)
5274
+            foreach ($relate_values as $name=>$value)
5275 5275
             {
5276 5276
                 $where .= " AND $name = '$value' ";
5277 5277
             }
5278 5278
             $query .= $where;
5279
-            $result = $this->db->query($query, false, "Looking For Duplicate Relationship:" . $query);
5280
-            $row=$this->db->fetchByAssoc($result);
5279
+            $result = $this->db->query($query, false, "Looking For Duplicate Relationship:".$query);
5280
+            $row = $this->db->fetchByAssoc($result);
5281 5281
         }
5282 5282
 
5283
-        if(!$check_duplicates || empty($row) )
5283
+        if (!$check_duplicates || empty($row))
5284 5284
         {
5285 5285
             unset($relate_values['id']);
5286
-            if ( isset($data_values))
5286
+            if (isset($data_values))
5287 5287
             {
5288
-                $relate_values = array_merge($relate_values,$data_values);
5288
+                $relate_values = array_merge($relate_values, $data_values);
5289 5289
             }
5290
-            $query = "INSERT INTO $table (id, ". implode(',', array_keys($relate_values)) . ", date_modified) VALUES ('" . create_guid() . "', " . "'" . implode("', '", $relate_values) . "', ".$date_modified.")" ;
5290
+            $query = "INSERT INTO $table (id, ".implode(',', array_keys($relate_values)).", date_modified) VALUES ('".create_guid()."', "."'".implode("', '", $relate_values)."', ".$date_modified.")";
5291 5291
 
5292
-            $this->db->query($query, false, "Creating Relationship:" . $query);
5292
+            $this->db->query($query, false, "Creating Relationship:".$query);
5293 5293
         }
5294 5294
         else if ($do_update)
5295 5295
         {
5296 5296
             $conds = array();
5297
-            foreach($data_values as $key=>$value)
5297
+            foreach ($data_values as $key=>$value)
5298 5298
             {
5299
-                array_push($conds,$key."='".$this->db->quote($value)."'");
5299
+                array_push($conds, $key."='".$this->db->quote($value)."'");
5300 5300
             }
5301
-            $query = "UPDATE $table SET ". implode(',', $conds).",date_modified=".$date_modified." ".$where;
5302
-            $this->db->query($query, false, "Updating Relationship:" . $query);
5301
+            $query = "UPDATE $table SET ".implode(',', $conds).",date_modified=".$date_modified." ".$where;
5302
+            $this->db->query($query, false, "Updating Relationship:".$query);
5303 5303
         }
5304 5304
     }
5305 5305
 
5306 5306
     function retrieve_relationships($table, $values, $select_id)
5307 5307
     {
5308 5308
         $query = "SELECT $select_id FROM $table WHERE deleted = 0  ";
5309
-        foreach($values as $name=>$value)
5309
+        foreach ($values as $name=>$value)
5310 5310
         {
5311 5311
             $query .= " AND $name = '$value' ";
5312 5312
         }
5313 5313
         $query .= " ORDER BY $select_id ";
5314
-        $result = $this->db->query($query, false, "Retrieving Relationship:" . $query);
5314
+        $result = $this->db->query($query, false, "Retrieving Relationship:".$query);
5315 5315
         $ids = array();
5316
-        while($row = $this->db->fetchByAssoc($result))
5316
+        while ($row = $this->db->fetchByAssoc($result))
5317 5317
         {
5318 5318
             $ids[] = $row;
5319 5319
         }
@@ -5324,16 +5324,16 @@  discard block
 block discarded – undo
5324 5324
     function loadLayoutDefs()
5325 5325
     {
5326 5326
         global $layout_defs;
5327
-        if(empty( $this->layout_def) && file_exists('modules/'. $this->module_dir . '/layout_defs.php'))
5327
+        if (empty($this->layout_def) && file_exists('modules/'.$this->module_dir.'/layout_defs.php'))
5328 5328
         {
5329
-            include_once('modules/'. $this->module_dir . '/layout_defs.php');
5330
-            if(file_exists('custom/modules/'. $this->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php'))
5329
+            include_once('modules/'.$this->module_dir.'/layout_defs.php');
5330
+            if (file_exists('custom/modules/'.$this->module_dir.'/Ext/Layoutdefs/layoutdefs.ext.php'))
5331 5331
             {
5332
-                include_once('custom/modules/'. $this->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php');
5332
+                include_once('custom/modules/'.$this->module_dir.'/Ext/Layoutdefs/layoutdefs.ext.php');
5333 5333
             }
5334
-            if ( empty( $layout_defs[get_class($this)]))
5334
+            if (empty($layout_defs[get_class($this)]))
5335 5335
             {
5336
-                echo "\$layout_defs[" . get_class($this) . "]; does not exist";
5336
+                echo "\$layout_defs[".get_class($this)."]; does not exist";
5337 5337
             }
5338 5338
 
5339 5339
             $this->layout_def = $layout_defs[get_class($this)];
@@ -5367,12 +5367,12 @@  discard block
 block discarded – undo
5367 5367
     */
5368 5368
     function call_custom_logic($event, $arguments = null)
5369 5369
     {
5370
-        if(!isset($this->processed) || $this->processed == false){
5370
+        if (!isset($this->processed) || $this->processed == false) {
5371 5371
             //add some logic to ensure we do not get into an infinite loop
5372
-            if(!empty($this->logicHookDepth[$event])) {
5373
-                if($this->logicHookDepth[$event] > $this->max_logic_depth)
5372
+            if (!empty($this->logicHookDepth[$event])) {
5373
+                if ($this->logicHookDepth[$event] > $this->max_logic_depth)
5374 5374
                     return;
5375
-            }else
5375
+            } else
5376 5376
                 $this->logicHookDepth[$event] = 0;
5377 5377
 
5378 5378
             //we have to put the increment operator here
@@ -5417,7 +5417,7 @@  discard block
 block discarded – undo
5417 5417
             $GLOBALS['log']->fatal("SUGARBEAN: cannot find Real Key for custom field of type dropdown - cannot return Value.");
5418 5418
             return false;
5419 5419
         }
5420
-        if(isset($realKey))
5420
+        if (isset($realKey))
5421 5421
         {
5422 5422
             return $this->custom_fields->avail_fields[$name][$realKey];
5423 5423
         }
@@ -5436,17 +5436,17 @@  discard block
 block discarded – undo
5436 5436
 	/**
5437 5437
     function ACLAccess($view,$is_owner='not_set')
5438 5438
 	*/
5439
-    function ACLAccess($view,$is_owner='not_set',$in_group='not_set')
5439
+    function ACLAccess($view, $is_owner = 'not_set', $in_group = 'not_set')
5440 5440
     {
5441 5441
         global $current_user;
5442
-        if($current_user->isAdmin()) {
5442
+        if ($current_user->isAdmin()) {
5443 5443
             return true;
5444 5444
         }
5445 5445
         $not_set = false;
5446 5446
 		/**
5447 5447
         if($is_owner == 'not_set')
5448 5448
 		*/
5449
-    	if($is_owner === 'not_set') //eggsurplus: should be ===
5449
+    	if ($is_owner === 'not_set') //eggsurplus: should be ===
5450 5450
         {
5451 5451
             $not_set = true;
5452 5452
             $is_owner = $this->isOwner($current_user->id);
@@ -5457,7 +5457,7 @@  discard block
 block discarded – undo
5457 5457
 		$view = strtolower($view);
5458 5458
 		$action = '';
5459 5459
 		// DJM - OBS Customizations - END CHANGE
5460
-    	if($in_group === 'not_set')
5460
+    	if ($in_group === 'not_set')
5461 5461
     	{
5462 5462
 			require_once("modules/SecurityGroups/SecurityGroup.php");
5463 5463
 			// DJM - OBS Customizations - May 2009
@@ -5483,7 +5483,7 @@  discard block
 block discarded – undo
5483 5483
  		   			$action = "view";
5484 5484
 					break;
5485 5485
  		   		case 'delete':
5486
- 		   			$action = "delete" ;
5486
+ 		   			$action = "delete";
5487 5487
 					break;
5488 5488
  		   		case 'export':
5489 5489
  		   			$action = "export";
@@ -5495,11 +5495,11 @@  discard block
 block discarded – undo
5495 5495
 					$action = "";
5496 5496
 					break;
5497 5497
     			}
5498
-			$in_group = SecurityGroup::groupHasAccess($this->module_dir,$this->id, $action); 
5498
+			$in_group = SecurityGroup::groupHasAccess($this->module_dir, $this->id, $action); 
5499 5499
 			// DJM - OBS Customizations - END CHANGE
5500 5500
     	}
5501 5501
         //if we don't implent acls return true
5502
-        if(!$this->bean_implements('ACL'))
5502
+        if (!$this->bean_implements('ACL'))
5503 5503
         return true;
5504 5504
         $view = strtolower($view);
5505 5505
         switch ($view)
@@ -5510,15 +5510,15 @@  discard block
 block discarded – undo
5510 5510
 				/**
5511 5511
                 return ACLController::checkAccess($this->module_dir,'list', true);
5512 5512
 				*/
5513
-    			return ACLController::checkAccess($this->module_dir,'list', true, $this->acltype, $in_group);
5513
+    			return ACLController::checkAccess($this->module_dir, 'list', true, $this->acltype, $in_group);
5514 5514
             case 'edit':
5515 5515
             case 'save':
5516
-                if( !$is_owner && $not_set && !empty($this->id)){
5516
+                if (!$is_owner && $not_set && !empty($this->id)) {
5517 5517
                     $class = get_class($this);
5518 5518
                     $temp = new $class();
5519
-                    if(!empty($this->fetched_row) && !empty($this->fetched_row['id']) && !empty($this->fetched_row['assigned_user_id']) && !empty($this->fetched_row['created_by'])){
5519
+                    if (!empty($this->fetched_row) && !empty($this->fetched_row['id']) && !empty($this->fetched_row['assigned_user_id']) && !empty($this->fetched_row['created_by'])) {
5520 5520
                         $temp->populateFromRow($this->fetched_row);
5521
-                    }else{
5521
+                    } else {
5522 5522
                         $temp->retrieve($this->id);
5523 5523
                     }
5524 5524
                     $is_owner = $temp->isOwner($current_user->id);
@@ -5528,29 +5528,29 @@  discard block
 block discarded – undo
5528 5528
 				/**
5529 5529
                 return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype);
5530 5530
 				*/
5531
-    			return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype, $in_group);
5531
+    			return ACLController::checkAccess($this->module_dir, 'edit', $is_owner, $this->acltype, $in_group);
5532 5532
             case 'view':
5533 5533
             case 'detail':
5534 5534
             case 'detailview':
5535 5535
 				/**
5536 5536
                 return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype);
5537 5537
 				*/
5538
-    			return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype, $in_group);
5538
+    			return ACLController::checkAccess($this->module_dir, 'view', $is_owner, $this->acltype, $in_group);
5539 5539
             case 'delete':
5540 5540
 				/**
5541 5541
                 return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype);
5542 5542
 				*/
5543
-    			return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype, $in_group);
5543
+    			return ACLController::checkAccess($this->module_dir, 'delete', $is_owner, $this->acltype, $in_group);
5544 5544
             case 'export':
5545 5545
 				/**
5546 5546
                 return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype);
5547 5547
 				*/
5548
-    			return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype, $in_group);
5548
+    			return ACLController::checkAccess($this->module_dir, 'export', $is_owner, $this->acltype, $in_group);
5549 5549
             case 'import':
5550 5550
 				/**
5551 5551
                 return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype);
5552 5552
 				*/
5553
-    			return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype, $in_group);
5553
+    			return ACLController::checkAccess($this->module_dir, 'import', true, $this->acltype, $in_group);
5554 5554
         }
5555 5555
         //if it is not one of the above views then it should be implemented on the page level
5556 5556
         return true;
@@ -5566,12 +5566,12 @@  discard block
 block discarded – undo
5566 5566
     {
5567 5567
         if (isset($this->field_defs['assigned_user_id']))
5568 5568
         {
5569
-            return $returnFieldName? 'assigned_user_id': $this->assigned_user_id;
5569
+            return $returnFieldName ? 'assigned_user_id' : $this->assigned_user_id;
5570 5570
         }
5571 5571
 
5572 5572
         if (isset($this->field_defs['created_by']))
5573 5573
         {
5574
-            return $returnFieldName? 'created_by': $this->created_by;
5574
+            return $returnFieldName ? 'created_by' : $this->created_by;
5575 5575
         }
5576 5576
 
5577 5577
         return '';
@@ -5586,7 +5586,7 @@  discard block
 block discarded – undo
5586 5586
     function isOwner($user_id)
5587 5587
     {
5588 5588
         //if we don't have an id we must be the owner as we are creating it
5589
-        if(!isset($this->id))
5589
+        if (!isset($this->id))
5590 5590
         {
5591 5591
             return true;
5592 5592
         }
@@ -5597,13 +5597,13 @@  discard block
 block discarded – undo
5597 5597
             }
5598 5598
             return false;
5599 5599
         } elseif (isset($this->assigned_user_id)) {
5600
-            if($this->assigned_user_id == $user_id) return true;
5600
+            if ($this->assigned_user_id == $user_id) return true;
5601 5601
             return false;
5602 5602
         }
5603 5603
         else
5604 5604
         {
5605 5605
             //other wise if there is a created_by that is the owner
5606
-            if(isset($this->created_by) && $this->created_by == $user_id)
5606
+            if (isset($this->created_by) && $this->created_by == $user_id)
5607 5607
             {
5608 5608
                 return true;
5609 5609
             }
@@ -5618,11 +5618,11 @@  discard block
 block discarded – undo
5618 5618
     */
5619 5619
     function getOwnerWhere($user_id)
5620 5620
     {
5621
-        if(isset($this->field_defs['assigned_user_id']))
5621
+        if (isset($this->field_defs['assigned_user_id']))
5622 5622
         {
5623 5623
             return " $this->table_name.assigned_user_id ='$user_id' ";
5624 5624
         }
5625
-        if(isset($this->field_defs['created_by']))
5625
+        if (isset($this->field_defs['created_by']))
5626 5626
         {
5627 5627
             return " $this->table_name.created_by ='$user_id' ";
5628 5628
         }
@@ -5639,7 +5639,7 @@  discard block
 block discarded – undo
5639 5639
     function listviewACLHelper()
5640 5640
     {
5641 5641
         $array_assign = array();
5642
-        if($this->ACLAccess('DetailView'))
5642
+        if ($this->ACLAccess('DetailView'))
5643 5643
         {
5644 5644
             $array_assign['MAIN'] = 'a';
5645 5645
         }
@@ -5655,27 +5655,27 @@  discard block
 block discarded – undo
5655 5655
     *
5656 5656
     * @return array of fields with id, name, access and category
5657 5657
     */
5658
-    function toArray($dbOnly = false, $stringOnly = false, $upperKeys=false)
5658
+    function toArray($dbOnly = false, $stringOnly = false, $upperKeys = false)
5659 5659
     {
5660 5660
         static $cache = array();
5661 5661
         $arr = array();
5662 5662
 
5663
-        foreach($this->field_defs as $field=>$data)
5663
+        foreach ($this->field_defs as $field=>$data)
5664 5664
         {
5665
-            if( !$dbOnly || !isset($data['source']) || $data['source'] == 'db')
5666
-            if(!$stringOnly || is_string($this->$field))
5667
-            if($upperKeys)
5665
+            if (!$dbOnly || !isset($data['source']) || $data['source'] == 'db')
5666
+            if (!$stringOnly || is_string($this->$field))
5667
+            if ($upperKeys)
5668 5668
             {
5669
-                                if(!isset($cache[$field])){
5669
+                                if (!isset($cache[$field])) {
5670 5670
                                     $cache[$field] = strtoupper($field);
5671 5671
                                 }
5672 5672
                 $arr[$cache[$field]] = $this->$field;
5673 5673
             }
5674 5674
             else
5675 5675
             {
5676
-                if(isset($this->$field)){
5676
+                if (isset($this->$field)) {
5677 5677
                     $arr[$field] = $this->$field;
5678
-                }else{
5678
+                } else {
5679 5679
                     $arr[$field] = '';
5680 5680
                 }
5681 5681
             }
@@ -5690,7 +5690,7 @@  discard block
 block discarded – undo
5690 5690
     */
5691 5691
     function fromArray($arr)
5692 5692
     {
5693
-        foreach($arr as $name=>$value)
5693
+        foreach ($arr as $name=>$value)
5694 5694
         {
5695 5695
             $this->$name = $value;
5696 5696
         }
@@ -5704,7 +5704,7 @@  discard block
 block discarded – undo
5704 5704
      */
5705 5705
     public function convertRow($row)
5706 5706
     {
5707
-        foreach($this->field_defs as $name => $fieldDef)
5707
+        foreach ($this->field_defs as $name => $fieldDef)
5708 5708
 		{
5709 5709
 		    // skip empty fields and non-db fields
5710 5710
             if (isset($name) && !empty($row[$name])) {
@@ -5750,7 +5750,7 @@  discard block
 block discarded – undo
5750 5750
 
5751 5751
         $this->fill_in_additional_list_fields();
5752 5752
 
5753
-        if($this->hasCustomFields())$this->custom_fields->fill_relationships();
5753
+        if ($this->hasCustomFields())$this->custom_fields->fill_relationships();
5754 5754
         $this->call_custom_logic("process_record");
5755 5755
     }
5756 5756
 
@@ -5769,7 +5769,7 @@  discard block
 block discarded – undo
5769 5769
     *
5770 5770
     * Internal function do not override.
5771 5771
     */
5772
-   function create_qualified_order_by( $order_by, $qualify)
5772
+   function create_qualified_order_by($order_by, $qualify)
5773 5773
    {	// if the column is empty, but the sort order is defined, the value will throw an error, so do not proceed if no order by is given
5774 5774
     if (empty($order_by))
5775 5775
     {
@@ -5778,10 +5778,10 @@  discard block
 block discarded – undo
5778 5778
     $order_by_clause = " ORDER BY ";
5779 5779
     $tmp = explode(",", $order_by);
5780 5780
     $comma = ' ';
5781
-    foreach ( $tmp as $stmp)
5781
+    foreach ($tmp as $stmp)
5782 5782
     {
5783
-        $stmp = (substr_count($stmp, ".") > 0?trim($stmp):"$qualify." . trim($stmp));
5784
-        $order_by_clause .= $comma . $stmp;
5783
+        $stmp = (substr_count($stmp, ".") > 0 ? trim($stmp) : "$qualify.".trim($stmp));
5784
+        $order_by_clause .= $comma.$stmp;
5785 5785
         $comma = ", ";
5786 5786
     }
5787 5787
     return $order_by_clause;
@@ -5801,16 +5801,16 @@  discard block
 block discarded – undo
5801 5801
             $street_field_2 = $street_field.'_2';
5802 5802
             $street_field_3 = $street_field.'_3';
5803 5803
             $street_field_4 = $street_field.'_4';
5804
-            if ( isset($this->$street_field_2)) {
5805
-                $this->$street_field .= "\n". $this->$street_field_2;
5804
+            if (isset($this->$street_field_2)) {
5805
+                $this->$street_field .= "\n".$this->$street_field_2;
5806 5806
                 unset($this->$street_field_2);
5807 5807
             }
5808
-            if ( isset($this->$street_field_3)) {
5809
-                $this->$street_field .= "\n". $this->$street_field_3;
5808
+            if (isset($this->$street_field_3)) {
5809
+                $this->$street_field .= "\n".$this->$street_field_3;
5810 5810
                 unset($this->$street_field_3);
5811 5811
             }
5812
-            if ( isset($this->$street_field_4)) {
5813
-                $this->$street_field .= "\n". $this->$street_field_4;
5812
+            if (isset($this->$street_field_4)) {
5813
+                $this->$street_field .= "\n".$this->$street_field_4;
5814 5814
                 unset($this->$street_field_4);
5815 5815
             }
5816 5816
             $this->$street_field = trim($this->$street_field, "\n");
@@ -5819,7 +5819,7 @@  discard block
 block discarded – undo
5819 5819
 
5820 5820
     protected function getEncryptKey()
5821 5821
     {
5822
-        if(empty(self::$field_key)) {
5822
+        if (empty(self::$field_key)) {
5823 5823
             self::$field_key = blowfishGetKey('encrypt_field');
5824 5824
         }
5825 5825
         return self::$field_key;
@@ -5843,7 +5843,7 @@  discard block
 block discarded – undo
5843 5843
  */
5844 5844
     function decrypt_after_retrieve($value)
5845 5845
     {
5846
-        if(empty($value)) return $value; // no need to decrypt empty
5846
+        if (empty($value)) return $value; // no need to decrypt empty
5847 5847
         require_once("include/utils/encryption_utils.php");
5848 5848
         return blowfishDecode($this->getEncryptKey(), $value);
5849 5849
     }
@@ -5852,19 +5852,19 @@  discard block
 block discarded – undo
5852 5852
     * Moved from save() method, functionality is the same, but this is intended to handle
5853 5853
     * Optimistic locking functionality.
5854 5854
     */
5855
-    private function _checkOptimisticLocking($action, $isUpdate){
5856
-        if($this->optimistic_lock && !isset($_SESSION['o_lock_fs'])){
5857
-            if(isset($_SESSION['o_lock_id']) && $_SESSION['o_lock_id'] == $this->id && $_SESSION['o_lock_on'] == $this->object_name)
5855
+    private function _checkOptimisticLocking($action, $isUpdate) {
5856
+        if ($this->optimistic_lock && !isset($_SESSION['o_lock_fs'])) {
5857
+            if (isset($_SESSION['o_lock_id']) && $_SESSION['o_lock_id'] == $this->id && $_SESSION['o_lock_on'] == $this->object_name)
5858 5858
             {
5859
-                if($action == 'Save' && $isUpdate && isset($this->modified_user_id) && $this->has_been_modified_since($_SESSION['o_lock_dm'], $this->modified_user_id))
5859
+                if ($action == 'Save' && $isUpdate && isset($this->modified_user_id) && $this->has_been_modified_since($_SESSION['o_lock_dm'], $this->modified_user_id))
5860 5860
                 {
5861 5861
                     $_SESSION['o_lock_class'] = get_class($this);
5862 5862
                     $_SESSION['o_lock_module'] = $this->module_dir;
5863 5863
                     $_SESSION['o_lock_object'] = $this->toArray();
5864 5864
                     $saveform = "<form name='save' id='save' method='POST'>";
5865
-                    foreach($_POST as $key=>$arg)
5865
+                    foreach ($_POST as $key=>$arg)
5866 5866
                     {
5867
-                        $saveform .= "<input type='hidden' name='". addslashes($key) ."' value='". addslashes($arg) ."'>";
5867
+                        $saveform .= "<input type='hidden' name='".addslashes($key)."' value='".addslashes($arg)."'>";
5868 5868
                     }
5869 5869
                     $saveform .= "</form><script>document.getElementById('save').submit();</script>";
5870 5870
                     $_SESSION['o_lock_save'] = $saveform;
@@ -5881,20 +5881,20 @@  discard block
 block discarded – undo
5881 5881
         }
5882 5882
         else
5883 5883
         {
5884
-            if(isset($_SESSION['o_lock_object']))	{ unset ($_SESSION['o_lock_object']); }
5885
-            if(isset($_SESSION['o_lock_id']))		{ unset ($_SESSION['o_lock_id']); }
5886
-            if(isset($_SESSION['o_lock_dm']))		{ unset ($_SESSION['o_lock_dm']); }
5887
-            if(isset($_SESSION['o_lock_fs']))		{ unset ($_SESSION['o_lock_fs']); }
5888
-            if(isset($_SESSION['o_lock_save']))		{ unset ($_SESSION['o_lock_save']); }
5884
+            if (isset($_SESSION['o_lock_object'])) { unset ($_SESSION['o_lock_object']); }
5885
+            if (isset($_SESSION['o_lock_id'])) { unset ($_SESSION['o_lock_id']); }
5886
+            if (isset($_SESSION['o_lock_dm'])) { unset ($_SESSION['o_lock_dm']); }
5887
+            if (isset($_SESSION['o_lock_fs'])) { unset ($_SESSION['o_lock_fs']); }
5888
+            if (isset($_SESSION['o_lock_save'])) { unset ($_SESSION['o_lock_save']); }
5889 5889
         }
5890 5890
     }
5891 5891
 
5892 5892
     /**
5893 5893
     * Send assignment notifications and invites for meetings and calls
5894 5894
     */
5895
-    private function _sendNotifications($check_notify){
5896
-        if($check_notify || (isset($this->notify_inworkflow) && $this->notify_inworkflow == true) // cn: bug 5795 - no invites sent to Contacts, and also bug 25995, in workflow, it will set the notify_on_save=true.
5897
-           && !$this->isOwner($this->created_by) )  // cn: bug 42727 no need to send email to owner (within workflow)
5895
+    private function _sendNotifications($check_notify) {
5896
+        if ($check_notify || (isset($this->notify_inworkflow) && $this->notify_inworkflow == true) // cn: bug 5795 - no invites sent to Contacts, and also bug 25995, in workflow, it will set the notify_on_save=true.
5897
+           && !$this->isOwner($this->created_by))  // cn: bug 42727 no need to send email to owner (within workflow)
5898 5898
         {
5899 5899
             $admin = new Administration();
5900 5900
             $admin->retrieveSettings();
@@ -5905,7 +5905,7 @@  discard block
 block discarded – undo
5905 5905
                 $GLOBALS['log']->info("Notifications: user assignment has changed, checking if user receives notifications");
5906 5906
                 $sendNotifications = true;
5907 5907
             }
5908
-            elseif(isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1)
5908
+            elseif (isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1)
5909 5909
             {
5910 5910
                 // cn: bug 5795 Send Invites failing for Contacts
5911 5911
                 $sendNotifications = true;
@@ -5916,7 +5916,7 @@  discard block
 block discarded – undo
5916 5916
             }
5917 5917
 
5918 5918
 
5919
-            if($sendNotifications == true)
5919
+            if ($sendNotifications == true)
5920 5920
             {
5921 5921
                 $notify_list = $this->get_notification_recipients();
5922 5922
                 foreach ($notify_list as $notify_user)
@@ -5977,10 +5977,10 @@  discard block
 block discarded – undo
5977 5977
 
5978 5978
         $cache_key = "load_cached_array.$module_dir.$module.$key";
5979 5979
         $result = sugar_cache_retrieve($cache_key);
5980
-        if(!empty($result))
5980
+        if (!empty($result))
5981 5981
         {
5982 5982
         	// Use SugarCache::EXTERNAL_CACHE_NULL_VALUE to store null values in the cache.
5983
-        	if($result == SugarCache::EXTERNAL_CACHE_NULL_VALUE)
5983
+        	if ($result == SugarCache::EXTERNAL_CACHE_NULL_VALUE)
5984 5984
         	{
5985 5985
         		return null;
5986 5986
         	}
@@ -5988,16 +5988,16 @@  discard block
 block discarded – undo
5988 5988
             return $result;
5989 5989
         }
5990 5990
 
5991
-        if(file_exists('modules/'.$module_dir.'/'.$fileName))
5991
+        if (file_exists('modules/'.$module_dir.'/'.$fileName))
5992 5992
         {
5993 5993
             // If the data was not loaded, try loading again....
5994
-            if(!isset($moduleDefs[$module]))
5994
+            if (!isset($moduleDefs[$module]))
5995 5995
             {
5996 5996
                 include('modules/'.$module_dir.'/'.$fileName);
5997 5997
                 $moduleDefs[$module] = $fields_array;
5998 5998
             }
5999 5999
             // Now that we have tried loading, make sure it was loaded
6000
-            if(empty($moduleDefs[$module]) || empty($moduleDefs[$module][$module][$key]))
6000
+            if (empty($moduleDefs[$module]) || empty($moduleDefs[$module][$module][$key]))
6001 6001
             {
6002 6002
                 // It was not loaded....  Fail.  Cache null to prevent future repeats of this calculation
6003 6003
 				sugar_cache_put($cache_key, SugarCache::EXTERNAL_CACHE_NULL_VALUE);
@@ -6022,7 +6022,7 @@  discard block
 block discarded – undo
6022 6022
      */
6023 6023
     public function getACLCategory()
6024 6024
     {
6025
-        return !empty($this->acl_category)?$this->acl_category:$this->module_dir;
6025
+        return !empty($this->acl_category) ? $this->acl_category : $this->module_dir;
6026 6026
     }
6027 6027
 
6028 6028
     /**
@@ -6071,7 +6071,7 @@  discard block
 block discarded – undo
6071 6071
             'select' => '',
6072 6072
             'join' => ''
6073 6073
         );
6074
-        if(isset($this->custom_fields))
6074
+        if (isset($this->custom_fields))
6075 6075
         {
6076 6076
             $result = $this->custom_fields->getJOIN($expandedList, $includeRelates, $where);
6077 6077
         }
@@ -6093,7 +6093,7 @@  discard block
 block discarded – undo
6093 6093
                 // walk through all currency-related fields
6094 6094
                 foreach ($this->field_defs as $this_field) {
6095 6095
                     if (isset($this_field['type']) && $this_field['type'] == 'relate'
6096
-                        && isset($this_field['module'])  && $this_field['module'] == 'Currencies'
6096
+                        && isset($this_field['module']) && $this_field['module'] == 'Currencies'
6097 6097
                         && isset($this_field['id_name']) && $this_field['id_name'] == 'currency_id') {
6098 6098
                         // populate related properties manually
6099 6099
                         $this_property = $this_field['name'];
Please login to merge, or discard this patch.
Braces   +338 added lines, -325 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
2
+if(!defined('sugarEntry') || !sugarEntry) {
3
+    die('Not A Valid Entry Point');
4
+}
3 5
 /*********************************************************************************
4 6
  * SugarCRM Community Edition is a customer relationship management program developed by
5 7
  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
@@ -315,8 +317,9 @@  discard block
 block discarded – undo
315 317
         global  $dictionary, $current_user;
316 318
         static $loaded_defs = array();
317 319
         $this->db = DBManagerFactory::getInstance();
318
-        if (empty($this->module_name))
319
-            $this->module_name = $this->module_dir;
320
+        if (empty($this->module_name)) {
321
+                    $this->module_name = $this->module_dir;
322
+        }
320 323
         if((false == $this->disable_vardefs && empty($loaded_defs[$this->object_name])) || !empty($GLOBALS['reload_vardefs']))
321 324
         {
322 325
             VardefManager::loadVardef($this->module_dir, $this->object_name);
@@ -339,12 +342,15 @@  discard block
 block discarded – undo
339 342
                 $this->setupCustomFields($this->module_dir);
340 343
             }
341 344
             //load up field_arrays from CacheHandler;
342
-            if(empty($this->list_fields))
343
-                $this->list_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'list_fields');
344
-            if(empty($this->column_fields))
345
-                $this->column_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'column_fields');
346
-            if(empty($this->required_fields))
347
-                $this->required_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'required_fields');
345
+            if(empty($this->list_fields)) {
346
+                            $this->list_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'list_fields');
347
+            }
348
+            if(empty($this->column_fields)) {
349
+                            $this->column_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'column_fields');
350
+            }
351
+            if(empty($this->required_fields)) {
352
+                            $this->required_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'required_fields');
353
+            }
348 354
 
349 355
             if(isset($GLOBALS['dictionary'][$this->object_name]) && !$this->disable_vardefs)
350 356
             {
@@ -361,8 +367,7 @@  discard block
 block discarded – undo
361 367
             $loaded_defs[$this->object_name]['required_fields'] =& $this->required_fields;
362 368
             $loaded_defs[$this->object_name]['field_name_map'] =& $this->field_name_map;
363 369
             $loaded_defs[$this->object_name]['field_defs'] =& $this->field_defs;
364
-        }
365
-        else
370
+        } else
366 371
         {
367 372
             $this->column_fields =& $loaded_defs[$this->object_name]['column_fields'] ;
368 373
             $this->list_fields =& $loaded_defs[$this->object_name]['list_fields'];
@@ -400,8 +405,9 @@  discard block
 block discarded – undo
400 405
      */
401 406
     function getObjectName()
402 407
     {
403
-        if ($this->object_name)
404
-            return $this->object_name;
408
+        if ($this->object_name) {
409
+                    return $this->object_name;
410
+        }
405 411
 
406 412
         // This is a quick way out. The generated metadata files have the table name
407 413
         // as the key. The correct way to do this is to override this function
@@ -459,8 +465,7 @@  discard block
 block discarded – undo
459 465
         if (isset($dictionary[$this->getObjectName()]['audited']))
460 466
         {
461 467
             return $dictionary[$this->getObjectName()]['audited'];
462
-        }
463
-        else
468
+        } else
464 469
         {
465 470
             return false;
466 471
         }
@@ -598,8 +603,9 @@  discard block
 block discarded – undo
598 603
      */
599 604
     function getFieldDefinition($name)
600 605
     {
601
-        if ( !isset($this->field_defs[$name]) )
602
-            return false;
606
+        if ( !isset($this->field_defs[$name]) ) {
607
+                    return false;
608
+        }
603 609
 
604 610
         return $this->field_defs[$name];
605 611
     }
@@ -657,8 +663,9 @@  discard block
 block discarded – undo
657 663
      */
658 664
     public function unPopulateDefaultValues()
659 665
     {
660
-        if ( !is_array($this->field_defs) )
661
-            return;
666
+        if ( !is_array($this->field_defs) ) {
667
+                    return;
668
+        }
662 669
 
663 670
         foreach ($this->field_defs as $field => $value) {
664 671
 		    if( !empty($this->$field)
@@ -698,8 +705,9 @@  discard block
 block discarded – undo
698 705
     }
699 706
 
700 707
     function populateDefaultValues($force=false){
701
-        if ( !is_array($this->field_defs) )
702
-            return;
708
+        if ( !is_array($this->field_defs) ) {
709
+                    return;
710
+        }
703 711
         foreach($this->field_defs as $field=>$value){
704 712
             if((isset($value['default']) || !empty($value['display_default'])) && ($force || empty($this->$field))){
705 713
                 $type = $value['type'];
@@ -717,10 +725,11 @@  discard block
 block discarded – undo
717 725
                         }
718 726
                         break;
719 727
                     case 'multienum':
720
-                        if(empty($value['default']) && !empty($value['display_default']))
721
-                            $this->$field = $value['display_default'];
722
-                        else
723
-                            $this->$field = $value['default'];
728
+                        if(empty($value['default']) && !empty($value['display_default'])) {
729
+                                                    $this->$field = $value['display_default'];
730
+                        } else {
731
+                                                    $this->$field = $value['default'];
732
+                        }
724 733
                         break;
725 734
                     case 'bool':
726 735
                     	if(isset($this->$field)){
@@ -770,8 +779,7 @@  discard block
 block discarded – undo
770 779
         {
771 780
             $GLOBALS['log']->fatal("removeRelationshipMeta: Metadata for table ".$tablename. " does not exist");
772 781
             display_notice("meta data absent for table ".$tablename." keyed to $key ");
773
-        }
774
-        else
782
+        } else
775 783
         {
776 784
             if (isset($dictionary[$key]['relationships']))
777 785
             {
@@ -821,8 +829,7 @@  discard block
 block discarded – undo
821 829
             if($iscustom)
822 830
             {
823 831
                 $filename='custom/modules/' . $module_dir . '/Ext/Vardefs/vardefs.ext.php';
824
-            }
825
-            else
832
+            } else
826 833
             {
827 834
                 if ($key == 'User')
828 835
                 {
@@ -830,8 +837,7 @@  discard block
 block discarded – undo
830 837
                     // this must be done because the Employees/vardefs.php does an include_once on
831 838
                     // Users/vardefs.php
832 839
                     $filename='modules/Users/vardefs.php';
833
-                }
834
-                else
840
+                } else
835 841
                 {
836 842
                     $filename='modules/'. $module_dir . '/vardefs.php';
837 843
                 }
@@ -845,8 +851,7 @@  discard block
 block discarded – undo
845 851
                 {
846 852
                     $dictionary = $GLOBALS['dictionary'];
847 853
                 }
848
-            }
849
-            else
854
+            } else
850 855
             {
851 856
                 $GLOBALS['log']->debug("createRelationshipMeta: no metadata file found" . $filename);
852 857
                 return;
@@ -857,8 +862,7 @@  discard block
 block discarded – undo
857 862
         {
858 863
             $GLOBALS['log']->fatal("createRelationshipMeta: Metadata for table ".$tablename. " does not exist");
859 864
             display_notice("meta data absent for table ".$tablename." keyed to $key ");
860
-        }
861
-        else
865
+        } else
862 866
         {
863 867
             if (isset($dictionary[$key]['relationships']))
864 868
             {
@@ -884,8 +888,7 @@  discard block
 block discarded – undo
884 888
                     if (Relationship::exists($rel_name,$db))
885 889
                     {
886 890
                         $GLOBALS['log']->debug('Skipping, reltionship already exists '.$rel_name);
887
-                    }
888
-                    else
891
+                    } else
889 892
                     {
890 893
                         $seed = BeanFactory::getBean("Relationships");
891 894
                         $keys = array_keys($seed->field_defs);
@@ -895,12 +898,10 @@  discard block
 block discarded – undo
895 898
                             if ($key == "id")
896 899
                             {
897 900
                                 $toInsert[$key] = create_guid();
898
-                            }
899
-                            else if ($key == "relationship_name")
901
+                            } else if ($key == "relationship_name")
900 902
                             {
901 903
                                 $toInsert[$key] = $rel_name;
902
-                            }
903
-                            else if (isset($rel_def[$key]))
904
+                            } else if (isset($rel_def[$key]))
904 905
                             {
905 906
                                 $toInsert[$key] = $rel_def[$key];
906 907
                             }
@@ -916,8 +917,7 @@  discard block
 block discarded – undo
916 917
                         $db->query($insert_string, true);
917 918
                     }
918 919
                 }
919
-            }
920
-            else
920
+            } else
921 921
             {
922 922
                 //todo
923 923
                 //log informational message stating no relationships meta was set for this bean.
@@ -986,10 +986,11 @@  discard block
 block discarded – undo
986 986
             //if rel_name is provided, search the fieldef array keys by name.
987 987
             if (isset($fieldDefs[$rel_name]['type']) && $fieldDefs[$rel_name]['type'] == 'link')
988 988
             {
989
-                if ($class == "Link2")
990
-                    $this->$rel_name = new $class($rel_name, $this);
991
-                else
992
-                    $this->$rel_name = new $class($fieldDefs[$rel_name]['relationship'], $this, $fieldDefs[$rel_name]);
989
+                if ($class == "Link2") {
990
+                                    $this->$rel_name = new $class($rel_name, $this);
991
+                } else {
992
+                                    $this->$rel_name = new $class($fieldDefs[$rel_name]['relationship'], $this, $fieldDefs[$rel_name]);
993
+                }
993 994
 
994 995
                 if (empty($this->$rel_name) ||
995 996
                         (method_exists($this->$rel_name, "loadedSuccesfully") && !$this->$rel_name->loadedSuccesfully()))
@@ -1048,8 +1049,9 @@  discard block
 block discarded – undo
1048 1049
     function get_linked_beans($field_name,$bean_name = '', $order_by = '', $begin_index = 0, $end_index = -1, $deleted=0, $optional_where="")
1049 1050
     {
1050 1051
         //if bean_name is Case then use aCase
1051
-        if($bean_name=="Case")
1052
-            $bean_name = "aCase";
1052
+        if($bean_name=="Case") {
1053
+                    $bean_name = "aCase";
1054
+        }
1053 1055
 
1054 1056
         if($this->load_relationship($field_name)) {
1055 1057
             if ($this->$field_name instanceof Link) {
@@ -1057,19 +1059,20 @@  discard block
 block discarded – undo
1057 1059
                 return array_values($this->$field_name->getBeans(new $bean_name(), $order_by, $begin_index, $end_index, $deleted, $optional_where));
1058 1060
             } else {
1059 1061
                 // Link2 style
1060
-                if ($end_index != -1 || !empty($deleted) || !empty($optional_where) || !empty($order_by))
1061
-                    return array_values($this->$field_name->getBeans(array(
1062
+                if ($end_index != -1 || !empty($deleted) || !empty($optional_where) || !empty($order_by)) {
1063
+                                    return array_values($this->$field_name->getBeans(array(
1062 1064
                         'where' => $optional_where,
1063 1065
                         'deleted' => $deleted,
1064 1066
                         'limit' => ($end_index - $begin_index),
1065 1067
                         'order_by' => $order_by
1066 1068
                     )));
1067
-                else
1068
-                    return array_values($this->$field_name->getBeans());
1069
+                } else {
1070
+                                    return array_values($this->$field_name->getBeans());
1071
+                }
1069 1072
             }
1073
+        } else {
1074
+                    return array();
1070 1075
         }
1071
-        else
1072
-            return array();
1073 1076
     }
1074 1077
 
1075 1078
     /**
@@ -1131,8 +1134,7 @@  discard block
 block discarded – undo
1131 1134
                            || is_bool($value_array['importable']) && $value_array['importable'] == true)) {
1132 1135
                         $importableFields[$key]=$value_array;
1133 1136
                     }
1134
-                }
1135
-                else {
1137
+                } else {
1136 1138
 
1137 1139
                     //Expose the cooresponding id field of a relate field if it is only defined as a link so that users can relate records by id during import
1138 1140
                     if( isset($value_array['type']) && ($value_array['type'] == 'relate') && isset($value_array['id_name']) )
@@ -1217,8 +1219,7 @@  discard block
 block discarded – undo
1217 1219
             if ($this->load_relationship($name))
1218 1220
             {
1219 1221
                 $this->$name->delete($id);
1220
-            }
1221
-            else
1222
+            } else
1222 1223
             {
1223 1224
                 $GLOBALS['log']->fatal("error loading relationship $name");
1224 1225
             }
@@ -1239,8 +1240,7 @@  discard block
 block discarded – undo
1239 1240
         {
1240 1241
             $GLOBALS['log']->fatal("create_tables: Metadata for table ".$this->table_name. " does not exist");
1241 1242
             display_notice("meta data absent for table ".$this->table_name." keyed to $key ");
1242
-        }
1243
-        else
1243
+        } else
1244 1244
         {
1245 1245
             if(!$this->db->tableExists($this->table_name))
1246 1246
             {
@@ -1248,12 +1248,11 @@  discard block
 block discarded – undo
1248 1248
                     if($this->bean_implements('ACL')){
1249 1249
                         if(!empty($this->acltype)){
1250 1250
                             ACLAction::addActions($this->getACLCategory(), $this->acltype);
1251
-                        }else{
1251
+                        } else{
1252 1252
                             ACLAction::addActions($this->getACLCategory());
1253 1253
                         }
1254 1254
                     }
1255
-            }
1256
-            else
1255
+            } else
1257 1256
             {
1258 1257
                 echo "Table already exists : $this->table_name<br>";
1259 1258
             }
@@ -1281,10 +1280,13 @@  discard block
 block discarded – undo
1281 1280
             $GLOBALS['log']->fatal("drop_tables: Metadata for table ".$this->table_name. " does not exist");
1282 1281
             echo "meta data absent for table ".$this->table_name."<br>\n";
1283 1282
         } else {
1284
-            if(empty($this->table_name))return;
1285
-            if ($this->db->tableExists($this->table_name))
1286
-
1283
+            if(empty($this->table_name)) {
1284
+                return;
1285
+            }
1286
+            if ($this->db->tableExists($this->table_name)) {
1287
+            
1287 1288
                 $this->db->dropTable($this);
1289
+            }
1288 1290
             if ($this->db->tableExists($this->table_name. '_cstm'))
1289 1291
             {
1290 1292
                 $this->db->dropTableName($this->table_name. '_cstm');
@@ -1322,8 +1324,9 @@  discard block
 block discarded – undo
1322 1324
             if (isset($def['type'])) {
1323 1325
                 $type=$def['type'];
1324 1326
             }
1325
-            if(isset($def['dbType']))
1326
-                $type .= $def['dbType'];
1327
+            if(isset($def['dbType'])) {
1328
+                            $type .= $def['dbType'];
1329
+            }
1327 1330
 
1328 1331
             if($def['type'] == 'html' || $def['type'] == 'longhtml') {
1329 1332
                 $this->$key = SugarCleaner::cleanHtml($this->$key, true);
@@ -1373,7 +1376,9 @@  discard block
 block discarded – undo
1373 1376
 
1374 1377
         $this->_checkOptimisticLocking($action, $isUpdate);
1375 1378
 
1376
-        if(!empty($this->modified_by_name)) $this->old_modified_by_name = $this->modified_by_name;
1379
+        if(!empty($this->modified_by_name)) {
1380
+            $this->old_modified_by_name = $this->modified_by_name;
1381
+        }
1377 1382
         if($this->update_modified_by)
1378 1383
         {
1379 1384
             $this->modified_user_id = 1;
@@ -1384,8 +1389,9 @@  discard block
 block discarded – undo
1384 1389
                 $this->modified_by_name = $current_user->user_name;
1385 1390
             }
1386 1391
         }
1387
-        if ($this->deleted != 1)
1388
-            $this->deleted = 0;
1392
+        if ($this->deleted != 1) {
1393
+                    $this->deleted = 0;
1394
+        }
1389 1395
         if(!$isUpdate)
1390 1396
         {
1391 1397
             if (empty($this->date_entered))
@@ -1607,7 +1613,7 @@  discard block
 block discarded – undo
1607 1613
 
1608 1614
                 if(!$notify_mail->Send()) {
1609 1615
                     $GLOBALS['log']->fatal("Notifications: error sending e-mail (method: {$notify_mail->Mailer}), (error: {$notify_mail->ErrorInfo})");
1610
-                }else{
1616
+                } else{
1611 1617
                     $GLOBALS['log']->info("Notifications: e-mail successfully sent");
1612 1618
                 }
1613 1619
             }
@@ -1646,8 +1652,7 @@  discard block
 block discarded – undo
1646 1652
         $xtpl = new XTemplate(get_notify_template_file($current_language));
1647 1653
         if($this->module_dir == "Cases") {
1648 1654
             $template_name = "Case"; //we should use Case, you can refer to the en_us.notify_template.html.
1649
-        }
1650
-        else {
1655
+        } else {
1651 1656
             $template_name = $beanList[$this->module_dir]; //bug 20637, in workflow this->object_name = strange chars.
1652 1657
         }
1653 1658
 
@@ -1745,8 +1750,7 @@  discard block
 block discarded – undo
1745 1750
             // if we should use relation data from properties (for REQUEST-independent calls)
1746 1751
             $rel_id = isset($this->new_rel_id) ? $this->new_rel_id : '';
1747 1752
             $rel_link = isset($this->new_rel_relname) ? $this->new_rel_relname : '';
1748
-        }
1749
-        else
1753
+        } else
1750 1754
         {
1751 1755
             // if we should use relation data from REQUEST
1752 1756
             $rel_id = isset($_REQUEST['relate_id']) ? $_REQUEST['relate_id'] : '';
@@ -1765,8 +1769,7 @@  discard block
 block discarded – undo
1765 1769
             if ($isRelationshipLoaded && !empty($this->$rel_link) && $this->$rel_link->getRelationshipObject() && $this->$rel_link->getRelationshipObject()->getLHSModule() == $this->$rel_link->getRelationshipObject()->getRHSModule() )
1766 1770
             {
1767 1771
                 $new_rel_link = $this->$rel_link->getRelationshipObject()->getLHSLink();
1768
-            }
1769
-            else
1772
+            } else
1770 1773
             {
1771 1774
                 //Try to find the link in this bean based on the relationship
1772 1775
                 foreach ($this->field_defs as $key => $def)
@@ -1800,7 +1803,9 @@  discard block
 block discarded – undo
1800 1803
             foreach ($this->relationship_fields as $id => $rel_name)
1801 1804
             {
1802 1805
 
1803
-                if (in_array($id, $exclude)) continue;
1806
+                if (in_array($id, $exclude)) {
1807
+                    continue;
1808
+                }
1804 1809
 
1805 1810
                 if(!empty($this->$id))
1806 1811
                 {
@@ -1853,8 +1858,10 @@  discard block
 block discarded – undo
1853 1858
         foreach ($this->field_defs as $def)
1854 1859
         {
1855 1860
             if ($def ['type'] == 'relate' && isset ($def ['id_name']) && isset ($def ['link']) && isset ($def['save'])) {
1856
-                if (in_array($def['id_name'], $exclude) || in_array($def['id_name'], $this->relationship_fields))
1857
-                    continue; // continue to honor the exclude array and exclude any relationships that will be handled by the relationship_fields mechanism
1861
+                if (in_array($def['id_name'], $exclude) || in_array($def['id_name'], $this->relationship_fields)) {
1862
+                                    continue;
1863
+                }
1864
+                // continue to honor the exclude array and exclude any relationships that will be handled by the relationship_fields mechanism
1858 1865
 
1859 1866
                 $linkField = $def ['link'];
1860 1867
                 if (isset($this->field_defs[$linkField])) {
@@ -1911,12 +1918,14 @@  discard block
 block discarded – undo
1911 1918
         {
1912 1919
             if (!empty($def['type']) && $def['type'] == "parent")
1913 1920
             {
1914
-                if (empty($def['type_name']) || empty($def['id_name']))
1915
-                    continue;
1921
+                if (empty($def['type_name']) || empty($def['id_name'])) {
1922
+                                    continue;
1923
+                }
1916 1924
                 $typeField = $def['type_name'];
1917 1925
                 $idField = $def['id_name'];
1918
-                if (in_array($idField, $exclude))
1919
-                    continue;
1926
+                if (in_array($idField, $exclude)) {
1927
+                                    continue;
1928
+                }
1920 1929
                 //Determine if the parent field has changed.
1921 1930
                 if (
1922 1931
                     //First check if the fetched row parent existed and now we no longer have one
@@ -2039,8 +2048,9 @@  discard block
 block discarded – undo
2039 2048
 	{
2040 2049
 		global $disable_date_format;
2041 2050
 		global $timedate;
2042
-		if (empty($timedate))
2043
-			$timedate=TimeDate::getInstance();
2051
+		if (empty($timedate)) {
2052
+					$timedate=TimeDate::getInstance();
2053
+		}
2044 2054
 
2045 2055
 		if(empty($this->field_defs))
2046 2056
 		{
@@ -2052,15 +2062,16 @@  discard block
 block discarded – undo
2052 2062
 			if(!isset($this->processed_dates_times[$field]))
2053 2063
 			{
2054 2064
 				$this->processed_dates_times[$field] = '1';
2055
-				if(empty($this->$field)) continue;
2065
+				if(empty($this->$field)) {
2066
+				    continue;
2067
+				}
2056 2068
 				if($field == 'date_modified' || $field == 'date_entered')
2057 2069
 				{
2058 2070
 					$this->$field = $this->db->fromConvert($this->$field, 'datetime');
2059 2071
 					if(empty($disable_date_format)) {
2060 2072
 						$this->$field = $timedate->to_display_date_time($this->$field);
2061 2073
 					}
2062
-				}
2063
-				elseif(isset($this->field_name_map[$field]['type']))
2074
+				} elseif(isset($this->field_name_map[$field]['type']))
2064 2075
 				{
2065 2076
 					$type = $this->field_name_map[$field]['type'];
2066 2077
 
@@ -2086,8 +2097,7 @@  discard block
 block discarded – undo
2086 2097
 									$this->$rel_field = $timedate->to_display_time($mergetime);
2087 2098
 								}
2088 2099
 							}
2089
-						}
2090
-						else
2100
+						} else
2091 2101
 						{
2092 2102
 							if(empty($disable_date_format)) {
2093 2103
 								$this->$field = $timedate->to_display_date($this->$field, false);
@@ -2098,8 +2108,7 @@  discard block
 block discarded – undo
2098 2108
 						if($this->$field == '0000-00-00 00:00:00')
2099 2109
 						{
2100 2110
 							$this->$field = '';
2101
-						}
2102
-						else
2111
+						} else
2103 2112
 						{
2104 2113
 							if(empty($disable_date_format)) {
2105 2114
 								$this->$field = $timedate->to_display_date_time($this->$field, true, true);
@@ -2188,7 +2197,9 @@  discard block
 block discarded – undo
2188 2197
             switch($def['type']) {
2189 2198
                 case 'datetime':
2190 2199
                 case 'datetimecombo':
2191
-                    if(empty($this->$field)) break;
2200
+                    if(empty($this->$field)) {
2201
+                        break;
2202
+                    }
2192 2203
                     if ($this->$field == 'NULL') {
2193 2204
                     	$this->$field = '';
2194 2205
                     	break;
@@ -2200,7 +2211,9 @@  discard block
 block discarded – undo
2200 2211
                     }
2201 2212
                     break;
2202 2213
                 case 'date':
2203
-                    if(empty($this->$field)) break;
2214
+                    if(empty($this->$field)) {
2215
+                        break;
2216
+                    }
2204 2217
                     if ($this->$field == 'NULL') {
2205 2218
                     	$this->$field = '';
2206 2219
                     	break;
@@ -2212,7 +2225,9 @@  discard block
 block discarded – undo
2212 2225
                     }
2213 2226
                     break;
2214 2227
                 case 'time':
2215
-                    if(empty($this->$field)) break;
2228
+                    if(empty($this->$field)) {
2229
+                        break;
2230
+                    }
2216 2231
                     if ($this->$field == 'NULL') {
2217 2232
                     	$this->$field = '';
2218 2233
                     	break;
@@ -2301,7 +2316,9 @@  discard block
 block discarded – undo
2301 2316
 
2302 2317
         $query .= $custom_join['join'];
2303 2318
         $query .= " WHERE $this->table_name.id = ".$this->db->quoted($id);
2304
-        if ($deleted) $query .= " AND $this->table_name.deleted=0";
2319
+        if ($deleted) {
2320
+            $query .= " AND $this->table_name.deleted=0";
2321
+        }
2305 2322
         $GLOBALS['log']->debug("Retrieve $this->object_name : ".$query);
2306 2323
         $result = $this->db->limitQuery($query,0,1,true, "Retrieving record by id $this->table_name:$id found ");
2307 2324
         if(empty($result))
@@ -2358,21 +2375,23 @@  discard block
 block discarded – undo
2358 2375
             if ($def [ 'type' ] == 'relate' && isset ( $def [ 'id_name'] ) && isset ( $def [ 'link'] ) && isset ( $def[ 'save' ])) {
2359 2376
                 if (isset($this->$key)) {
2360 2377
                     $this->rel_fields_before_value[$key]=$this->$key;
2361
-                    if (isset($this->$def [ 'id_name']))
2362
-                        $this->rel_fields_before_value[$def [ 'id_name']]=$this->$def [ 'id_name'];
2378
+                    if (isset($this->$def [ 'id_name'])) {
2379
+                                            $this->rel_fields_before_value[$def [ 'id_name']]=$this->$def [ 'id_name'];
2380
+                    }
2381
+                } else {
2382
+                                    $this->rel_fields_before_value[$key]=null;
2363 2383
                 }
2364
-                else
2365
-                    $this->rel_fields_before_value[$key]=null;
2366 2384
            }
2367 2385
         }
2368 2386
         if (isset($this->relationship_fields) && is_array($this->relationship_fields))
2369 2387
         {
2370 2388
             foreach ($this->relationship_fields as $rel_id=>$rel_name)
2371 2389
             {
2372
-                if (isset($this->$rel_id))
2373
-                    $this->rel_fields_before_value[$rel_id]=$this->$rel_id;
2374
-                else
2375
-                    $this->rel_fields_before_value[$rel_id]=null;
2390
+                if (isset($this->$rel_id)) {
2391
+                                    $this->rel_fields_before_value[$rel_id]=$this->$rel_id;
2392
+                } else {
2393
+                                    $this->rel_fields_before_value[$rel_id]=null;
2394
+                }
2376 2395
             }
2377 2396
         }
2378 2397
 
@@ -2398,8 +2417,9 @@  discard block
 block discarded – undo
2398 2417
         $nullvalue='';
2399 2418
         foreach($this->field_defs as $field=>$field_value)
2400 2419
         {
2401
-            if($field == 'user_preferences' && $this->module_dir == 'Users')
2402
-                continue;
2420
+            if($field == 'user_preferences' && $this->module_dir == 'Users') {
2421
+                            continue;
2422
+            }
2403 2423
             if(isset($row[$field]))
2404 2424
             {
2405 2425
                 $this->$field = $row[$field];
@@ -2407,8 +2427,7 @@  discard block
 block discarded – undo
2407 2427
                 if(!empty($row[$owner])){
2408 2428
                     $this->$owner = $row[$owner];
2409 2429
                 }
2410
-            }
2411
-            else
2430
+            } else
2412 2431
             {
2413 2432
                 $this->$field = $nullvalue;
2414 2433
             }
@@ -2452,10 +2471,11 @@  discard block
 block discarded – undo
2452 2471
         //handle distinct clause
2453 2472
         $star = '*';
2454 2473
         if(substr_count(strtolower($query), 'distinct')){
2455
-            if (!empty($this->seed) && !empty($this->seed->table_name ))
2456
-                $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2457
-            else
2458
-                $star = 'DISTINCT ' . $this->table_name . '.id';
2474
+            if (!empty($this->seed) && !empty($this->seed->table_name )) {
2475
+                            $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2476
+            } else {
2477
+                            $star = 'DISTINCT ' . $this->table_name . '.id';
2478
+            }
2459 2479
 
2460 2480
         }
2461 2481
 
@@ -2476,10 +2496,11 @@  discard block
 block discarded – undo
2476 2496
                 preg_match($pattern, $union_query, $matches);
2477 2497
                 if (!empty($matches)) {
2478 2498
                     if (stristr($matches[0], "distinct")) {
2479
-                        if (!empty($this->seed) && !empty($this->seed->table_name ))
2480
-                            $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2481
-                        else
2482
-                            $star = 'DISTINCT ' . $this->table_name . '.id';
2499
+                        if (!empty($this->seed) && !empty($this->seed->table_name )) {
2500
+                                                    $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2501
+                        } else {
2502
+                                                    $star = 'DISTINCT ' . $this->table_name . '.id';
2503
+                        }
2483 2504
                     }
2484 2505
                 } // if
2485 2506
                 $replacement = 'SELECT count(' . $star . ') c FROM ';
@@ -2529,7 +2550,7 @@  discard block
 block discarded – undo
2529 2550
             if(!empty($owner_where)){
2530 2551
                 if(empty($where)){
2531 2552
                     $where = $owner_where;
2532
-                }else{
2553
+                } else{
2533 2554
                     $where .= ' AND '.  $owner_where;
2534 2555
                 }
2535 2556
             }
@@ -2550,14 +2571,14 @@  discard block
 block discarded – undo
2550 2571
     */
2551 2572
     public function process_order_by($order_by, $submodule = null, $suppress_table_name = false)
2552 2573
     {
2553
-        if (empty($order_by))
2554
-            return $order_by;
2574
+        if (empty($order_by)) {
2575
+                    return $order_by;
2576
+        }
2555 2577
         //submodule is empty,this is for list object in focus
2556 2578
         if (empty($submodule))
2557 2579
         {
2558 2580
             $bean_queried = $this;
2559
-        }
2560
-        else
2581
+        } else
2561 2582
         {
2562 2583
             //submodule is set, so this is for subpanel, use submodule
2563 2584
             $bean_queried = $submodule;
@@ -2652,8 +2673,7 @@  discard block
 block discarded – undo
2652 2673
             if(empty($where))
2653 2674
             {
2654 2675
                 $where = $owner_where;
2655
-            }
2656
-            else
2676
+            } else
2657 2677
             {
2658 2678
                 $where .= ' AND '.  $owner_where;
2659 2679
             }
@@ -2739,8 +2759,7 @@  discard block
 block discarded – undo
2739 2759
             if(empty($entire_where))
2740 2760
             {
2741 2761
                 $entire_where = ' WHERE ' . $where;
2742
-            }
2743
-            else
2762
+            } else
2744 2763
             {
2745 2764
                 $entire_where .= ' AND ' . $where;
2746 2765
             }
@@ -2780,16 +2799,15 @@  discard block
 block discarded – undo
2780 2799
                             }
2781 2800
                             //call function from required file
2782 2801
                             $query_array = $shortcut_function_name($parameters);
2783
-                        }else{
2802
+                        } else{
2784 2803
                             //call function from parent bean
2785 2804
                             $query_array = $parentbean->$shortcut_function_name($parameters);
2786 2805
                         }
2787
-                    }
2788
-                    else
2806
+                    } else
2789 2807
                     {
2790 2808
                         $query_array = $parentbean->$shortcut_function_name();
2791 2809
                     }
2792
-                }  else {
2810
+                } else {
2793 2811
                     $related_field_name = $this_subpanel->get_data_source_name();
2794 2812
                     if (!$parentbean->load_relationship($related_field_name)){
2795 2813
                         unset ($parentbean->$related_field_name);
@@ -2805,8 +2823,7 @@  discard block
 block discarded – undo
2805 2823
                     if(empty($where_definition))
2806 2824
                     {
2807 2825
                         $where_definition = $table_where;
2808
-                    }
2809
-                    else
2826
+                    } else
2810 2827
                     {
2811 2828
                         $where_definition .= ' AND ' . $table_where;
2812 2829
                     }
@@ -2897,8 +2914,7 @@  discard block
 block discarded – undo
2897 2914
         {
2898 2915
             $subpanel_def->load_sub_subpanels();
2899 2916
             $subpanel_list=$subpanel_def->sub_subpanels;
2900
-        }
2901
-        else
2917
+        } else
2902 2918
         {
2903 2919
             $subpanel_list[]=$subpanel_def;
2904 2920
         }
@@ -2925,7 +2941,7 @@  discard block
 block discarded – undo
2925 2941
                         }
2926 2942
                         //call function from required file
2927 2943
                         $tmp_final_query =  $shortcut_function_name($parameters);
2928
-                    }else{
2944
+                    } else{
2929 2945
                         //call function from parent bean
2930 2946
                         $tmp_final_query =  $parentbean->$shortcut_function_name($parameters);
2931 2947
                     }
@@ -2953,8 +2969,9 @@  discard block
 block discarded – undo
2953 2969
                 $query_fields = $GLOBALS['db']->getSelectFieldsFromQuery($subquery['select']);
2954 2970
                 foreach($query_fields as $field => $select)
2955 2971
                 {
2956
-                    if (!in_array($field, $all_fields))
2957
-                        $all_fields[] = $field;
2972
+                    if (!in_array($field, $all_fields)) {
2973
+                                            $all_fields[] = $field;
2974
+                    }
2958 2975
                 }
2959 2976
                 $subqueries[$i]['query_fields'] = $query_fields;
2960 2977
             }
@@ -2968,8 +2985,7 @@  discard block
 block discarded – undo
2968 2985
                     if (!isset($subquery['query_fields'][$field]))
2969 2986
                     {
2970 2987
                         $subquery['select'] .= " NULL $field,";
2971
-                    }
2972
-                    else
2988
+                    } else
2973 2989
                     {
2974 2990
                         $subquery['select'] .= " {$subquery['query_fields'][$field]},";
2975 2991
                     }
@@ -2991,12 +3007,10 @@  discard block
 block discarded – undo
2991 3007
                 if (!empty($subquery['params']['distinct']) && !empty($subpanel_def->table_name))
2992 3008
                 {
2993 3009
                     $query_rows = "( SELECT count(DISTINCT ". $subpanel_def->table_name . ".id)".  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
2994
-                }
2995
-                elseif ($select_position !== false && $distinct_position!= false)
3010
+                } elseif ($select_position !== false && $distinct_position!= false)
2996 3011
                 {
2997 3012
                     $query_rows = "( ".substr_replace($query_array['select'],"SELECT count(",$select_position,6). ")" .  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
2998
-                }
2999
-                else
3013
+                } else
3000 3014
                 {
3001 3015
                     //resort to default behavior.
3002 3016
                     $query_rows = "( SELECT count(*)".  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
@@ -3010,8 +3024,7 @@  discard block
 block discarded – undo
3010 3024
                         if (empty($subquery['where']))
3011 3025
                         {
3012 3026
                             $subquerystring.=" WHERE " .$subquery['secondary_where'];
3013
-                        }
3014
-                        else
3027
+                        } else
3015 3028
                         {
3016 3029
                             $subquerystring.=" AND " .$subquery['secondary_where'];
3017 3030
                         }
@@ -3054,8 +3067,7 @@  discard block
 block discarded – undo
3054 3067
             {
3055 3068
                 $submodule->assign_display_fields($submodule->module_dir);
3056 3069
                 $response['list'] = array($submodule);
3057
-            }
3058
-            else
3070
+            } else
3059 3071
         {
3060 3072
                 $response['list'] = array();
3061 3073
             }
@@ -3120,8 +3132,7 @@  discard block
 block discarded – undo
3120 3132
             if(empty($where))
3121 3133
             {
3122 3134
                 $where = $owner_where;
3123
-            }
3124
-            else
3135
+            } else
3125 3136
             {
3126 3137
                 $where .= ' AND '.  $owner_where;
3127 3138
             }
@@ -3168,8 +3179,7 @@  discard block
 block discarded – undo
3168 3179
         if(empty($filter))
3169 3180
         {
3170 3181
             $ret_array['select'] = " SELECT $distinct $this->table_name.* ";
3171
-        }
3172
-        else
3182
+        } else
3173 3183
         {
3174 3184
             $ret_array['select'] = " SELECT $distinct $this->table_name.id ";
3175 3185
         }
@@ -3183,8 +3193,7 @@  discard block
 block discarded – undo
3183 3193
         {
3184 3194
             $ret_array['secondary_select']=& $ret_array['select'];
3185 3195
             $ret_array['secondary_from'] = & $ret_array['from'];
3186
-        }
3187
-        else
3196
+        } else
3188 3197
         {
3189 3198
             $ret_array['secondary_select'] = '';
3190 3199
         }
@@ -3229,17 +3238,15 @@  discard block
 block discarded – undo
3229 3238
                     if(isset($this->field_defs[$field]))
3230 3239
                     {
3231 3240
                         $fields[$field]= $this->field_defs[$field];
3232
-                    }
3233
-                    else
3241
+                    } else
3234 3242
                     {
3235 3243
                         $fields[$field] = array('force_exists'=>true);
3236 3244
                     }
3237 3245
                 }
3238
-            }else{
3246
+            } else{
3239 3247
                 $fields = 	$filter;
3240 3248
             }
3241
-        }
3242
-        else
3249
+        } else
3243 3250
         {
3244 3251
             $fields = 	$this->field_defs;
3245 3252
         }
@@ -3255,8 +3262,9 @@  discard block
 block discarded – undo
3255 3262
 			$this->field_defs[$field]['source'] == 'non-db')
3256 3263
 		{
3257 3264
 			$addrelatefield = $this->get_relationship_field($field);
3258
-			if ($addrelatefield)
3259
-				$addrelate[$addrelatefield] = true;
3265
+			if ($addrelatefield) {
3266
+							$addrelate[$addrelatefield] = true;
3267
+			}
3260 3268
 		}
3261 3269
 		if(!empty($this->field_defs[$field]['id_name'])){
3262 3270
 			$addrelate[$this->field_defs[$field]['id_name']] = true;
@@ -3278,15 +3286,15 @@  discard block
 block discarded – undo
3278 3286
             {
3279 3287
                 if(!empty($filter) && isset($filter[$field]['force_exists']) && $filter[$field]['force_exists'])
3280 3288
                 {
3281
-                    if ( isset($filter[$field]['force_default']) )
3282
-                        $ret_array['select'] .= ", {$filter[$field]['force_default']} $field ";
3283
-                    else
3284
-                    //spaces are a fix for length issue problem with unions.  The union only returns the maximum number of characters from the first select statement.
3289
+                    if ( isset($filter[$field]['force_default']) ) {
3290
+                                            $ret_array['select'] .= ", {$filter[$field]['force_default']} $field ";
3291
+                    } else {
3292
+                                        //spaces are a fix for length issue problem with unions.  The union only returns the maximum number of characters from the first select statement.
3285 3293
                         $ret_array['select'] .= ", '                                                                                                                                                                                                                                                              ' $field ";
3294
+                    }
3286 3295
                 }
3287 3296
                 continue;
3288
-            }
3289
-            else
3297
+            } else
3290 3298
             {
3291 3299
                 $data = $this->field_defs[$field];
3292 3300
             }
@@ -3306,8 +3314,9 @@  discard block
 block discarded – undo
3306 3314
                     }
3307 3315
                 }
3308 3316
 		
3309
-            	if (!$process_field)
3310
-                	continue;
3317
+            	if (!$process_field) {
3318
+            	                	continue;
3319
+            	}
3311 3320
             }
3312 3321
 
3313 3322
             if(  (!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter) ))
@@ -3385,16 +3394,14 @@  discard block
 block discarded – undo
3385 3394
                     if(empty($join_type))
3386 3395
                     {
3387 3396
                         $params['join_type'] = ' LEFT JOIN ';
3388
-                    }
3389
-                    else
3397
+                    } else
3390 3398
                     {
3391 3399
                         $params['join_type'] = $join_type;
3392 3400
                     }
3393 3401
                     if(isset($data['join_name']))
3394 3402
                     {
3395 3403
                         $params['join_table_alias'] = $data['join_name'];
3396
-                    }
3397
-                    else
3404
+                    } else
3398 3405
                     {
3399 3406
                         $params['join_table_alias']	= 'jt' . $jtcount;
3400 3407
 
@@ -3402,8 +3409,7 @@  discard block
 block discarded – undo
3402 3409
                     if(isset($data['join_link_name']))
3403 3410
                     {
3404 3411
                         $params['join_table_link_alias'] = $data['join_link_name'];
3405
-                    }
3406
-                    else
3412
+                    } else
3407 3413
                     {
3408 3414
                         $params['join_table_link_alias'] = 'jtl' . $jtcount;
3409 3415
                     }
@@ -3443,8 +3449,7 @@  discard block
 block discarded – undo
3443 3449
                                 if(isset($rel_mod->field_defs['assigned_user_id']))
3444 3450
                                 {
3445 3451
                                     $ret_array['secondary_select'].= " , ".	$params['join_table_alias'] . ".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3446
-                                }
3447
-                                else
3452
+                                } else
3448 3453
                                 {
3449 3454
                                     if(isset($rel_mod->field_defs['created_by']))
3450 3455
                                     {
@@ -3457,8 +3462,7 @@  discard block
 block discarded – undo
3457 3462
                         if(isset($data['db_concat_fields']))
3458 3463
                         {
3459 3464
                             $ret_array['secondary_select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3460
-                        }
3461
-                        else
3465
+                        } else
3462 3466
                         {
3463 3467
                             if(!isset($data['relationship_fields']))
3464 3468
                             {
@@ -3471,7 +3475,9 @@  discard block
 block discarded – undo
3471 3475
                         }
3472 3476
                         $count_used =0;
3473 3477
                         foreach($used_join_key as $used_key) {
3474
-                            if($used_key == $join['rel_key']) $count_used++;
3478
+                            if($used_key == $join['rel_key']) {
3479
+                                $count_used++;
3480
+                            }
3475 3481
                         }
3476 3482
                         if($count_used <= 1) {//27416, the $ret_array['secondary_select'] should always generate, regardless the dbtype
3477 3483
                             // add rel_key only if it was not aready added
@@ -3485,7 +3491,9 @@  discard block
 block discarded – undo
3485 3491
                         {
3486 3492
                             foreach($data['relationship_fields'] as $r_name=>$alias_name)
3487 3493
                             {
3488
-                                if(!empty( $secondarySelectedFields[$alias_name]))continue;
3494
+                                if(!empty( $secondarySelectedFields[$alias_name])) {
3495
+                                    continue;
3496
+                                }
3489 3497
                                 $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $r_name .' ' . $alias_name;
3490 3498
                                 $secondarySelectedFields[$alias_name] = true;
3491 3499
                             }
@@ -3498,14 +3506,12 @@  discard block
 block discarded – undo
3498 3506
                                 $ret_array['secondary_where'] = $params['join_table_link_alias'] . '.' . $join['rel_key']. "='" .$parentbean->id . "'";
3499 3507
                             }
3500 3508
                         }
3501
-                    }
3502
-                    else
3509
+                    } else
3503 3510
                     {
3504 3511
                         if(isset($data['db_concat_fields']))
3505 3512
                         {
3506 3513
                             $ret_array['select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3507
-                        }
3508
-                        else
3514
+                        } else
3509 3515
                         {
3510 3516
                             $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3511 3517
                         }
@@ -3532,8 +3538,7 @@  discard block
 block discarded – undo
3532 3538
                                 if(isset($rel_mod->field_defs['assigned_user_id']))
3533 3539
                                 {
3534 3540
                                     $ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.assigned_user_id ' .  $field . '_owner';
3535
-                                }
3536
-                                else
3541
+                                } else
3537 3542
                                 {
3538 3543
                                     $ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.created_by ' .  $field . '_owner';
3539 3544
                                 }
@@ -3568,20 +3573,22 @@  discard block
 block discarded – undo
3568 3573
 	                       $where = preg_replace('/'.$data['name'].'/', $db_field, $where);
3569 3574
 
3570 3575
 				// For relationship fields replace their alias by the corresponsding link table and r_name
3571
-				if(isset($data['relationship_fields']))
3572
-					foreach($data['relationship_fields'] as $r_name=>$alias_name)
3576
+				if(isset($data['relationship_fields'])) {
3577
+									foreach($data['relationship_fields'] as $r_name=>$alias_name)
3573 3578
 					{
3574 3579
 						$db_field = $this->db->concat($params['join_table_link_alias'], $r_name);
3580
+				}
3575 3581
 						$where = preg_replace('/' . $alias_name . '/', $db_field, $where);
3576 3582
 					}
3577 3583
                     	}
3578
-                    }else{
3584
+                    } else{
3579 3585
                         $where = preg_replace('/(^|[\s(])' . $data['name'] . '/', '${1}' . $params['join_table_alias'] . '.'.$data['rname'], $where);
3580 3586
 
3581 3587
 			// For relationship fields replace their alias by the corresponsding link table and r_name
3582
-			if(isset($data['relationship_fields']))
3583
-				foreach($data['relationship_fields'] as $r_name=>$alias_name)
3588
+			if(isset($data['relationship_fields'])) {
3589
+							foreach($data['relationship_fields'] as $r_name=>$alias_name)
3584 3590
 					$where = preg_replace('/(^|[\s(])' . $alias_name . '/', '${1}' . $params['join_table_link_alias'] . '.'.$r_name, $where);
3591
+			}
3585 3592
                     }
3586 3593
                     if(!$table_joined)
3587 3594
                     {
@@ -3598,8 +3605,7 @@  discard block
 block discarded – undo
3598 3605
             if(isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id']))
3599 3606
             {
3600 3607
                 $ret_array['select'] .= ", $this->table_name.assigned_user_id ";
3601
-            }
3602
-            else if(isset($this->field_defs['created_by']) &&  empty($selectedFields[$this->table_name.'.created_by']))
3608
+            } else if(isset($this->field_defs['created_by']) &&  empty($selectedFields[$this->table_name.'.created_by']))
3603 3609
             {
3604 3610
                 $ret_array['select'] .= ", $this->table_name.created_by ";
3605 3611
             }
@@ -3621,14 +3627,15 @@  discard block
 block discarded – undo
3621 3627
         if($show_deleted == 0)
3622 3628
         {
3623 3629
             $where_auto = "$this->table_name.deleted=0";
3624
-        }else if($show_deleted == 1)
3630
+        } else if($show_deleted == 1)
3625 3631
         {
3626 3632
             $where_auto = "$this->table_name.deleted=1";
3627 3633
         }
3628
-        if($where != "")
3629
-            $ret_array['where'] = " where ($where) AND $where_auto";
3630
-        else
3631
-            $ret_array['where'] = " where $where_auto";
3634
+        if($where != "") {
3635
+                    $ret_array['where'] = " where ($where) AND $where_auto";
3636
+        } else {
3637
+                    $ret_array['where'] = " where $where_auto";
3638
+        }
3632 3639
 
3633 3640
         //make call to process the order by clause
3634 3641
         $order_by = $this->process_order_by($order_by);
@@ -3656,8 +3663,9 @@  discard block
 block discarded – undo
3656 3663
 		foreach ($this->field_defs as $field_def => $value)
3657 3664
 		{
3658 3665
 			if (isset($value['relationship_fields']) && 
3659
-				in_array($field, $value['relationship_fields']) )
3660
-				return $field_def;
3666
+				in_array($field, $value['relationship_fields']) ) {
3667
+							return $field_def;
3668
+			}
3661 3669
 		}
3662 3670
 
3663 3671
 		return false;
@@ -3705,24 +3713,23 @@  discard block
 block discarded – undo
3705 3713
                         if(isset($field_def['db_concat_fields']))
3706 3714
                         {
3707 3715
                             $queries[$child_info['parent_type']] .= ' , ' . $this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']) . ' parent_name';
3708
-                        }
3709
-                        else
3716
+                        } else
3710 3717
                         {
3711 3718
                             $queries[$child_info['parent_type']] .= ' , name parent_name';
3712 3719
                         }
3713 3720
                         if(isset($templates[$child_info['parent_type']]->field_defs['assigned_user_id']))
3714 3721
                         {
3715 3722
                             $queries[$child_info['parent_type']] .= ", assigned_user_id parent_name_owner , '{$child_info['parent_type']}' parent_name_mod";;
3716
-                        }else if(isset($templates[$child_info['parent_type']]->field_defs['created_by']))
3723
+                        } else if(isset($templates[$child_info['parent_type']]->field_defs['created_by']))
3717 3724
                         {
3718 3725
                             $queries[$child_info['parent_type']] .= ", created_by parent_name_owner, '{$child_info['parent_type']}' parent_name_mod";
3719 3726
                         }
3720 3727
                         $queries[$child_info['parent_type']] .= " FROM " . $templates[$child_info['parent_type']]->table_name ." WHERE id IN ('{$child_info['parent_id']}'";
3721
-                    }
3722
-                    else
3728
+                    } else
3723 3729
                     {
3724
-                        if(empty($parent_child_map[$child_info['parent_id']]))
3725
-                        $queries[$child_info['parent_type']] .= " ,'{$child_info['parent_id']}'";
3730
+                        if(empty($parent_child_map[$child_info['parent_id']])) {
3731
+                                                $queries[$child_info['parent_type']] .= " ,'{$child_info['parent_id']}'";
3732
+                        }
3726 3733
                     }
3727 3734
                     $parent_child_map[$child_info['parent_id']][] = $child_info['child_id'];
3728 3735
                 }
@@ -3795,8 +3802,7 @@  discard block
 block discarded – undo
3795 3802
                     $row_offset = (floor(($rows_found -1) / $limit)) * $limit;
3796 3803
                 }
3797 3804
             }
3798
-        }
3799
-        else
3805
+        } else
3800 3806
         {
3801 3807
             if((empty($limit) || $limit == -1))
3802 3808
             {
@@ -3813,8 +3819,7 @@  discard block
 block discarded – undo
3813 3819
         if(!empty($limit) && $limit != -1 && $limit != -99)
3814 3820
         {
3815 3821
             $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $this->object_name list: ");
3816
-        }
3817
-        else
3822
+        } else
3818 3823
         {
3819 3824
             $result = $db->query($query,true,"Error retrieving $this->object_name list: ");
3820 3825
         }
@@ -3831,7 +3836,9 @@  discard block
 block discarded – undo
3831 3836
             while ($max_per_page == -99 || ($index < $row_offset + $max_per_page))
3832 3837
             {
3833 3838
                 $row = $db->fetchByAssoc($result);
3834
-                if (empty($row)) break;
3839
+                if (empty($row)) {
3840
+                    break;
3841
+                }
3835 3842
 
3836 3843
                 //instantiate a new class each time. This is because php5 passes
3837 3844
                 //by reference by default so if we continually update $this, we will
@@ -3851,11 +3858,10 @@  discard block
 block discarded – undo
3851 3858
                         }
3852 3859
 
3853 3860
                         $GLOBALS['log']->debug("$temp->object_name({$row['id']}): ".$field." = ".$temp->$field);
3854
-                    }else if (isset($row[$this->table_name .'.'.$field]))
3861
+                    } else if (isset($row[$this->table_name .'.'.$field]))
3855 3862
                     {
3856 3863
                         $temp->$field = $row[$this->table_name .'.'.$field];
3857
-                    }
3858
-                    else
3864
+                    } else
3859 3865
                     {
3860 3866
                         $temp->$field = "";
3861 3867
                     }
@@ -3863,7 +3869,9 @@  discard block
 block discarded – undo
3863 3869
 
3864 3870
                 $temp->check_date_relationships_load();
3865 3871
                 $temp->fill_in_additional_list_fields();
3866
-                if($temp->hasCustomFields()) $temp->custom_fields->fill_relationships();
3872
+                if($temp->hasCustomFields()) {
3873
+                    $temp->custom_fields->fill_relationships();
3874
+                }
3867 3875
                 $temp->call_custom_logic("process_record");
3868 3876
 
3869 3877
                 // fix defect #44206. implement the same logic as sugar_currency_format
@@ -3910,8 +3918,9 @@  discard block
 block discarded – undo
3910 3918
         if (!$is_count_query)
3911 3919
         {
3912 3920
             $count_query = SugarBean::create_list_count_query($query);
3913
-        } else
3914
-            $count_query=$query;
3921
+        } else {
3922
+                    $count_query=$query;
3923
+        }
3915 3924
 
3916 3925
         $result = $this->db->query($count_query, true, "Error running count query for $this->object_name List: ");
3917 3926
         $row_num = 0;
@@ -3984,8 +3993,7 @@  discard block
 block discarded – undo
3984 3993
                 $row_offset = (floor(($rows_found -1) / $limit)) * $limit;
3985 3994
 
3986 3995
             }
3987
-        }
3988
-        else
3996
+        } else
3989 3997
         {
3990 3998
             if((empty($limit) || $limit == -1))
3991 3999
             {
@@ -4007,8 +4015,7 @@  discard block
 block discarded – undo
4007 4015
             if(!empty($limit) && $limit != -1 && $limit != -99)
4008 4016
             {
4009 4017
                 $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $parent_bean->object_name list: ");
4010
-            }
4011
-            else
4018
+            } else
4012 4019
             {
4013 4020
                 $result = $db->query($query,true,"Error retrieving $this->object_name list: ");
4014 4021
             }
@@ -4054,13 +4061,11 @@  discard block
 block discarded – undo
4054 4061
                             {
4055 4062
                                 $current_bean->$field = $this->convertField($row[$field], $value);
4056 4063
                                 unset($row[$field]);
4057
-                            }
4058
-                            else if (isset($row[$this->table_name .'.'.$field]))
4064
+                            } else if (isset($row[$this->table_name .'.'.$field]))
4059 4065
                             {
4060 4066
                                 $current_bean->$field = $this->convertField($row[$this->table_name .'.'.$field], $value);
4061 4067
                                 unset($row[$this->table_name .'.'.$field]);
4062
-                            }
4063
-                            else
4068
+                            } else
4064 4069
                             {
4065 4070
                                 $current_bean->$field = "";
4066 4071
                                 unset($row[$field]);
@@ -4084,8 +4089,7 @@  discard block
 block discarded – undo
4084 4089
                             {
4085 4090
                                 $execute_function[] = 	$value['function_class'];
4086 4091
                                 $execute_function[] = 	$value['function_name'];
4087
-                            }
4088
-                            else
4092
+                            } else
4089 4093
                             {
4090 4094
                                 $execute_function	= $value['function_name'];
4091 4095
                             }
@@ -4098,8 +4102,7 @@  discard block
 block discarded – undo
4098 4102
                                         $can_execute = false;
4099 4103
                                     } else if($param == '$this') {
4100 4104
                                         $execute_params[] = $this;
4101
-                                    }
4102
-                                    else
4105
+                                    } else
4103 4106
                                     {
4104 4107
                                         $execute_params[] = $this->$param;
4105 4108
                                     }
@@ -4110,13 +4113,11 @@  discard block
 block discarded – undo
4110 4113
                                         $can_execute = false;
4111 4114
                                     } else if($param == '$this') {
4112 4115
                                         $execute_params[] = $current_bean;
4113
-                                    }
4114
-                                    else
4116
+                                    } else
4115 4117
                                     {
4116 4118
                                         $execute_params[] = $current_bean->$param;
4117 4119
                                     }
4118
-                                }
4119
-                                else
4120
+                                } else
4120 4121
                                 {
4121 4122
                                     $can_execute = false;
4122 4123
                                 }
@@ -4177,8 +4178,7 @@  discard block
 block discarded – undo
4177 4178
             if(isset($post_retrieve))
4178 4179
             {
4179 4180
                 $parent_fields = $this->retrieve_parent_fields($post_retrieve);
4180
-            }
4181
-            else
4181
+            } else
4182 4182
             {
4183 4183
                 $parent_fields = array();
4184 4184
             }
@@ -4197,8 +4197,7 @@  discard block
 block discarded – undo
4197 4197
                     $previous_offset++;
4198 4198
                 }
4199 4199
             }
4200
-        }
4201
-        else
4200
+        } else
4202 4201
         {
4203 4202
             $row_found 	= 0;
4204 4203
             $parent_fields = array();
@@ -4267,8 +4266,9 @@  discard block
 block discarded – undo
4267 4266
 
4268 4267
         $response = Array();
4269 4268
         $response['bean'] = $this;
4270
-        if (empty($total_rows))
4271
-            $total_rows=0;
4269
+        if (empty($total_rows)) {
4270
+                    $total_rows=0;
4271
+        }
4272 4272
         $response['row_count'] = $total_rows;
4273 4273
         $response['next_offset'] = $next_offset;
4274 4274
         $response['previous_offset'] = $previous_offset;
@@ -4311,8 +4311,7 @@  discard block
 block discarded – undo
4311 4311
                 {
4312 4312
                     $bean->$field = $row[$field];
4313 4313
                     $GLOBALS['log']->debug("process_full_list: $bean->object_name({$row['id']}): ".$field." = ".$bean->$field);
4314
-                }
4315
-                else
4314
+                } else
4316 4315
                 {
4317 4316
                     $bean->$field = '';
4318 4317
                 }
@@ -4329,8 +4328,11 @@  discard block
 block discarded – undo
4329 4328
             $list[] = $bean;
4330 4329
         }
4331 4330
         //}
4332
-        if (isset($list)) return $list;
4333
-        else return null;
4331
+        if (isset($list)) {
4332
+            return $list;
4333
+        } else {
4334
+            return null;
4335
+        }
4334 4336
     }
4335 4337
 
4336 4338
     /**
@@ -4394,10 +4396,12 @@  discard block
 block discarded – undo
4394 4396
             $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
4395 4397
 
4396 4398
         }
4397
-		if(!empty($this->field_defs['created_by']) && !empty($this->created_by))
4398
-		$this->created_by_name = get_assigned_user_name($this->created_by);
4399
-		if(!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4400
-		$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
4399
+		if(!empty($this->field_defs['created_by']) && !empty($this->created_by)) {
4400
+				$this->created_by_name = get_assigned_user_name($this->created_by);
4401
+		}
4402
+		if(!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id)) {
4403
+				$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
4404
+		}
4401 4405
 
4402 4406
 		if(!empty($this->field_defs['parent_name'])){
4403 4407
 			$this->fill_in_additional_parent_fields();
@@ -4412,7 +4416,7 @@  discard block
 block discarded – undo
4412 4416
 
4413 4417
         if(!empty($this->parent_id) && !empty($this->last_parent_id) && $this->last_parent_id == $this->parent_id){
4414 4418
             return false;
4415
-        }else{
4419
+        } else{
4416 4420
             $this->parent_name = '';
4417 4421
         }
4418 4422
         if(!empty($this->parent_type)) {
@@ -4442,8 +4446,9 @@  discard block
 block discarded – undo
4442 4446
         {
4443 4447
             $list=$this->$linkFieldName->get();
4444 4448
             $this->$idField = '' ; // match up with null value in $this->populateFromRow()
4445
-            if (!empty($list))
4446
-                $this->$idField = $list[0];
4449
+            if (!empty($list)) {
4450
+                            $this->$idField = $list[0];
4451
+            }
4447 4452
         }
4448 4453
     }
4449 4454
 
@@ -4452,11 +4457,13 @@  discard block
 block discarded – undo
4452 4457
     */
4453 4458
     function fill_in_relationship_fields(){
4454 4459
         global $fill_in_rel_depth;
4455
-        if(empty($fill_in_rel_depth) || $fill_in_rel_depth < 0)
4456
-            $fill_in_rel_depth = 0;
4460
+        if(empty($fill_in_rel_depth) || $fill_in_rel_depth < 0) {
4461
+                    $fill_in_rel_depth = 0;
4462
+        }
4457 4463
 
4458
-        if($fill_in_rel_depth > 1)
4459
-            return;
4464
+        if($fill_in_rel_depth > 1) {
4465
+                    return;
4466
+        }
4460 4467
 
4461 4468
         $fill_in_rel_depth++;
4462 4469
 
@@ -4498,13 +4505,13 @@  discard block
 block discarded – undo
4498 4505
                     }
4499 4506
                     if(!empty($this->$id_name) && isset($this->$name))
4500 4507
                     {
4501
-                        if(!isset($field['additionalFields']))
4502
-                           $field['additionalFields'] = array();
4508
+                        if(!isset($field['additionalFields'])) {
4509
+                                                   $field['additionalFields'] = array();
4510
+                        }
4503 4511
                         if(!empty($field['rname']))
4504 4512
                         {
4505 4513
                             $field['additionalFields'][$field['rname']]= $name;
4506
-                        }
4507
-                        else
4514
+                        } else
4508 4515
                         {
4509 4516
                             $field['additionalFields']['name']= $name;
4510 4517
                         }
@@ -4539,8 +4546,7 @@  discard block
 block discarded – undo
4539 4546
 		if(isset($_SESSION['show_deleted']))
4540 4547
 		{
4541 4548
 			$this->mark_undeleted($id);
4542
-		}
4543
-		else
4549
+		} else
4544 4550
 		{
4545 4551
 			// call the custom business logic
4546 4552
 			$custom_logic_arguments['id'] = $id;
@@ -4802,8 +4808,7 @@  discard block
 block discarded – undo
4802 4808
         if(!empty($row_offset) && $row_offset != 0 && !empty($limit) && $limit != -1)
4803 4809
         {
4804 4810
             $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $template->object_name list: ");
4805
-        }
4806
-        else
4811
+        } else
4807 4812
         {
4808 4813
             $result = $db->query($query, true);
4809 4814
         }
@@ -4872,8 +4877,7 @@  discard block
 block discarded – undo
4872 4877
     if (!empty($limit))
4873 4878
     {
4874 4879
         $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $this->object_name list: ");
4875
-    }
4876
-    else
4880
+    } else
4877 4881
     {
4878 4882
         $result = $db->query($query, true);
4879 4883
     }
@@ -4919,8 +4923,7 @@  discard block
 block discarded – undo
4919 4923
             if(empty($ids))
4920 4924
             {
4921 4925
                 $ids = "('" . $row['id'] . "'";
4922
-            }
4923
-            else
4926
+            } else
4924 4927
             {
4925 4928
                 $ids .= ",'" . $row['id'] . "'";
4926 4929
             }
@@ -4928,7 +4931,7 @@  discard block
 block discarded – undo
4928 4931
         if(empty($ids))
4929 4932
         {
4930 4933
             $ids = "('')";
4931
-        }else{
4934
+        } else{
4932 4935
             $ids .= ')';
4933 4936
         }
4934 4937
 
@@ -5000,10 +5003,12 @@  discard block
 block discarded – undo
5000 5003
             if(isset($this->$field)){
5001 5004
 
5002 5005
                 // cn: bug 12270 - sensitive fields being passed arbitrarily in listViews
5003
-                if(isset($sensitiveFields[$field]))
5004
-                    continue;
5005
-                if(!isset($cache[$field]))
5006
-                    $cache[$field] = strtoupper($field);
5006
+                if(isset($sensitiveFields[$field])) {
5007
+                                    continue;
5008
+                }
5009
+                if(!isset($cache[$field])) {
5010
+                                    $cache[$field] = strtoupper($field);
5011
+                }
5007 5012
 
5008 5013
                 //Fields hidden by Dependent Fields
5009 5014
                 if (isset($value['hidden']) && $value['hidden'] === true) {
@@ -5020,18 +5025,17 @@  discard block
 block discarded – undo
5020 5025
                     elseif(!empty($value['options']) && !empty($mod_strings[$value['options']][$this->$field]))
5021 5026
                     {
5022 5027
                         $return_array[$cache[$field]] = $mod_strings[$value['options']][$this->$field];
5023
-                    }
5024
-                    else{
5028
+                    } else{
5025 5029
                         $return_array[$cache[$field]] = $this->$field;
5026 5030
                     }
5027 5031
                     //end bug 21672
5028 5032
 // tjy: no need to do this str_replace as the changes in 29994 for ListViewGeneric.tpl for translation handle this now
5029 5033
 //				}elseif(!empty($value['type']) && $value['type'] == 'multienum'&& empty($value['function'])){
5030 5034
 //					$return_array[strtoupper($field)] = str_replace('^,^', ', ', $this->$field );
5031
-                }elseif(!empty($value['custom_module']) && $value['type'] != 'currency'){
5035
+                } elseif(!empty($value['custom_module']) && $value['type'] != 'currency'){
5032 5036
 //					$this->format_field($value);
5033 5037
                     $return_array[$cache[$field]] = $this->$field;
5034
-                }else{
5038
+                } else{
5035 5039
                     $return_array[$cache[$field]] = $this->$field;
5036 5040
                 }
5037 5041
                 // handle "Assigned User Name"
@@ -5150,23 +5154,29 @@  discard block
 block discarded – undo
5150 5154
     }
5151 5155
 
5152 5156
     function getRelatedFields($module, $id, $fields, $return_array = false){
5153
-        if(empty($GLOBALS['beanList'][$module]))return '';
5157
+        if(empty($GLOBALS['beanList'][$module])) {
5158
+            return '';
5159
+        }
5154 5160
         $object = BeanFactory::getObjectName($module);
5155 5161
 
5156 5162
         VardefManager::loadVardef($module, $object);
5157
-        if(empty($GLOBALS['dictionary'][$object]['table']))return '';
5163
+        if(empty($GLOBALS['dictionary'][$object]['table'])) {
5164
+            return '';
5165
+        }
5158 5166
         $table = $GLOBALS['dictionary'][$object]['table'];
5159 5167
         $query  = 'SELECT id';
5160 5168
         foreach($fields as $field=>$alias){
5161 5169
             if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])){
5162 5170
                 $query .= ' ,' .$this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']) .  ' as ' . $alias ;
5163
-            }else if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
5171
+            } else if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
5164 5172
                 (empty($GLOBALS['dictionary'][$object]['fields'][$field]['source']) ||
5165 5173
                 $GLOBALS['dictionary'][$object]['fields'][$field]['source'] != "non-db"))
5166 5174
             {
5167 5175
                 $query .= ' ,' .$table . '.' . $field . ' as ' . $alias;
5168 5176
             }
5169
-            if(!$return_array)$this->$alias = '';
5177
+            if(!$return_array) {
5178
+                $this->$alias = '';
5179
+            }
5170 5180
         }
5171 5181
         if($query == 'SELECT id' || empty($id)){
5172 5182
             return '';
@@ -5177,8 +5187,7 @@  discard block
 block discarded – undo
5177 5187
         {
5178 5188
             $query .= " , ".	$table  . ".assigned_user_id owner";
5179 5189
 
5180
-        }
5181
-        else if(isset($GLOBALS['dictionary'][$object]['fields']['created_by']))
5190
+        } else if(isset($GLOBALS['dictionary'][$object]['fields']['created_by']))
5182 5191
         {
5183 5192
             $query .= " , ".	$table . ".created_by owner";
5184 5193
 
@@ -5214,8 +5223,9 @@  discard block
 block discarded – undo
5214 5223
         {
5215 5224
             if(isset($this->field_name_map[$field]) && empty($this->$field))
5216 5225
             {
5217
-                if($this->field_name_map[$field]['type'] != 'date' && $this->field_name_map[$field]['type'] != 'enum')
5218
-                $this->$field = $field;
5226
+                if($this->field_name_map[$field]['type'] != 'date' && $this->field_name_map[$field]['type'] != 'enum') {
5227
+                                $this->$field = $field;
5228
+                }
5219 5229
                 if($this->field_name_map[$field]['type'] == 'date')
5220 5230
                 {
5221 5231
                     $this->$field = $timedate->to_display_date('1980-07-09');
@@ -5290,8 +5300,7 @@  discard block
 block discarded – undo
5290 5300
             $query = "INSERT INTO $table (id, ". implode(',', array_keys($relate_values)) . ", date_modified) VALUES ('" . create_guid() . "', " . "'" . implode("', '", $relate_values) . "', ".$date_modified.")" ;
5291 5301
 
5292 5302
             $this->db->query($query, false, "Creating Relationship:" . $query);
5293
-        }
5294
-        else if ($do_update)
5303
+        } else if ($do_update)
5295 5304
         {
5296 5305
             $conds = array();
5297 5306
             foreach($data_values as $key=>$value)
@@ -5370,10 +5379,12 @@  discard block
 block discarded – undo
5370 5379
         if(!isset($this->processed) || $this->processed == false){
5371 5380
             //add some logic to ensure we do not get into an infinite loop
5372 5381
             if(!empty($this->logicHookDepth[$event])) {
5373
-                if($this->logicHookDepth[$event] > $this->max_logic_depth)
5374
-                    return;
5375
-            }else
5376
-                $this->logicHookDepth[$event] = 0;
5382
+                if($this->logicHookDepth[$event] > $this->max_logic_depth) {
5383
+                                    return;
5384
+                }
5385
+            } else {
5386
+                            $this->logicHookDepth[$event] = 0;
5387
+            }
5377 5388
 
5378 5389
             //we have to put the increment operator here
5379 5390
             //otherwise we may never increase the depth for that event in the case
@@ -5403,16 +5414,13 @@  discard block
 block discarded – undo
5403 5414
         if ($this->custom_fields->avail_fields[$name]['ext1'])
5404 5415
         {
5405 5416
             $realKey = 'ext1';
5406
-        }
5407
-        elseif ($this->custom_fields->avail_fields[$name]['ext2'])
5417
+        } elseif ($this->custom_fields->avail_fields[$name]['ext2'])
5408 5418
         {
5409 5419
             $realKey = 'ext2';
5410
-        }
5411
-        elseif ($this->custom_fields->avail_fields[$name]['ext3'])
5420
+        } elseif ($this->custom_fields->avail_fields[$name]['ext3'])
5412 5421
         {
5413 5422
             $realKey = 'ext3';
5414
-        }
5415
-        else
5423
+        } else
5416 5424
         {
5417 5425
             $GLOBALS['log']->fatal("SUGARBEAN: cannot find Real Key for custom field of type dropdown - cannot return Value.");
5418 5426
             return false;
@@ -5446,9 +5454,11 @@  discard block
 block discarded – undo
5446 5454
 		/**
5447 5455
         if($is_owner == 'not_set')
5448 5456
 		*/
5449
-    	if($is_owner === 'not_set') //eggsurplus: should be ===
5457
+    	if($is_owner === 'not_set') {
5458
+    	    //eggsurplus: should be ===
5450 5459
         {
5451 5460
             $not_set = true;
5461
+    	}
5452 5462
             $is_owner = $this->isOwner($current_user->id);
5453 5463
         }
5454 5464
 		// DJM - OBS Customizations - May 2009
@@ -5499,8 +5509,9 @@  discard block
 block discarded – undo
5499 5509
 			// DJM - OBS Customizations - END CHANGE
5500 5510
     	}
5501 5511
         //if we don't implent acls return true
5502
-        if(!$this->bean_implements('ACL'))
5503
-        return true;
5512
+        if(!$this->bean_implements('ACL')) {
5513
+                return true;
5514
+        }
5504 5515
         $view = strtolower($view);
5505 5516
         switch ($view)
5506 5517
         {
@@ -5518,7 +5529,7 @@  discard block
 block discarded – undo
5518 5529
                     $temp = new $class();
5519 5530
                     if(!empty($this->fetched_row) && !empty($this->fetched_row['id']) && !empty($this->fetched_row['assigned_user_id']) && !empty($this->fetched_row['created_by'])){
5520 5531
                         $temp->populateFromRow($this->fetched_row);
5521
-                    }else{
5532
+                    } else{
5522 5533
                         $temp->retrieve($this->id);
5523 5534
                     }
5524 5535
                     $is_owner = $temp->isOwner($current_user->id);
@@ -5597,10 +5608,11 @@  discard block
 block discarded – undo
5597 5608
             }
5598 5609
             return false;
5599 5610
         } elseif (isset($this->assigned_user_id)) {
5600
-            if($this->assigned_user_id == $user_id) return true;
5611
+            if($this->assigned_user_id == $user_id) {
5612
+                return true;
5613
+            }
5601 5614
             return false;
5602
-        }
5603
-        else
5615
+        } else
5604 5616
         {
5605 5617
             //other wise if there is a created_by that is the owner
5606 5618
             if(isset($this->created_by) && $this->created_by == $user_id)
@@ -5642,8 +5654,7 @@  discard block
 block discarded – undo
5642 5654
         if($this->ACLAccess('DetailView'))
5643 5655
         {
5644 5656
             $array_assign['MAIN'] = 'a';
5645
-        }
5646
-        else
5657
+        } else
5647 5658
         {
5648 5659
             $array_assign['MAIN'] = 'span';
5649 5660
         }
@@ -5662,20 +5673,20 @@  discard block
 block discarded – undo
5662 5673
 
5663 5674
         foreach($this->field_defs as $field=>$data)
5664 5675
         {
5665
-            if( !$dbOnly || !isset($data['source']) || $data['source'] == 'db')
5666
-            if(!$stringOnly || is_string($this->$field))
5676
+            if( !$dbOnly || !isset($data['source']) || $data['source'] == 'db') {
5677
+                        if(!$stringOnly || is_string($this->$field))
5667 5678
             if($upperKeys)
5668 5679
             {
5669 5680
                                 if(!isset($cache[$field])){
5670 5681
                                     $cache[$field] = strtoupper($field);
5682
+            }
5671 5683
                                 }
5672 5684
                 $arr[$cache[$field]] = $this->$field;
5673
-            }
5674
-            else
5685
+            } else
5675 5686
             {
5676 5687
                 if(isset($this->$field)){
5677 5688
                     $arr[$field] = $this->$field;
5678
-                }else{
5689
+                } else{
5679 5690
                     $arr[$field] = '';
5680 5691
                 }
5681 5692
             }
@@ -5750,7 +5761,9 @@  discard block
 block discarded – undo
5750 5761
 
5751 5762
         $this->fill_in_additional_list_fields();
5752 5763
 
5753
-        if($this->hasCustomFields())$this->custom_fields->fill_relationships();
5764
+        if($this->hasCustomFields()) {
5765
+            $this->custom_fields->fill_relationships();
5766
+        }
5754 5767
         $this->call_custom_logic("process_record");
5755 5768
     }
5756 5769
 
@@ -5843,7 +5856,10 @@  discard block
 block discarded – undo
5843 5856
  */
5844 5857
     function decrypt_after_retrieve($value)
5845 5858
     {
5846
-        if(empty($value)) return $value; // no need to decrypt empty
5859
+        if(empty($value)) {
5860
+            return $value;
5861
+        }
5862
+        // no need to decrypt empty
5847 5863
         require_once("include/utils/encryption_utils.php");
5848 5864
         return blowfishDecode($this->getEncryptKey(), $value);
5849 5865
     }
@@ -5870,16 +5886,14 @@  discard block
 block discarded – undo
5870 5886
                     $_SESSION['o_lock_save'] = $saveform;
5871 5887
                     header('Location: index.php?module=OptimisticLock&action=LockResolve');
5872 5888
                     die();
5873
-                }
5874
-                else
5889
+                } else
5875 5890
                 {
5876 5891
                     unset ($_SESSION['o_lock_object']);
5877 5892
                     unset ($_SESSION['o_lock_id']);
5878 5893
                     unset ($_SESSION['o_lock_dm']);
5879 5894
                 }
5880 5895
             }
5881
-        }
5882
-        else
5896
+        } else
5883 5897
         {
5884 5898
             if(isset($_SESSION['o_lock_object']))	{ unset ($_SESSION['o_lock_object']); }
5885 5899
             if(isset($_SESSION['o_lock_id']))		{ unset ($_SESSION['o_lock_id']); }
@@ -5894,9 +5908,11 @@  discard block
 block discarded – undo
5894 5908
     */
5895 5909
     private function _sendNotifications($check_notify){
5896 5910
         if($check_notify || (isset($this->notify_inworkflow) && $this->notify_inworkflow == true) // cn: bug 5795 - no invites sent to Contacts, and also bug 25995, in workflow, it will set the notify_on_save=true.
5897
-           && !$this->isOwner($this->created_by) )  // cn: bug 42727 no need to send email to owner (within workflow)
5911
+           && !$this->isOwner($this->created_by) ) {
5912
+            // cn: bug 42727 no need to send email to owner (within workflow)
5898 5913
         {
5899 5914
             $admin = new Administration();
5915
+        }
5900 5916
             $admin->retrieveSettings();
5901 5917
             $sendNotifications = false;
5902 5918
 
@@ -5904,13 +5920,11 @@  discard block
 block discarded – undo
5904 5920
             {
5905 5921
                 $GLOBALS['log']->info("Notifications: user assignment has changed, checking if user receives notifications");
5906 5922
                 $sendNotifications = true;
5907
-            }
5908
-            elseif(isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1)
5923
+            } elseif(isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1)
5909 5924
             {
5910 5925
                 // cn: bug 5795 Send Invites failing for Contacts
5911 5926
                 $sendNotifications = true;
5912
-            }
5913
-            else
5927
+            } else
5914 5928
             {
5915 5929
                 $GLOBALS['log']->info("Notifications: not sending e-mail, notify_on is set to OFF");
5916 5930
             }
@@ -6116,8 +6130,7 @@  discard block
 block discarded – undo
6116 6130
             !empty($this->field_defs['email_addresses_non_primary']) && $this->field_defs['email_addresses_non_primary']['type'] == 'email')
6117 6131
         {
6118 6132
             return true;
6119
-        }
6120
-        else
6133
+        } else
6121 6134
         {
6122 6135
             return false;
6123 6136
         }
Please login to merge, or discard this patch.
Doc Comments   +29 added lines, -19 removed lines patch added patch discarded remove patch
@@ -394,8 +394,7 @@  discard block
 block discarded – undo
394 394
      *
395 395
      * All implementing classes must set a value for the object_name variable.
396 396
      *
397
-     * @param array $arr row of data fetched from the database.
398
-     * @return  nothing
397
+     * @return  string
399 398
      *
400 399
      */
401 400
     function getObjectName()
@@ -1036,7 +1035,6 @@  discard block
 block discarded – undo
1036 1035
      * Method will load the relationship if not done so already.
1037 1036
      *
1038 1037
      * @param string $field_name relationship to be loaded.
1039
-     * @param string $bean name  class name of the related bean.legacy
1040 1038
      * @param string $order_by, Optional, default empty.
1041 1039
      * @param int $begin_index Optional, default 0, unused.
1042 1040
      * @param int $end_index Optional, default -1
@@ -2279,7 +2277,7 @@  discard block
 block discarded – undo
2279 2277
      * The fetched data is then set into the bean. The function also processes the fetched data by formattig
2280 2278
      * date/time and numeric values.
2281 2279
      *
2282
-     * @param string $id Optional, default -1, is set to -1 id value from the bean is used, else, passed value is used
2280
+     * @param integer $id Optional, default -1, is set to -1 id value from the bean is used, else, passed value is used
2283 2281
      * @param boolean $encode Optional, default true, encodes the values fetched from the database.
2284 2282
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
2285 2283
      *
@@ -2502,9 +2500,9 @@  discard block
 block discarded – undo
2502 2500
     * @param string $order_by
2503 2501
     * @param string $where Additional where clause
2504 2502
     * @param int $row_offset Optaional,default 0, starting row number
2505
-    * @param init $limit Optional, default -1
2503
+    * @param integer $limit Optional, default -1
2506 2504
     * @param int $max Optional, default -1
2507
-    * @param boolean $show_deleted Optional, default 0, if set to 1 system will show deleted records.
2505
+    * @param integer $show_deleted Optional, default 0, if set to 1 system will show deleted records.
2508 2506
     * @return array Fetched data.
2509 2507
     *
2510 2508
     * Internal function, do not override.
@@ -2629,9 +2627,9 @@  discard block
 block discarded – undo
2629 2627
     * @param string $order_by
2630 2628
     * @param string $where Additional where clause
2631 2629
     * @param int $row_offset Optaional,default 0, starting row number
2632
-    * @param init $limit Optional, default -1
2630
+    * @param integer $limit Optional, default -1
2633 2631
     * @param int $max Optional, default -1
2634
-    * @param boolean $show_deleted Optioanl, default 0, if set to 1 system will show deleted records.
2632
+    * @param integer $show_deleted Optioanl, default 0, if set to 1 system will show deleted records.
2635 2633
     * @return array Fetched data.
2636 2634
     *
2637 2635
     * Internal function, do not override.
@@ -2756,6 +2754,11 @@  discard block
 block discarded – undo
2756 2754
     }
2757 2755
 
2758 2756
 
2757
+    /**
2758
+     * @param aSubPanel $subpanel_def
2759
+     * @param SugarBean $parentbean
2760
+     * @param string $order_by
2761
+     */
2759 2762
     protected static function build_sub_queries_for_union($subpanel_list, $subpanel_def, $parentbean, $order_by)
2760 2763
     {
2761 2764
         global $layout_edit_mode, $beanFiles, $beanList;
@@ -3928,15 +3931,15 @@  discard block
 block discarded – undo
3928 3931
      * executes the query and returns fetched data.
3929 3932
      *
3930 3933
      * Internal function, do not override.
3931
-     * @param object $parent_bean
3934
+     * @param SugarBean $parent_bean
3932 3935
      * @param string $query query to be processed.
3933 3936
      * @param int $row_offset
3934 3937
      * @param int $limit optional, default -1
3935 3938
      * @param int $max_per_page Optional, default -1
3936 3939
      * @param string $where Custom where clause.
3937
-     * @param array $subpanel_def definition of sub-panel to be processed
3940
+     * @param aSubPanel $subpanel_def definition of sub-panel to be processed
3938 3941
      * @param string $query_row_count
3939
-     * @param array $seconday_queries
3942
+     * @param array $secondary_queries
3940 3943
      * @return array Fetched data.
3941 3944
      */
3942 3945
     function process_union_list_query($parent_bean, $query,
@@ -4577,6 +4580,7 @@  discard block
 block discarded – undo
4577 4580
      * Restores data deleted by call to mark_deleted() function.
4578 4581
      *
4579 4582
      * Internal function, do not override.
4583
+    * @param string $id
4580 4584
     */
4581 4585
     function mark_undeleted($id)
4582 4586
     {
@@ -4609,7 +4613,7 @@  discard block
 block discarded – undo
4609 4613
     /**
4610 4614
      * Returns path for files of bean or false on error
4611 4615
      *
4612
-     * @return bool|string
4616
+     * @return false|string
4613 4617
      */
4614 4618
     public function deleteFileDirectory()
4615 4619
     {
@@ -4941,8 +4945,8 @@  discard block
 block discarded – undo
4941 4945
     * Internal function, do not override.
4942 4946
     *
4943 4947
     * @param string $query - the query that should be executed to build the list
4944
-    * @param object $template - The object that should be used to copy the records
4945
-    * @param array $field_list List of  fields.
4948
+    * @param Contact $template - The object that should be used to copy the records
4949
+    * @param string[] $field_list List of  fields.
4946 4950
     * @return array
4947 4951
     */
4948 4952
     function build_related_list2($query, &$template, &$field_list)
@@ -5088,7 +5092,7 @@  discard block
 block discarded – undo
5088 5092
      * @param array @fields_array  array of name value pairs used to construct query.
5089 5093
      * @param boolean $encode Optional, default true, encode fetched data.
5090 5094
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
5091
-     * @return object Instance of this bean with fetched data.
5095
+     * @return null|SugarBean Instance of this bean with fetched data.
5092 5096
      */
5093 5097
     function retrieve_by_string_fields($fields_array, $encode=true, $deleted=true)
5094 5098
     {
@@ -5259,6 +5263,9 @@  discard block
 block discarded – undo
5259 5263
     * 	RELATIONSHIP HANDLING
5260 5264
     */
5261 5265
 
5266
+    /**
5267
+     * @param string $table
5268
+     */
5262 5269
     function set_relationship($table, $relate_values, $check_duplicates = true,$do_update=false,$data_values=null)
5263 5270
     {
5264 5271
         $where = '';
@@ -5364,6 +5371,7 @@  discard block
 block discarded – undo
5364 5371
     * 		$bean - $this bean passed in by reference.
5365 5372
     *		$event - The string for the current event (i.e. before_save)
5366 5373
     * 		$arguments - An array of arguments that are specific to the event.
5374
+    * @param string $event
5367 5375
     */
5368 5376
     function call_custom_logic($event, $arguments = null)
5369 5377
     {
@@ -5765,7 +5773,7 @@  discard block
 block discarded – undo
5765 5773
     *
5766 5774
     * @param string $order_by original order by from the query
5767 5775
     * @param string $qualify prefix for columns in the order by list.
5768
-    * @return  prefixed
5776
+    * @return  string
5769 5777
     *
5770 5778
     * Internal function do not override.
5771 5779
     */
@@ -5851,6 +5859,7 @@  discard block
 block discarded – undo
5851 5859
     /**
5852 5860
     * Moved from save() method, functionality is the same, but this is intended to handle
5853 5861
     * Optimistic locking functionality.
5862
+    * @param boolean $isUpdate
5854 5863
     */
5855 5864
     private function _checkOptimisticLocking($action, $isUpdate){
5856 5865
         if($this->optimistic_lock && !isset($_SESSION['o_lock_fs'])){
@@ -5891,6 +5900,7 @@  discard block
 block discarded – undo
5891 5900
 
5892 5901
     /**
5893 5902
     * Send assignment notifications and invites for meetings and calls
5903
+    * @param boolean $check_notify
5894 5904
     */
5895 5905
     private function _sendNotifications($check_notify){
5896 5906
         if($check_notify || (isset($this->notify_inworkflow) && $this->notify_inworkflow == true) // cn: bug 5795 - no invites sent to Contacts, and also bug 25995, in workflow, it will set the notify_on_save=true.
@@ -5961,9 +5971,9 @@  discard block
 block discarded – undo
5961 5971
      * bean files and have since been moved to separate files. Was previously in include/CacheHandler.php
5962 5972
      *
5963 5973
      * @deprecated
5964
-     * @param $module_dir string the module directory
5965
-     * @param $module string the name of the module
5966
-     * @param $key string the type of field array we are referencing, i.e. list_fields, column_fields, required_fields
5974
+     * @param string $module_dir string the module directory
5975
+     * @param string $module string the name of the module
5976
+     * @param string $key string the type of field array we are referencing, i.e. list_fields, column_fields, required_fields
5967 5977
      **/
5968 5978
     private function _loadCachedArray(
5969 5979
         $module_dir,
Please login to merge, or discard this patch.