Completed
Push — master ( a75ecc...97ae17 )
by Adam
71:21 queued 52:34
created
themes/SuiteR/css/colourSelector.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // config|_override.php
4
-if(is_file('../../../config.php')) {
4
+if (is_file('../../../config.php')) {
5 5
     require_once('../../../config.php');
6 6
 }
7 7
 
8 8
 // load up the config_override.php file.  This is used to provide default user settings
9
-if(is_file('../../../config_override.php')) {
9
+if (is_file('../../../config_override.php')) {
10 10
     require_once('../../../config_override.php');
11 11
 }
12 12
 
13
-if(!isset($sugar_config['theme_settings']['SuiteR'])) return;
13
+if (!isset($sugar_config['theme_settings']['SuiteR'])) return;
14 14
 
15 15
 //set file type back to css from php
16 16
 header("Content-type: text/css; charset: UTF-8");
@@ -33,21 +33,21 @@  discard block
 block discarded – undo
33 33
 /* Dashlet CSS */
34 34
 
35 35
 .dashletPanel .h3Row{
36
-background: #<?php echo $sugar_config['theme_settings']['SuiteR']['dashlet'];?>;
36
+background: #<?php echo $sugar_config['theme_settings']['SuiteR']['dashlet']; ?>;
37 37
 }
38 38
 
39 39
 .dashletPanel .h3Row h3{
40
-color: #<?php echo $sugar_config['theme_settings']['SuiteR']['dashlet_headertext'];?> !important;
40
+color: #<?php echo $sugar_config['theme_settings']['SuiteR']['dashlet_headertext']; ?> !important;
41 41
 }
42 42
 
43 43
 .dashletPanel .h3Row .dashletToolSet .icon{
44
-fill: #<?php echo $sugar_config['theme_settings']['SuiteR']['dashlet_headertext'];?> !important;
44
+fill: #<?php echo $sugar_config['theme_settings']['SuiteR']['dashlet_headertext']; ?> !important;
45 45
 }
46 46
 
47 47
 /* Top navigation bar CSS */
48 48
 
49 49
 .navbar-inverse {
50
-background:#<?php echo $sugar_config['theme_settings']['SuiteR']['navbar'];?> !important;
50
+background:#<?php echo $sugar_config['theme_settings']['SuiteR']['navbar']; ?> !important;
51 51
 }
52 52
 
53 53
 .headerlinks a:link, .headerlinks a:visited, .navbar-inverse .navbar-brand, .moremenu a,  a[id^=grouptab], a[id^=moduleTab] {
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 
76 76
 #searchform .btn
77 77
 {
78
-background:#<?php echo $sugar_config['theme_settings']['SuiteR']['navbar'];?> !important;
79
-color: #<?php echo $sugar_config['theme_settings']['SuiteR']['icon'];?> !important;
78
+background:#<?php echo $sugar_config['theme_settings']['SuiteR']['navbar']; ?> !important;
79
+color: #<?php echo $sugar_config['theme_settings']['SuiteR']['icon']; ?> !important;
80 80
 }
81 81
 
82 82
 #usermenu a{
Please login to merge, or discard this patch.
data/SugarBean.php 1 patch
Spacing   +836 added lines, -836 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
         }
@@ -2347,23 +2347,23 @@  discard block
 block discarded – undo
2347 2347
          foreach ($this->get_related_fields() as $rel_field_name)
2348 2348
          {
2349 2349
              $field_name = $rel_field_name['name'];
2350
-             if (! empty($this->$field_name))
2350
+             if (!empty($this->$field_name))
2351 2351
              {
2352 2352
                  $this->fetched_rel_row[$rel_field_name['name']] = $this->$field_name;
2353 2353
              }
2354 2354
          }
2355 2355
         //make a copy of fields in the relationship_fields array. These field values will be used to
2356 2356
         //clear relationship.
2357
-        foreach ( $this->field_defs as $key => $def )
2357
+        foreach ($this->field_defs as $key => $def)
2358 2358
         {
2359
-            if (isset($def [ 'type' ]) && $def [ 'type' ] == 'relate' && isset ( $def [ 'id_name'] ) && isset ( $def [ 'link'] ) && isset ( $def[ 'save' ])) {
2359
+            if (isset($def ['type']) && $def ['type'] == 'relate' && isset ($def ['id_name']) && isset ($def ['link']) && isset ($def['save'])) {
2360 2360
                 if (isset($this->$key)) {
2361
-                    $this->rel_fields_before_value[$key]=$this->$key;
2362
-                    if (isset($this->$def [ 'id_name']))
2363
-                        $this->rel_fields_before_value[$def [ 'id_name']]=$this->$def [ 'id_name'];
2361
+                    $this->rel_fields_before_value[$key] = $this->$key;
2362
+                    if (isset($this->$def ['id_name']))
2363
+                        $this->rel_fields_before_value[$def ['id_name']] = $this->$def ['id_name'];
2364 2364
                 }
2365 2365
                 else
2366
-                    $this->rel_fields_before_value[$key]=null;
2366
+                    $this->rel_fields_before_value[$key] = null;
2367 2367
            }
2368 2368
         }
2369 2369
         if (isset($this->relationship_fields) && is_array($this->relationship_fields))
@@ -2371,9 +2371,9 @@  discard block
 block discarded – undo
2371 2371
             foreach ($this->relationship_fields as $rel_id=>$rel_name)
2372 2372
             {
2373 2373
                 if (isset($this->$rel_id))
2374
-                    $this->rel_fields_before_value[$rel_id]=$this->$rel_id;
2374
+                    $this->rel_fields_before_value[$rel_id] = $this->$rel_id;
2375 2375
                 else
2376
-                    $this->rel_fields_before_value[$rel_id]=null;
2376
+                    $this->rel_fields_before_value[$rel_id] = null;
2377 2377
             }
2378 2378
         }
2379 2379
 
@@ -2396,16 +2396,16 @@  discard block
 block discarded – undo
2396 2396
      */
2397 2397
     function populateFromRow($row)
2398 2398
     {
2399
-        $nullvalue='';
2400
-        foreach($this->field_defs as $field=>$field_value)
2399
+        $nullvalue = '';
2400
+        foreach ($this->field_defs as $field=>$field_value)
2401 2401
         {
2402
-            if(($field == 'user_preferences' && $this->module_dir == 'Users') || ($field == 'internal' && $this->module_dir == 'Cases') )
2402
+            if (($field == 'user_preferences' && $this->module_dir == 'Users') || ($field == 'internal' && $this->module_dir == 'Cases'))
2403 2403
                 continue;
2404
-            if(isset($row[$field]))
2404
+            if (isset($row[$field]))
2405 2405
             {
2406 2406
                 $this->$field = $row[$field];
2407
-                $owner = $field . '_owner';
2408
-                if(!empty($row[$owner])){
2407
+                $owner = $field.'_owner';
2408
+                if (!empty($row[$owner])) {
2409 2409
                     $this->$owner = $row[$owner];
2410 2410
                 }
2411 2411
             }
@@ -2447,48 +2447,48 @@  discard block
 block discarded – undo
2447 2447
     function create_list_count_query($query)
2448 2448
     {
2449 2449
         // remove the 'order by' clause which is expected to be at the end of the query
2450
-        $pattern = '/\sORDER BY.*/is';  // ignores the case
2450
+        $pattern = '/\sORDER BY.*/is'; // ignores the case
2451 2451
         $replacement = '';
2452 2452
         $query = preg_replace($pattern, $replacement, $query);
2453 2453
         //handle distinct clause
2454 2454
         $star = '*';
2455
-        if(substr_count(strtolower($query), 'distinct')){
2456
-            if (!empty($this->seed) && !empty($this->seed->table_name ))
2457
-                $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2455
+        if (substr_count(strtolower($query), 'distinct')) {
2456
+            if (!empty($this->seed) && !empty($this->seed->table_name))
2457
+                $star = 'DISTINCT '.$this->seed->table_name.'.id';
2458 2458
             else
2459
-                $star = 'DISTINCT ' . $this->table_name . '.id';
2459
+                $star = 'DISTINCT '.$this->table_name.'.id';
2460 2460
 
2461 2461
         }
2462 2462
 
2463 2463
         // change the select expression to 'count(*)'
2464
-        $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is';  // ignores the case
2465
-        $replacement = 'SELECT count(' . $star . ') c FROM ';
2464
+        $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is'; // ignores the case
2465
+        $replacement = 'SELECT count('.$star.') c FROM ';
2466 2466
 
2467 2467
         //if the passed query has union clause then replace all instances of the pattern.
2468 2468
         //this is very rare. I have seen this happening only from projects module.
2469 2469
         //in addition to this added a condition that has  union clause and uses
2470 2470
         //sub-selects.
2471
-        if (strstr($query," UNION ALL ") !== false) {
2471
+        if (strstr($query, " UNION ALL ") !== false) {
2472 2472
 
2473 2473
             //separate out all the queries.
2474
-            $union_qs=explode(" UNION ALL ", $query);
2474
+            $union_qs = explode(" UNION ALL ", $query);
2475 2475
             foreach ($union_qs as $key=>$union_query) {
2476 2476
                 $star = '*';
2477 2477
                 preg_match($pattern, $union_query, $matches);
2478 2478
                 if (!empty($matches)) {
2479 2479
                     if (stristr($matches[0], "distinct")) {
2480
-                        if (!empty($this->seed) && !empty($this->seed->table_name ))
2481
-                            $star = 'DISTINCT ' . $this->seed->table_name . '.id';
2480
+                        if (!empty($this->seed) && !empty($this->seed->table_name))
2481
+                            $star = 'DISTINCT '.$this->seed->table_name.'.id';
2482 2482
                         else
2483
-                            $star = 'DISTINCT ' . $this->table_name . '.id';
2483
+                            $star = 'DISTINCT '.$this->table_name.'.id';
2484 2484
                     }
2485 2485
                 } // if
2486
-                $replacement = 'SELECT count(' . $star . ') c FROM ';
2487
-                $union_qs[$key] = preg_replace($pattern, $replacement, $union_query,1);
2486
+                $replacement = 'SELECT count('.$star.') c FROM ';
2487
+                $union_qs[$key] = preg_replace($pattern, $replacement, $union_query, 1);
2488 2488
             }
2489
-            $modified_select_query=implode(" UNION ALL ",$union_qs);
2489
+            $modified_select_query = implode(" UNION ALL ", $union_qs);
2490 2490
         } else {
2491
-            $modified_select_query = preg_replace($pattern, $replacement, $query,1);
2491
+            $modified_select_query = preg_replace($pattern, $replacement, $query, 1);
2492 2492
         }
2493 2493
 
2494 2494
 
@@ -2511,15 +2511,15 @@  discard block
 block discarded – undo
2511 2511
     * Internal function, do not override.
2512 2512
     *
2513 2513
     */
2514
-    function get_list($order_by = "", $where = "", $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $singleSelect=false, $select_fields = array())
2514
+    function get_list($order_by = "", $where = "", $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0, $singleSelect = false, $select_fields = array())
2515 2515
     {
2516 2516
         $GLOBALS['log']->debug("get_list:  order_by = '$order_by' and where = '$where' and limit = '$limit'");
2517
-        if(isset($_SESSION['show_deleted']))
2517
+        if (isset($_SESSION['show_deleted']))
2518 2518
         {
2519 2519
             $show_deleted = 1;
2520 2520
         }
2521 2521
 
2522
-        if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
2522
+        if ($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list'))
2523 2523
         {
2524 2524
             global $current_user;
2525 2525
             $owner_where = $this->getOwnerWhere($current_user->id);
@@ -2527,15 +2527,15 @@  discard block
 block discarded – undo
2527 2527
             //rrs - because $this->getOwnerWhere() can return '' we need to be sure to check for it and
2528 2528
             //handle it properly else you could get into a situation where you are create a where stmt like
2529 2529
             //WHERE .. AND ''
2530
-            if(!empty($owner_where)){
2531
-                if(empty($where)){
2530
+            if (!empty($owner_where)) {
2531
+                if (empty($where)) {
2532 2532
                     $where = $owner_where;
2533
-                }else{
2534
-                    $where .= ' AND '.  $owner_where;
2533
+                } else {
2534
+                    $where .= ' AND '.$owner_where;
2535 2535
                 }
2536 2536
             }
2537 2537
         }
2538
-        $query = $this->create_new_list_query($order_by, $where,$select_fields,array(), $show_deleted,'',false,null,$singleSelect);
2538
+        $query = $this->create_new_list_query($order_by, $where, $select_fields, array(), $show_deleted, '', false, null, $singleSelect);
2539 2539
         return $this->process_list_query($query, $row_offset, $limit, $max, $where);
2540 2540
     }
2541 2541
 
@@ -2581,9 +2581,9 @@  discard block
 block discarded – undo
2581 2581
 
2582 2582
                 if (empty($field_defs['table']) && !$suppress_table_name) {
2583 2583
                     if ($source == 'db') {
2584
-                        $list_column[0] = $bean_queried->table_name . '.' . $list_column[0] ;
2584
+                        $list_column[0] = $bean_queried->table_name.'.'.$list_column[0];
2585 2585
                     } elseif ($source == 'custom_fields') {
2586
-                        $list_column[0] = $bean_queried->table_name . '_cstm.' . $list_column[0] ;
2586
+                        $list_column[0] = $bean_queried->table_name.'_cstm.'.$list_column[0];
2587 2587
                     }
2588 2588
                 }
2589 2589
 
@@ -2637,49 +2637,49 @@  discard block
 block discarded – undo
2637 2637
     *
2638 2638
     * Internal function, do not override.
2639 2639
     */
2640
-    function get_detail($order_by = "", $where = "",  $offset = 0, $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0)
2640
+    function get_detail($order_by = "", $where = "", $offset = 0, $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0)
2641 2641
     {
2642 2642
         $GLOBALS['log']->debug("get_detail:  order_by = '$order_by' and where = '$where' and limit = '$limit' and offset = '$offset'");
2643
-        if(isset($_SESSION['show_deleted']))
2643
+        if (isset($_SESSION['show_deleted']))
2644 2644
         {
2645 2645
             $show_deleted = 1;
2646 2646
         }
2647 2647
 
2648
-        if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
2648
+        if ($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list'))
2649 2649
         {
2650 2650
             global $current_user;
2651 2651
             $owner_where = $this->getOwnerWhere($current_user->id);
2652 2652
 
2653
-            if(empty($where))
2653
+            if (empty($where))
2654 2654
             {
2655 2655
                 $where = $owner_where;
2656 2656
             }
2657 2657
             else
2658 2658
             {
2659
-                $where .= ' AND '.  $owner_where;
2659
+                $where .= ' AND '.$owner_where;
2660 2660
             }
2661 2661
         }
2662 2662
 
2663 2663
 		/* BEGIN - SECURITY GROUPS */
2664
-    	if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
2664
+    	if ($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list'))
2665 2665
     	{
2666 2666
 			require_once('modules/SecurityGroups/SecurityGroup.php');
2667 2667
     		global $current_user;
2668 2668
     		$owner_where = $this->getOwnerWhere($current_user->id);
2669
-    		$group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
2670
-	    	if(!empty($owner_where)){
2671
-				if(empty($where))
2669
+    		$group_where = SecurityGroup::getGroupWhere($this->table_name, $this->module_dir, $current_user->id);
2670
+	    	if (!empty($owner_where)) {
2671
+				if (empty($where))
2672 2672
 	    		{
2673
-	    			$where = " (".  $owner_where." or ".$group_where.") ";
2673
+	    			$where = " (".$owner_where." or ".$group_where.") ";
2674 2674
 	    		} else {
2675
-	    			$where .= " AND (".  $owner_where." or ".$group_where.") ";
2675
+	    			$where .= " AND (".$owner_where." or ".$group_where.") ";
2676 2676
 	    		}
2677 2677
 			} else {
2678
-				$where .= ' AND '.  $group_where;
2678
+				$where .= ' AND '.$group_where;
2679 2679
 			}
2680 2680
     	}
2681 2681
     	/* END - SECURITY GROUPS */
2682
-        $query = $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted, $offset);
2682
+        $query = $this->create_new_list_query($order_by, $where, array(), array(), $show_deleted, $offset);
2683 2683
 
2684 2684
         //Add Limit and Offset to query
2685 2685
         //$query .= " LIMIT 1 OFFSET $offset";
@@ -2698,13 +2698,13 @@  discard block
 block discarded – undo
2698 2698
     *
2699 2699
     * Internal function, do not override.
2700 2700
     */
2701
-    function get_related_list($child_seed,$related_field_name, $order_by = "", $where = "",
2702
-    $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0)
2701
+    function get_related_list($child_seed, $related_field_name, $order_by = "", $where = "",
2702
+    $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0)
2703 2703
     {
2704 2704
         global $layout_edit_mode;
2705 2705
         $query_array = array();
2706 2706
 
2707
-        if(isset($layout_edit_mode) && $layout_edit_mode)
2707
+        if (isset($layout_edit_mode) && $layout_edit_mode)
2708 2708
         {
2709 2709
             $response = array();
2710 2710
             $child_seed->assign_display_fields($child_seed->module_dir);
@@ -2716,7 +2716,7 @@  discard block
 block discarded – undo
2716 2716
             return $response;
2717 2717
         }
2718 2718
         $GLOBALS['log']->debug("get_related_list:  order_by = '$order_by' and where = '$where' and limit = '$limit'");
2719
-        if(isset($_SESSION['show_deleted']))
2719
+        if (isset($_SESSION['show_deleted']))
2720 2720
         {
2721 2721
             $show_deleted = 1;
2722 2722
         }
@@ -2735,22 +2735,22 @@  discard block
 block discarded – undo
2735 2735
         }
2736 2736
 
2737 2737
         $entire_where = $query_array['where'];
2738
-        if(!empty($where))
2738
+        if (!empty($where))
2739 2739
         {
2740
-            if(empty($entire_where))
2740
+            if (empty($entire_where))
2741 2741
             {
2742
-                $entire_where = ' WHERE ' . $where;
2742
+                $entire_where = ' WHERE '.$where;
2743 2743
             }
2744 2744
             else
2745 2745
             {
2746
-                $entire_where .= ' AND ' . $where;
2746
+                $entire_where .= ' AND '.$where;
2747 2747
             }
2748 2748
         }
2749 2749
 
2750
-        $query = 'SELECT '.$child_seed->table_name.'.* ' . $query_array['from'] . ' ' . $entire_where;
2751
-        if(!empty($order_by))
2750
+        $query = 'SELECT '.$child_seed->table_name.'.* '.$query_array['from'].' '.$entire_where;
2751
+        if (!empty($order_by))
2752 2752
         {
2753
-            $query .= " ORDER BY " . $order_by;
2753
+            $query .= " ORDER BY ".$order_by;
2754 2754
         }
2755 2755
 
2756 2756
         return $child_seed->process_list_query($query, $row_offset, $limit, $max, $where);
@@ -2761,27 +2761,27 @@  discard block
 block discarded – undo
2761 2761
     {
2762 2762
         global $layout_edit_mode, $beanFiles, $beanList;
2763 2763
         $subqueries = array();
2764
-        foreach($subpanel_list as $this_subpanel)
2764
+        foreach ($subpanel_list as $this_subpanel)
2765 2765
         {
2766
-            if(!$this_subpanel->isDatasourceFunction() || ($this_subpanel->isDatasourceFunction()
2766
+            if (!$this_subpanel->isDatasourceFunction() || ($this_subpanel->isDatasourceFunction()
2767 2767
                 && isset($this_subpanel->_instance_properties['generate_select'])
2768
-                && $this_subpanel->_instance_properties['generate_select']==true))
2768
+                && $this_subpanel->_instance_properties['generate_select'] == true))
2769 2769
             {
2770 2770
                 //the custom query function must return an array with
2771 2771
                 if ($this_subpanel->isDatasourceFunction()) {
2772 2772
                     $shortcut_function_name = $this_subpanel->get_data_source_name();
2773
-                    $parameters=$this_subpanel->get_function_parameters();
2773
+                    $parameters = $this_subpanel->get_function_parameters();
2774 2774
                     if (!empty($parameters))
2775 2775
                     {
2776 2776
                         //if the import file function is set, then import the file to call the custom function from
2777
-                        if (is_array($parameters)  && isset($parameters['import_function_file'])){
2777
+                        if (is_array($parameters) && isset($parameters['import_function_file'])) {
2778 2778
                             //this call may happen multiple times, so only require if function does not exist
2779
-                            if(!function_exists($shortcut_function_name)){
2779
+                            if (!function_exists($shortcut_function_name)) {
2780 2780
                                 require_once($parameters['import_function_file']);
2781 2781
                             }
2782 2782
                             //call function from required file
2783 2783
                             $query_array = $shortcut_function_name($parameters);
2784
-                        }else{
2784
+                        } else {
2785 2785
                             //call function from parent bean
2786 2786
                             $query_array = $parentbean->$shortcut_function_name($parameters);
2787 2787
                         }
@@ -2790,9 +2790,9 @@  discard block
 block discarded – undo
2790 2790
                     {
2791 2791
                         $query_array = $parentbean->$shortcut_function_name();
2792 2792
                     }
2793
-                }  else {
2793
+                } else {
2794 2794
                     $related_field_name = $this_subpanel->get_data_source_name();
2795
-                    if (!$parentbean->load_relationship($related_field_name)){
2795
+                    if (!$parentbean->load_relationship($related_field_name)) {
2796 2796
                         unset ($parentbean->$related_field_name);
2797 2797
                         continue;
2798 2798
                     }
@@ -2801,15 +2801,15 @@  discard block
 block discarded – undo
2801 2801
                 $table_where = preg_replace('/^\s*WHERE/i', '', $this_subpanel->get_where());
2802 2802
                 $where_definition = preg_replace('/^\s*WHERE/i', '', $query_array['where']);
2803 2803
 
2804
-                if(!empty($table_where))
2804
+                if (!empty($table_where))
2805 2805
                 {
2806
-                    if(empty($where_definition))
2806
+                    if (empty($where_definition))
2807 2807
                     {
2808 2808
                         $where_definition = $table_where;
2809 2809
                     }
2810 2810
                     else
2811 2811
                     {
2812
-                        $where_definition .= ' AND ' . $table_where;
2812
+                        $where_definition .= ' AND '.$table_where;
2813 2813
                     }
2814 2814
                 }
2815 2815
 
@@ -2824,21 +2824,21 @@  discard block
 block discarded – undo
2824 2824
 
2825 2825
 
2826 2826
                 $list_fields = $this_subpanel->get_list_fields();
2827
-                foreach($list_fields as $list_key=>$list_field)
2827
+                foreach ($list_fields as $list_key=>$list_field)
2828 2828
                 {
2829
-                    if(isset($list_field['usage']) && $list_field['usage'] == 'display_only')
2829
+                    if (isset($list_field['usage']) && $list_field['usage'] == 'display_only')
2830 2830
                     {
2831 2831
                         unset($list_fields[$list_key]);
2832 2832
                     }
2833 2833
                 }
2834 2834
 
2835 2835
 
2836
-                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
+                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'))
2837 2837
                 {
2838
-                    $order_by = $submodule->table_name .'.'. $order_by;
2838
+                    $order_by = $submodule->table_name.'.'.$order_by;
2839 2839
                 }
2840 2840
                 $table_name = $this_subpanel->table_name;
2841
-                $panel_name=$this_subpanel->name;
2841
+                $panel_name = $this_subpanel->name;
2842 2842
                 $params = array();
2843 2843
                 $params['distinct'] = $this_subpanel->distinct_query();
2844 2844
 
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
                 // use single select in case when sorting by relate field
2850 2850
                 $singleSelect = $submodule->is_relate_field($order_by);
2851 2851
 
2852
-                $subquery = $submodule->create_new_list_query('',$subwhere ,$list_fields,$params, 0,'', true,$parentbean, $singleSelect);
2852
+                $subquery = $submodule->create_new_list_query('', $subwhere, $list_fields, $params, 0, '', true, $parentbean, $singleSelect);
2853 2853
 
2854 2854
                 $subquery['select'] = $subquery['select']." , '$panel_name' panel_name ";
2855 2855
                 $subquery['from'] = $subquery['from'].$query_array['join'];
@@ -2881,27 +2881,27 @@  discard block
 block discarded – undo
2881 2881
      *
2882 2882
      * Internal Function, do not overide.
2883 2883
      */
2884
-    static function get_union_related_list($parentbean, $order_by = "", $sort_order='', $where = "",
2885
-    $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $subpanel_def)
2884
+    static function get_union_related_list($parentbean, $order_by = "", $sort_order = '', $where = "",
2885
+    $row_offset = 0, $limit = -1, $max = -1, $show_deleted = 0, $subpanel_def)
2886 2886
     {
2887 2887
         $secondary_queries = array();
2888 2888
         global $layout_edit_mode, $beanFiles, $beanList;
2889 2889
 
2890
-        if(isset($_SESSION['show_deleted']))
2890
+        if (isset($_SESSION['show_deleted']))
2891 2891
         {
2892 2892
             $show_deleted = 1;
2893 2893
         }
2894 2894
         $final_query = '';
2895 2895
         $final_query_rows = '';
2896
-        $subpanel_list=array();
2896
+        $subpanel_list = array();
2897 2897
         if ($subpanel_def->isCollection())
2898 2898
         {
2899 2899
             $subpanel_def->load_sub_subpanels();
2900
-            $subpanel_list=$subpanel_def->sub_subpanels;
2900
+            $subpanel_list = $subpanel_def->sub_subpanels;
2901 2901
         }
2902 2902
         else
2903 2903
         {
2904
-            $subpanel_list[]=$subpanel_def;
2904
+            $subpanel_list[] = $subpanel_def;
2905 2905
         }
2906 2906
 
2907 2907
         $first = true;
@@ -2910,36 +2910,36 @@  discard block
 block discarded – undo
2910 2910
         //The second loop merges the queries and forces them to select the same number of columns
2911 2911
         //All columns in a sub-subpanel group must have the same aliases
2912 2912
         //If the subpanel is a datasource function, it can't be a collection so we just poll that function for the and return that
2913
-        foreach($subpanel_list as $this_subpanel)
2913
+        foreach ($subpanel_list as $this_subpanel)
2914 2914
         {
2915
-            if($this_subpanel->isDatasourceFunction() && empty($this_subpanel->_instance_properties['generate_select']))
2915
+            if ($this_subpanel->isDatasourceFunction() && empty($this_subpanel->_instance_properties['generate_select']))
2916 2916
             {
2917 2917
                 $shortcut_function_name = $this_subpanel->get_data_source_name();
2918
-                $parameters=$this_subpanel->get_function_parameters();
2918
+                $parameters = $this_subpanel->get_function_parameters();
2919 2919
                 if (!empty($parameters))
2920 2920
                 {
2921 2921
                     //if the import file function is set, then import the file to call the custom function from
2922
-                    if (is_array($parameters)  && isset($parameters['import_function_file'])){
2922
+                    if (is_array($parameters) && isset($parameters['import_function_file'])) {
2923 2923
                         //this call may happen multiple times, so only require if function does not exist
2924
-                        if(!function_exists($shortcut_function_name)){
2924
+                        if (!function_exists($shortcut_function_name)) {
2925 2925
                             require_once($parameters['import_function_file']);
2926 2926
                         }
2927 2927
                         //call function from required file
2928
-                        $tmp_final_query =  $shortcut_function_name($parameters);
2929
-                    }else{
2928
+                        $tmp_final_query = $shortcut_function_name($parameters);
2929
+                    } else {
2930 2930
                         //call function from parent bean
2931
-                        $tmp_final_query =  $parentbean->$shortcut_function_name($parameters);
2931
+                        $tmp_final_query = $parentbean->$shortcut_function_name($parameters);
2932 2932
                     }
2933 2933
                 } else {
2934 2934
                     $tmp_final_query = $parentbean->$shortcut_function_name();
2935 2935
                 }
2936
-                if(!$first)
2936
+                if (!$first)
2937 2937
                     {
2938
-                        $final_query_rows .= ' UNION ALL ( '.$parentbean->create_list_count_query($tmp_final_query, $parameters) . ' )';
2939
-                        $final_query .= ' UNION ALL ( '.$tmp_final_query . ' )';
2938
+                        $final_query_rows .= ' UNION ALL ( '.$parentbean->create_list_count_query($tmp_final_query, $parameters).' )';
2939
+                        $final_query .= ' UNION ALL ( '.$tmp_final_query.' )';
2940 2940
                     } else {
2941
-                        $final_query_rows = '(' . $parentbean->create_list_count_query($tmp_final_query, $parameters) . ')';
2942
-                        $final_query = '(' . $tmp_final_query . ')';
2941
+                        $final_query_rows = '('.$parentbean->create_list_count_query($tmp_final_query, $parameters).')';
2942
+                        $final_query = '('.$tmp_final_query.')';
2943 2943
                         $first = false;
2944 2944
                     }
2945 2945
                 }
@@ -2949,10 +2949,10 @@  discard block
 block discarded – undo
2949 2949
         {
2950 2950
             $subqueries = SugarBean::build_sub_queries_for_union($subpanel_list, $subpanel_def, $parentbean, $order_by);
2951 2951
             $all_fields = array();
2952
-            foreach($subqueries as $i => $subquery)
2952
+            foreach ($subqueries as $i => $subquery)
2953 2953
             {
2954 2954
                 $query_fields = $GLOBALS['db']->getSelectFieldsFromQuery($subquery['select']);
2955
-                foreach($query_fields as $field => $select)
2955
+                foreach ($query_fields as $field => $select)
2956 2956
                 {
2957 2957
                     if (!in_array($field, $all_fields))
2958 2958
                         $all_fields[] = $field;
@@ -2961,10 +2961,10 @@  discard block
 block discarded – undo
2961 2961
             }
2962 2962
             $first = true;
2963 2963
             //Now ensure the queries have the same set of fields in the same order.
2964
-            foreach($subqueries as $subquery)
2964
+            foreach ($subqueries as $subquery)
2965 2965
             {
2966 2966
                 $subquery['select'] = "SELECT";
2967
-                foreach($all_fields as $field)
2967
+                foreach ($all_fields as $field)
2968 2968
                 {
2969 2969
                     if (!isset($subquery['query_fields'][$field]))
2970 2970
                     {
@@ -2975,56 +2975,56 @@  discard block
 block discarded – undo
2975 2975
                         $subquery['select'] .= " {$subquery['query_fields'][$field]},";
2976 2976
                     }
2977 2977
                 }
2978
-                $subquery['select'] = substr($subquery['select'], 0 , strlen($subquery['select']) - 1);
2978
+                $subquery['select'] = substr($subquery['select'], 0, strlen($subquery['select']) - 1);
2979 2979
                 //Put the query into the final_query
2980
-                $query =  $subquery['select'] . " " . $subquery['from'] . " " . $subquery['where'];
2981
-                if(!$first)
2980
+                $query = $subquery['select']." ".$subquery['from']." ".$subquery['where'];
2981
+                if (!$first)
2982 2982
                 {
2983
-                    $query = ' UNION ALL ( '.$query . ' )';
2983
+                    $query = ' UNION ALL ( '.$query.' )';
2984 2984
                     $final_query_rows .= " UNION ALL ";
2985 2985
                 } else {
2986
-                    $query = '(' . $query . ')';
2986
+                    $query = '('.$query.')';
2987 2987
                     $first = false;
2988 2988
                 }
2989 2989
                 $query_array = $subquery['query_array'];
2990
-                $select_position=strpos($query_array['select'],"SELECT");
2991
-                $distinct_position=strpos($query_array['select'],"DISTINCT");
2990
+                $select_position = strpos($query_array['select'], "SELECT");
2991
+                $distinct_position = strpos($query_array['select'], "DISTINCT");
2992 2992
                 if (!empty($subquery['params']['distinct']) && !empty($subpanel_def->table_name))
2993 2993
                 {
2994
-                    $query_rows = "( SELECT count(DISTINCT ". $subpanel_def->table_name . ".id)".  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
2994
+                    $query_rows = "( SELECT count(DISTINCT ".$subpanel_def->table_name.".id)".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
2995 2995
                 }
2996
-                elseif ($select_position !== false && $distinct_position!= false)
2996
+                elseif ($select_position !== false && $distinct_position != false)
2997 2997
                 {
2998
-                    $query_rows = "( ".substr_replace($query_array['select'],"SELECT count(",$select_position,6). ")" .  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
2998
+                    $query_rows = "( ".substr_replace($query_array['select'], "SELECT count(", $select_position, 6).")".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
2999 2999
                 }
3000 3000
                 else
3001 3001
                 {
3002 3002
                     //resort to default behavior.
3003
-                    $query_rows = "( SELECT count(*)".  $subquery['from_min'].$query_array['join']. $subquery['where'].' )';
3003
+                    $query_rows = "( SELECT count(*)".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
3004 3004
                 }
3005
-                if(!empty($subquery['secondary_select']))
3005
+                if (!empty($subquery['secondary_select']))
3006 3006
                 {
3007 3007
 
3008
-                    $subquerystring= $subquery['secondary_select'] . $subquery['secondary_from'].$query_array['join']. $subquery['where'];
3008
+                    $subquerystring = $subquery['secondary_select'].$subquery['secondary_from'].$query_array['join'].$subquery['where'];
3009 3009
                     if (!empty($subquery['secondary_where']))
3010 3010
                     {
3011 3011
                         if (empty($subquery['where']))
3012 3012
                         {
3013
-                            $subquerystring.=" WHERE " .$subquery['secondary_where'];
3013
+                            $subquerystring .= " WHERE ".$subquery['secondary_where'];
3014 3014
                         }
3015 3015
                         else
3016 3016
                         {
3017
-                            $subquerystring.=" AND " .$subquery['secondary_where'];
3017
+                            $subquerystring .= " AND ".$subquery['secondary_where'];
3018 3018
                         }
3019 3019
                     }
3020
-                    $secondary_queries[]=$subquerystring;
3020
+                    $secondary_queries[] = $subquerystring;
3021 3021
                 }
3022 3022
                 $final_query .= $query;
3023 3023
                 $final_query_rows .= $query_rows;
3024 3024
             }
3025 3025
         }
3026 3026
 
3027
-        if(!empty($order_by))
3027
+        if (!empty($order_by))
3028 3028
         {
3029 3029
             $isCollection = $subpanel_def->isCollection();
3030 3030
             if ($isCollection) {
@@ -3038,20 +3038,20 @@  discard block
 block discarded – undo
3038 3038
             }
3039 3039
 
3040 3040
             if (!empty($sort_order)) {
3041
-                $order_by .= ' ' . $sort_order;
3041
+                $order_by .= ' '.$sort_order;
3042 3042
             }
3043 3043
 
3044 3044
             $order_by = $parentbean->process_order_by($order_by, $submodule, $suppress_table_name);
3045 3045
             if (!empty($order_by)) {
3046
-                $final_query .= ' ORDER BY ' . $order_by;
3046
+                $final_query .= ' ORDER BY '.$order_by;
3047 3047
             }
3048 3048
         }
3049 3049
 
3050 3050
 
3051
-        if(isset($layout_edit_mode) && $layout_edit_mode)
3051
+        if (isset($layout_edit_mode) && $layout_edit_mode)
3052 3052
         {
3053 3053
             $response = array();
3054
-            if(!empty($submodule))
3054
+            if (!empty($submodule))
3055 3055
             {
3056 3056
                 $submodule->assign_display_fields($submodule->module_dir);
3057 3057
                 $response['list'] = array($submodule);
@@ -3068,7 +3068,7 @@  discard block
 block discarded – undo
3068 3068
             return $response;
3069 3069
         }
3070 3070
 
3071
-        return $parentbean->process_union_list_query($parentbean, $final_query, $row_offset, $limit, $max, '',$subpanel_def, $final_query_rows, $secondary_queries);
3071
+        return $parentbean->process_union_list_query($parentbean, $final_query, $row_offset, $limit, $max, '', $subpanel_def, $final_query_rows, $secondary_queries);
3072 3072
     }
3073 3073
 
3074 3074
 
@@ -3080,14 +3080,14 @@  discard block
 block discarded – undo
3080 3080
     * @param boolean $check_dates. defaults to false
3081 3081
     * @param int $show_deleted show deleted records. defaults to 0
3082 3082
     */
3083
-    function get_full_list($order_by = "", $where = "", $check_dates=false, $show_deleted = 0)
3083
+    function get_full_list($order_by = "", $where = "", $check_dates = false, $show_deleted = 0)
3084 3084
     {
3085 3085
         $GLOBALS['log']->debug("get_full_list:  order_by = '$order_by' and where = '$where'");
3086
-        if(isset($_SESSION['show_deleted']))
3086
+        if (isset($_SESSION['show_deleted']))
3087 3087
         {
3088 3088
             $show_deleted = 1;
3089 3089
         }
3090
-        $query = $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted);
3090
+        $query = $this->create_new_list_query($order_by, $where, array(), array(), $show_deleted);
3091 3091
         return $this->process_full_list_query($query, $check_dates);
3092 3092
     }
3093 3093
 
@@ -3107,29 +3107,29 @@  discard block
 block discarded – undo
3107 3107
      * @param boolean $singleSelect Optional, default false.
3108 3108
      * @return String select query string, optionally an array value will be returned if $return_array= true.
3109 3109
      */
3110
-	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
+	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)
3111 3111
     {
3112 3112
         global $beanFiles, $beanList;
3113 3113
         $selectedFields = array();
3114 3114
         $secondarySelectedFields = array();
3115 3115
         $ret_array = array();
3116 3116
         $distinct = '';
3117
-        if($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list') )
3117
+        if ($this->bean_implements('ACL') && ACLController::requireOwner($this->module_dir, 'list'))
3118 3118
         {
3119 3119
             global $current_user;
3120 3120
             $owner_where = $this->getOwnerWhere($current_user->id);
3121
-            if(empty($where))
3121
+            if (empty($where))
3122 3122
             {
3123 3123
                 $where = $owner_where;
3124 3124
             }
3125 3125
             else
3126 3126
             {
3127
-                $where .= ' AND '.  $owner_where;
3127
+                $where .= ' AND '.$owner_where;
3128 3128
             }
3129 3129
         }
3130 3130
 		/* BEGIN - SECURITY GROUPS */
3131 3131
     	global $current_user, $sugar_config;
3132
-    	if($this->module_dir == 'Users' && !is_admin($current_user)
3132
+    	if ($this->module_dir == 'Users' && !is_admin($current_user)
3133 3133
 				&& isset($sugar_config['securitysuite_filter_user_list'])
3134 3134
 				&& $sugar_config['securitysuite_filter_user_list'] == true
3135 3135
     	) {
@@ -3137,36 +3137,36 @@  discard block
 block discarded – undo
3137 3137
     		global $current_user;
3138 3138
     		$group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
3139 3139
     		//$group_where = "user_name = 'admin'";
3140
-    		if(empty($where))
3140
+    		if (empty($where))
3141 3141
     		{
3142 3142
     			$where = " (".$group_where.") ";
3143 3143
     		} else {
3144 3144
     			$where .= " AND (".$group_where.") ";
3145 3145
     		}
3146 3146
     	} else
3147
-    	if($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list') )
3147
+    	if ($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list'))
3148 3148
     	{
3149 3149
 			require_once('modules/SecurityGroups/SecurityGroup.php');
3150 3150
     		global $current_user;
3151 3151
     		$owner_where = $this->getOwnerWhere($current_user->id);
3152
-    		$group_where = SecurityGroup::getGroupWhere($this->table_name,$this->module_dir,$current_user->id);
3153
-	    	if(!empty($owner_where)){
3154
-				if(empty($where))
3152
+    		$group_where = SecurityGroup::getGroupWhere($this->table_name, $this->module_dir, $current_user->id);
3153
+	    	if (!empty($owner_where)) {
3154
+				if (empty($where))
3155 3155
 	    		{
3156
-	    			$where = " (".  $owner_where." or ".$group_where.") ";
3156
+	    			$where = " (".$owner_where." or ".$group_where.") ";
3157 3157
 	    		} else {
3158
-	    			$where .= " AND (".  $owner_where." or ".$group_where.") ";
3158
+	    			$where .= " AND (".$owner_where." or ".$group_where.") ";
3159 3159
 	    		}
3160 3160
 			} else {
3161
-				$where .= ' AND '.  $group_where;
3161
+				$where .= ' AND '.$group_where;
3162 3162
 			}
3163 3163
     	}
3164 3164
     	/* END - SECURITY GROUPS */
3165
-        if(!empty($params['distinct']))
3165
+        if (!empty($params['distinct']))
3166 3166
         {
3167 3167
             $distinct = ' DISTINCT ';
3168 3168
         }
3169
-        if(empty($filter))
3169
+        if (empty($filter))
3170 3170
         {
3171 3171
             $ret_array['select'] = " SELECT $distinct $this->table_name.* ";
3172 3172
         }
@@ -3176,21 +3176,21 @@  discard block
 block discarded – undo
3176 3176
         }
3177 3177
         $ret_array['from'] = " FROM $this->table_name ";
3178 3178
         $ret_array['from_min'] = $ret_array['from'];
3179
-        $ret_array['secondary_from'] = $ret_array['from'] ;
3179
+        $ret_array['secondary_from'] = $ret_array['from'];
3180 3180
         $ret_array['where'] = '';
3181 3181
         $ret_array['order_by'] = '';
3182 3182
         //secondary selects are selects that need to be run after the primary query to retrieve additional info on main
3183
-        if($singleSelect)
3183
+        if ($singleSelect)
3184 3184
         {
3185
-            $ret_array['secondary_select']=& $ret_array['select'];
3185
+            $ret_array['secondary_select'] = & $ret_array['select'];
3186 3186
             $ret_array['secondary_from'] = & $ret_array['from'];
3187 3187
         }
3188 3188
         else
3189 3189
         {
3190 3190
             $ret_array['secondary_select'] = '';
3191 3191
         }
3192
-        $custom_join = $this->getCustomJoin( empty($filter)? true: $filter );
3193
-        if((!isset($params['include_custom_fields']) || $params['include_custom_fields']))
3192
+        $custom_join = $this->getCustomJoin(empty($filter) ? true : $filter);
3193
+        if ((!isset($params['include_custom_fields']) || $params['include_custom_fields']))
3194 3194
         {
3195 3195
             $ret_array['select'] .= $custom_join['select'];
3196 3196
         }
@@ -3206,43 +3206,43 @@  discard block
 block discarded – undo
3206 3206
         }
3207 3207
 
3208 3208
         $joined_tables = array();
3209
-        if(!empty($params['joined_tables']))
3209
+        if (!empty($params['joined_tables']))
3210 3210
         {
3211
-            foreach($params['joined_tables'] as $table)
3211
+            foreach ($params['joined_tables'] as $table)
3212 3212
             {
3213 3213
                 $joined_tables[$table] = 1;
3214 3214
             }
3215 3215
         }
3216 3216
 
3217
-        if(!empty($filter))
3217
+        if (!empty($filter))
3218 3218
         {
3219 3219
             $filterKeys = array_keys($filter);
3220
-            if(is_numeric($filterKeys[0]))
3220
+            if (is_numeric($filterKeys[0]))
3221 3221
             {
3222 3222
                 $fields = array();
3223
-                foreach($filter as $field)
3223
+                foreach ($filter as $field)
3224 3224
                 {
3225 3225
                     $field = strtolower($field);
3226 3226
                     //remove out id field so we don't duplicate it
3227
-                    if ( $field == 'id' && !empty($filter) ) {
3227
+                    if ($field == 'id' && !empty($filter)) {
3228 3228
                         continue;
3229 3229
                     }
3230
-                    if(isset($this->field_defs[$field]))
3230
+                    if (isset($this->field_defs[$field]))
3231 3231
                     {
3232
-                        $fields[$field]= $this->field_defs[$field];
3232
+                        $fields[$field] = $this->field_defs[$field];
3233 3233
                     }
3234 3234
                     else
3235 3235
                     {
3236 3236
                         $fields[$field] = array('force_exists'=>true);
3237 3237
                     }
3238 3238
                 }
3239
-            }else{
3240
-                $fields = 	$filter;
3239
+            } else {
3240
+                $fields = $filter;
3241 3241
             }
3242 3242
         }
3243 3243
         else
3244 3244
         {
3245
-            $fields = 	$this->field_defs;
3245
+            $fields = $this->field_defs;
3246 3246
         }
3247 3247
 
3248 3248
         $used_join_key = array();
@@ -3250,7 +3250,7 @@  discard block
 block discarded – undo
3250 3250
 	//walk through the fields and for every relationship field add their relationship_info field
3251 3251
 	//relationshipfield-aliases are resolved in SugarBean::create_new_list_query through their relationship_info field
3252 3252
 	$addrelate = array();
3253
-	foreach($fields as $field=>$value)
3253
+	foreach ($fields as $field=>$value)
3254 3254
 	{
3255 3255
 		if (isset($this->field_defs[$field]) && isset($this->field_defs[$field]['source']) && 
3256 3256
 			$this->field_defs[$field]['source'] == 'non-db')
@@ -3259,27 +3259,27 @@  discard block
 block discarded – undo
3259 3259
 			if ($addrelatefield)
3260 3260
 				$addrelate[$addrelatefield] = true;
3261 3261
 		}
3262
-		if(!empty($this->field_defs[$field]['id_name'])){
3262
+		if (!empty($this->field_defs[$field]['id_name'])) {
3263 3263
 			$addrelate[$this->field_defs[$field]['id_name']] = true;
3264 3264
 		}
3265 3265
 	}
3266 3266
 
3267 3267
 	$fields = array_merge($addrelate, $fields);
3268 3268
 
3269
-        foreach($fields as $field=>$value)
3269
+        foreach ($fields as $field=>$value)
3270 3270
         {
3271 3271
             //alias is used to alias field names
3272
-            $alias='';
3273
-            if 	(isset($value['alias']))
3272
+            $alias = '';
3273
+            if (isset($value['alias']))
3274 3274
             {
3275
-                $alias =' as ' . $value['alias'] . ' ';
3275
+                $alias = ' as '.$value['alias'].' ';
3276 3276
             }
3277 3277
 
3278
-            if(empty($this->field_defs[$field]) || !empty($value['force_blank']) )
3278
+            if (empty($this->field_defs[$field]) || !empty($value['force_blank']))
3279 3279
             {
3280
-                if(!empty($filter) && isset($filter[$field]['force_exists']) && $filter[$field]['force_exists'])
3280
+                if (!empty($filter) && isset($filter[$field]['force_exists']) && $filter[$field]['force_exists'])
3281 3281
                 {
3282
-                    if ( isset($filter[$field]['force_default']) )
3282
+                    if (isset($filter[$field]['force_default']))
3283 3283
                         $ret_array['select'] .= ", {$filter[$field]['force_default']} $field ";
3284 3284
                     else
3285 3285
                     //spaces are a fix for length issue problem with unions.  The union only returns the maximum number of characters from the first select statement.
@@ -3311,14 +3311,14 @@  discard block
 block discarded – undo
3311 3311
                 	continue;
3312 3312
             }
3313 3313
 
3314
-            if(  (!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter) ))
3314
+            if ((!isset($data['source']) || $data['source'] == 'db') && (!empty($alias) || !empty($filter)))
3315 3315
             {
3316 3316
                 $ret_array['select'] .= ", $this->table_name.$field $alias";
3317 3317
                 $selectedFields["$this->table_name.$field"] = true;
3318
-            } else if(  (!isset($data['source']) || $data['source'] == 'custom_fields') && (!empty($alias) || !empty($filter) )) {
3318
+            } else if ((!isset($data['source']) || $data['source'] == 'custom_fields') && (!empty($alias) || !empty($filter))) {
3319 3319
                 //add this column only if it has NOT already been added to select statement string
3320
-                $colPos = strpos($ret_array['select'],"$this->table_name"."_cstm".".$field");
3321
-                if(!$colPos || $colPos<0)
3320
+                $colPos = strpos($ret_array['select'], "$this->table_name"."_cstm".".$field");
3321
+                if (!$colPos || $colPos < 0)
3322 3322
                 {
3323 3323
                     $ret_array['select'] .= ", $this->table_name"."_cstm".".$field $alias";
3324 3324
                 }
@@ -3326,22 +3326,22 @@  discard block
 block discarded – undo
3326 3326
                 $selectedFields["$this->table_name.$field"] = true;
3327 3327
             }
3328 3328
 
3329
-            if($data['type'] != 'relate' && isset($data['db_concat_fields']))
3329
+            if ($data['type'] != 'relate' && isset($data['db_concat_fields']))
3330 3330
             {
3331
-                $ret_array['select'] .= ", " . $this->db->concat($this->table_name, $data['db_concat_fields']) . " as $field";
3331
+                $ret_array['select'] .= ", ".$this->db->concat($this->table_name, $data['db_concat_fields'])." as $field";
3332 3332
                 $selectedFields[$this->db->concat($this->table_name, $data['db_concat_fields'])] = true;
3333 3333
             }
3334 3334
             //Custom relate field or relate fields built in module builder which have no link field associated.
3335 3335
             if ($data['type'] == 'relate' && (isset($data['custom_module']) || isset($data['ext2']))) {
3336
-                $joinTableAlias = 'jt' . $jtcount;
3336
+                $joinTableAlias = 'jt'.$jtcount;
3337 3337
                 $relateJoinInfo = $this->custom_fields->getRelateJoin($data, $joinTableAlias, false);
3338 3338
                 $ret_array['select'] .= $relateJoinInfo['select'];
3339 3339
                 $ret_array['from'] .= $relateJoinInfo['from'];
3340 3340
                 //Replace any references to the relationship in the where clause with the new alias
3341 3341
                 //If the link isn't set, assume that search used the local table for the field
3342 3342
                 $searchTable = isset($data['link']) ? $relateJoinInfo['rel_table'] : $this->table_name;
3343
-                $field_name = $relateJoinInfo['rel_table'] . '.' . !empty($data['name'])?$data['name']:'name';
3344
-                $where = preg_replace('/(^|[\s(])' . $field_name . '/' , '${1}' . $relateJoinInfo['name_field'], $where);
3343
+                $field_name = $relateJoinInfo['rel_table'].'.'.!empty($data['name']) ? $data['name'] : 'name';
3344
+                $where = preg_replace('/(^|[\s(])'.$field_name.'/', '${1}'.$relateJoinInfo['name_field'], $where);
3345 3345
                 $jtcount++;
3346 3346
             }
3347 3347
             //Parent Field
@@ -3349,7 +3349,7 @@  discard block
 block discarded – undo
3349 3349
                 //See if we need to join anything by inspecting the where clause
3350 3350
                 $match = preg_match('/(^|[\s(])parent_([a-zA-Z]+_?[a-zA-Z]+)_([a-zA-Z]+_?[a-zA-Z]+)\.name/', $where, $matches);
3351 3351
                 if ($match) {
3352
-                    $joinTableAlias = 'jt' . $jtcount;
3352
+                    $joinTableAlias = 'jt'.$jtcount;
3353 3353
                     $joinModule = $matches[2];
3354 3354
                     $joinTable = $matches[3];
3355 3355
                     $localTable = $this->table_name;
@@ -3363,7 +3363,7 @@  discard block
 block discarded – undo
3363 3363
                     if (isset($rel_mod->field_defs['name']))
3364 3364
                     {
3365 3365
                         $name_field_def = $rel_mod->field_defs['name'];
3366
-                        if(isset($name_field_def['db_concat_fields']))
3366
+                        if (isset($name_field_def['db_concat_fields']))
3367 3367
                         {
3368 3368
                             $nameField = $this->db->concat($joinTableAlias, $name_field_def['db_concat_fields']);
3369 3369
                         }
@@ -3372,7 +3372,7 @@  discard block
 block discarded – undo
3372 3372
                     $ret_array['from'] .= " LEFT JOIN $joinTable $joinTableAlias
3373 3373
                         ON $localTable.{$data['id_name']} = $joinTableAlias.id";
3374 3374
                     //Replace any references to the relationship in the where clause with the new alias
3375
-                    $where = preg_replace('/(^|[\s(])parent_' . $joinModule . '_' . $joinTable . '\.name/', '${1}' . $nameField, $where);
3375
+                    $where = preg_replace('/(^|[\s(])parent_'.$joinModule.'_'.$joinTable.'\.name/', '${1}'.$nameField, $where);
3376 3376
                     $jtcount++;
3377 3377
                 }
3378 3378
             }
@@ -3381,10 +3381,10 @@  discard block
 block discarded – undo
3381 3381
             {
3382 3382
                 $linkField = $data['link'];
3383 3383
                 $this->load_relationship($linkField);
3384
-                if(!empty($this->$linkField))
3384
+                if (!empty($this->$linkField))
3385 3385
                 {
3386 3386
                     $params = array();
3387
-                    if(empty($join_type))
3387
+                    if (empty($join_type))
3388 3388
                     {
3389 3389
                         $params['join_type'] = ' LEFT JOIN ';
3390 3390
                     }
@@ -3392,22 +3392,22 @@  discard block
 block discarded – undo
3392 3392
                     {
3393 3393
                         $params['join_type'] = $join_type;
3394 3394
                     }
3395
-                    if(isset($data['join_name']))
3395
+                    if (isset($data['join_name']))
3396 3396
                     {
3397 3397
                         $params['join_table_alias'] = $data['join_name'];
3398 3398
                     }
3399 3399
                     else
3400 3400
                     {
3401
-                        $params['join_table_alias']	= 'jt' . $jtcount;
3401
+                        $params['join_table_alias'] = 'jt'.$jtcount;
3402 3402
 
3403 3403
                     }
3404
-                    if(isset($data['join_link_name']))
3404
+                    if (isset($data['join_link_name']))
3405 3405
                     {
3406 3406
                         $params['join_table_link_alias'] = $data['join_link_name'];
3407 3407
                     }
3408 3408
                     else
3409 3409
                     {
3410
-                        $params['join_table_link_alias'] = 'jtl' . $jtcount;
3410
+                        $params['join_table_link_alias'] = 'jtl'.$jtcount;
3411 3411
                     }
3412 3412
                     $join_primary = !isset($data['join_primary']) || $data['join_primary'];
3413 3413
 
@@ -3420,126 +3420,126 @@  discard block
 block discarded – undo
3420 3420
 					global $beanFiles, $beanList;
3421 3421
                     // °3/21/2014 FIX NS-TEAM - Relationship fields could not be displayed in subpanels
3422 3422
                     //if($data['rname'] && !empty($beanFiles[$beanList[$rel_module]])) {
3423
-                    if(isset($data['rname']) && $data['rname'] == 'name' && !empty($beanFiles[$beanList[$rel_module]])) {
3423
+                    if (isset($data['rname']) && $data['rname'] == 'name' && !empty($beanFiles[$beanList[$rel_module]])) {
3424 3424
 
3425 3425
 						//create an instance of the related bean
3426 3426
 						require_once($beanFiles[$beanList[$rel_module]]);
3427 3427
 						$rel_mod = new $beanList[$rel_module]();
3428 3428
 						//if bean has first and last name fields, then name should be concatenated
3429
-						if(isset($rel_mod->field_name_map['first_name']) && isset($rel_mod->field_name_map['last_name'])){
3429
+						if (isset($rel_mod->field_name_map['first_name']) && isset($rel_mod->field_name_map['last_name'])) {
3430 3430
 								$data['db_concat_fields'] = array(0=>'first_name', 1=>'last_name');
3431 3431
 						}
3432 3432
 					}
3433 3433
 
3434 3434
 
3435
-    				if($join['type'] == 'many-to-many')
3435
+    				if ($join['type'] == 'many-to-many')
3436 3436
     				{
3437
-    					if(empty($ret_array['secondary_select']))
3437
+    					if (empty($ret_array['secondary_select']))
3438 3438
     					{
3439 3439
     						$ret_array['secondary_select'] = " SELECT $this->table_name.id ref_id  ";
3440 3440
 
3441
-                            if(!empty($beanFiles[$beanList[$rel_module]]) && $join_primary)
3441
+                            if (!empty($beanFiles[$beanList[$rel_module]]) && $join_primary)
3442 3442
                             {
3443 3443
                                 require_once($beanFiles[$beanList[$rel_module]]);
3444 3444
                                 $rel_mod = new $beanList[$rel_module]();
3445
-                                if(isset($rel_mod->field_defs['assigned_user_id']))
3445
+                                if (isset($rel_mod->field_defs['assigned_user_id']))
3446 3446
                                 {
3447
-                                    $ret_array['secondary_select'].= " , ".	$params['join_table_alias'] . ".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3447
+                                    $ret_array['secondary_select'] .= " , ".$params['join_table_alias'].".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3448 3448
                                 }
3449 3449
                                 else
3450 3450
                                 {
3451
-                                    if(isset($rel_mod->field_defs['created_by']))
3451
+                                    if (isset($rel_mod->field_defs['created_by']))
3452 3452
                                     {
3453
-                                        $ret_array['secondary_select'].= " , ".	$params['join_table_alias'] . ".created_by {$field}_owner , '$rel_module' {$field}_mod";
3453
+                                        $ret_array['secondary_select'] .= " , ".$params['join_table_alias'].".created_by {$field}_owner , '$rel_module' {$field}_mod";
3454 3454
                                     }
3455 3455
                                 }
3456 3456
                             }
3457 3457
                         }
3458 3458
 
3459
-                        if(isset($data['db_concat_fields']))
3459
+                        if (isset($data['db_concat_fields']))
3460 3460
                         {
3461
-                            $ret_array['secondary_select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3461
+                            $ret_array['secondary_select'] .= ' , '.$this->db->concat($params['join_table_alias'], $data['db_concat_fields']).' '.$field;
3462 3462
                         }
3463 3463
                         else
3464 3464
                         {
3465
-                            if(!isset($data['relationship_fields']))
3465
+                            if (!isset($data['relationship_fields']))
3466 3466
                             {
3467
-                                $ret_array['secondary_select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3467
+                                $ret_array['secondary_select'] .= ' , '.$params['join_table_alias'].'.'.$data['rname'].' '.$field;
3468 3468
                             }
3469 3469
                         }
3470
-                        if(!$singleSelect)
3470
+                        if (!$singleSelect)
3471 3471
                         {
3472 3472
                             $ret_array['select'] .= ", '                                                                                                                                                                                                                                                              ' $field ";
3473 3473
                         }
3474
-                        $count_used =0;
3475
-                        foreach($used_join_key as $used_key) {
3476
-                            if($used_key == $join['rel_key']) $count_used++;
3474
+                        $count_used = 0;
3475
+                        foreach ($used_join_key as $used_key) {
3476
+                            if ($used_key == $join['rel_key']) $count_used++;
3477 3477
                         }
3478
-                        if($count_used <= 1) {//27416, the $ret_array['secondary_select'] should always generate, regardless the dbtype
3478
+                        if ($count_used <= 1) {//27416, the $ret_array['secondary_select'] should always generate, regardless the dbtype
3479 3479
                             // add rel_key only if it was not aready added
3480
-                            if(!$singleSelect)
3480
+                            if (!$singleSelect)
3481 3481
                             {
3482
-                                $ret_array['select'] .= ", '                                    '  " . $join['rel_key'] . ' ';
3482
+                                $ret_array['select'] .= ", '                                    '  ".$join['rel_key'].' ';
3483 3483
                             }
3484
-                            $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $join['rel_key'] .' ' . $join['rel_key'];
3484
+                            $ret_array['secondary_select'] .= ', '.$params['join_table_link_alias'].'.'.$join['rel_key'].' '.$join['rel_key'];
3485 3485
                         }
3486
-                        if(isset($data['relationship_fields']))
3486
+                        if (isset($data['relationship_fields']))
3487 3487
                         {
3488
-                            foreach($data['relationship_fields'] as $r_name=>$alias_name)
3488
+                            foreach ($data['relationship_fields'] as $r_name=>$alias_name)
3489 3489
                             {
3490
-                                if(!empty( $secondarySelectedFields[$alias_name]))continue;
3491
-                                $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'].'.'. $r_name .' ' . $alias_name;
3490
+                                if (!empty($secondarySelectedFields[$alias_name]))continue;
3491
+                                $ret_array['secondary_select'] .= ', '.$params['join_table_link_alias'].'.'.$r_name.' '.$alias_name;
3492 3492
                                 $secondarySelectedFields[$alias_name] = true;
3493 3493
                             }
3494 3494
                         }
3495
-                        if(!$table_joined)
3495
+                        if (!$table_joined)
3496 3496
                         {
3497
-                            $ret_array['secondary_from'] .= ' ' . $join['join']. ' AND ' . $params['join_table_alias'].'.deleted=0';
3497
+                            $ret_array['secondary_from'] .= ' '.$join['join'].' AND '.$params['join_table_alias'].'.deleted=0';
3498 3498
                             if (isset($data['link_type']) && $data['link_type'] == 'relationship_info' && ($parentbean instanceOf SugarBean))
3499 3499
                             {
3500
-                                $ret_array['secondary_where'] = $params['join_table_link_alias'] . '.' . $join['rel_key']. "='" .$parentbean->id . "'";
3500
+                                $ret_array['secondary_where'] = $params['join_table_link_alias'].'.'.$join['rel_key']."='".$parentbean->id."'";
3501 3501
                             }
3502 3502
                         }
3503 3503
                     }
3504 3504
                     else
3505 3505
                     {
3506
-                        if(isset($data['db_concat_fields']))
3506
+                        if (isset($data['db_concat_fields']))
3507 3507
                         {
3508
-                            $ret_array['select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3508
+                            $ret_array['select'] .= ' , '.$this->db->concat($params['join_table_alias'], $data['db_concat_fields']).' '.$field;
3509 3509
                         }
3510 3510
                         else
3511 3511
                         {
3512
-                            $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3512
+                            $ret_array['select'] .= ' , '.$params['join_table_alias'].'.'.$data['rname'].' '.$field;
3513 3513
                         }
3514
-                        if(isset($data['additionalFields'])){
3515
-                            foreach($data['additionalFields'] as $k=>$v){
3514
+                        if (isset($data['additionalFields'])) {
3515
+                            foreach ($data['additionalFields'] as $k=>$v) {
3516 3516
                                 if (!empty($data['id_name']) && $data['id_name'] == $v && !empty($fields[$data['id_name']])) {
3517 3517
                                     continue;
3518 3518
                                 }
3519
-                                $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $k . ' ' . $v;
3519
+                                $ret_array['select'] .= ' , '.$params['join_table_alias'].'.'.$k.' '.$v;
3520 3520
                             }
3521 3521
                         }
3522
-                        if(!$table_joined)
3522
+                        if (!$table_joined)
3523 3523
                         {
3524
-                            $ret_array['from'] .= ' ' . $join['join']. ' AND ' . $params['join_table_alias'].'.deleted=0';
3525
-                            if(!empty($beanList[$rel_module]) && !empty($beanFiles[$beanList[$rel_module]]))
3524
+                            $ret_array['from'] .= ' '.$join['join'].' AND '.$params['join_table_alias'].'.deleted=0';
3525
+                            if (!empty($beanList[$rel_module]) && !empty($beanFiles[$beanList[$rel_module]]))
3526 3526
                             {
3527 3527
                                 require_once($beanFiles[$beanList[$rel_module]]);
3528 3528
                                 $rel_mod = new $beanList[$rel_module]();
3529
-                                if(isset($value['target_record_key']) && !empty($filter))
3529
+                                if (isset($value['target_record_key']) && !empty($filter))
3530 3530
                                 {
3531 3531
                                     $selectedFields[$this->table_name.'.'.$value['target_record_key']] = true;
3532 3532
                                     $ret_array['select'] .= " , $this->table_name.{$value['target_record_key']} ";
3533 3533
                                 }
3534
-                                if(isset($rel_mod->field_defs['assigned_user_id']))
3534
+                                if (isset($rel_mod->field_defs['assigned_user_id']))
3535 3535
                                 {
3536
-                                    $ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.assigned_user_id ' .  $field . '_owner';
3536
+                                    $ret_array['select'] .= ' , '.$params['join_table_alias'].'.assigned_user_id '.$field.'_owner';
3537 3537
                                 }
3538 3538
                                 else
3539 3539
                                 {
3540
-                                    $ret_array['select'] .= ' , ' .$params['join_table_alias'] . '.created_by ' .  $field . '_owner';
3540
+                                    $ret_array['select'] .= ' , '.$params['join_table_alias'].'.created_by '.$field.'_owner';
3541 3541
                                 }
3542
-                                $ret_array['select'] .= "  , '".$rel_module  ."' " .  $field . '_mod';
3542
+                                $ret_array['select'] .= "  , '".$rel_module."' ".$field.'_mod';
3543 3543
 
3544 3544
                             }
3545 3545
                         }
@@ -3547,65 +3547,65 @@  discard block
 block discarded – undo
3547 3547
                     // To fix SOAP stuff where we are trying to retrieve all the accounts data where accounts.id = ..
3548 3548
                     // and this code changes accounts to jt4 as there is a self join with the accounts table.
3549 3549
                     //Martin fix #27494
3550
-                    if(isset($data['db_concat_fields'])){
3550
+                    if (isset($data['db_concat_fields'])) {
3551 3551
                     	$buildWhere = false;
3552
-                        if(in_array('first_name', $data['db_concat_fields']) && in_array('last_name', $data['db_concat_fields']))
3552
+                        if (in_array('first_name', $data['db_concat_fields']) && in_array('last_name', $data['db_concat_fields']))
3553 3553
                     	{
3554 3554
                      	   $exp = '/\(\s*?'.$data['name'].'.*?\%\'\s*?\)/';
3555
-                    	   if(preg_match($exp, $where, $matches))
3555
+                    	   if (preg_match($exp, $where, $matches))
3556 3556
                     	   {
3557 3557
                     	   	  $search_expression = $matches[0];
3558 3558
                     	   	  //Create three search conditions - first + last, first, last
3559
-                    	   	  $first_name_search = str_replace($data['name'], $params['join_table_alias'] . '.first_name', $search_expression);
3560
-                    	   	  $last_name_search = str_replace($data['name'], $params['join_table_alias'] . '.last_name', $search_expression);
3559
+                    	   	  $first_name_search = str_replace($data['name'], $params['join_table_alias'].'.first_name', $search_expression);
3560
+                    	   	  $last_name_search = str_replace($data['name'], $params['join_table_alias'].'.last_name', $search_expression);
3561 3561
 							  $full_name_search = str_replace($data['name'], $this->db->concat($params['join_table_alias'], $data['db_concat_fields']), $search_expression);
3562 3562
 							  $buildWhere = true;
3563
-							  $where = str_replace($search_expression, '(' . $full_name_search . ' OR ' . $first_name_search . ' OR ' . $last_name_search . ')', $where);
3563
+							  $where = str_replace($search_expression, '('.$full_name_search.' OR '.$first_name_search.' OR '.$last_name_search.')', $where);
3564 3564
                     	   }
3565 3565
                     	}
3566 3566
 
3567
-                    	if(!$buildWhere)
3567
+                    	if (!$buildWhere)
3568 3568
                     	{
3569 3569
 	                       $db_field = $this->db->concat($params['join_table_alias'], $data['db_concat_fields']);
3570 3570
 	                       $where = preg_replace('/'.$data['name'].'/', $db_field, $where);
3571 3571
 
3572 3572
 				// For relationship fields replace their alias by the corresponsding link table and r_name
3573
-				if(isset($data['relationship_fields']))
3574
-					foreach($data['relationship_fields'] as $r_name=>$alias_name)
3573
+				if (isset($data['relationship_fields']))
3574
+					foreach ($data['relationship_fields'] as $r_name=>$alias_name)
3575 3575
 					{
3576 3576
 						$db_field = $this->db->concat($params['join_table_link_alias'], $r_name);
3577
-						$where = preg_replace('/' . $alias_name . '/', $db_field, $where);
3577
+						$where = preg_replace('/'.$alias_name.'/', $db_field, $where);
3578 3578
 					}
3579 3579
                     	}
3580
-                    }else{
3581
-                        $where = preg_replace('/(^|[\s(])' . $data['name'] . '/', '${1}' . $params['join_table_alias'] . '.'.$data['rname'], $where);
3580
+                    } else {
3581
+                        $where = preg_replace('/(^|[\s(])'.$data['name'].'/', '${1}'.$params['join_table_alias'].'.'.$data['rname'], $where);
3582 3582
 
3583 3583
 			// For relationship fields replace their alias by the corresponsding link table and r_name
3584
-			if(isset($data['relationship_fields']))
3585
-				foreach($data['relationship_fields'] as $r_name=>$alias_name)
3586
-					$where = preg_replace('/(^|[\s(])' . $alias_name . '/', '${1}' . $params['join_table_link_alias'] . '.'.$r_name, $where);
3584
+			if (isset($data['relationship_fields']))
3585
+				foreach ($data['relationship_fields'] as $r_name=>$alias_name)
3586
+					$where = preg_replace('/(^|[\s(])'.$alias_name.'/', '${1}'.$params['join_table_link_alias'].'.'.$r_name, $where);
3587 3587
                     }
3588
-                    if(!$table_joined)
3588
+                    if (!$table_joined)
3589 3589
                     {
3590
-                        $joined_tables[$params['join_table_alias']]=1;
3591
-                        $joined_tables[$params['join_table_link_alias']]=1;
3590
+                        $joined_tables[$params['join_table_alias']] = 1;
3591
+                        $joined_tables[$params['join_table_link_alias']] = 1;
3592 3592
                     }
3593 3593
 
3594 3594
                     $jtcount++;
3595 3595
                 }
3596 3596
             }
3597 3597
         }
3598
-        if(!empty($filter))
3598
+        if (!empty($filter))
3599 3599
         {
3600
-            if(isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id']))
3600
+            if (isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id']))
3601 3601
             {
3602 3602
                 $ret_array['select'] .= ", $this->table_name.assigned_user_id ";
3603 3603
             }
3604
-            else if(isset($this->field_defs['created_by']) &&  empty($selectedFields[$this->table_name.'.created_by']))
3604
+            else if (isset($this->field_defs['created_by']) && empty($selectedFields[$this->table_name.'.created_by']))
3605 3605
             {
3606 3606
                 $ret_array['select'] .= ", $this->table_name.created_by ";
3607 3607
             }
3608
-            if(isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name.'.system_id']))
3608
+            if (isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name.'.system_id']))
3609 3609
             {
3610 3610
                 $ret_array['select'] .= ", $this->table_name.system_id ";
3611 3611
             }
@@ -3613,21 +3613,21 @@  discard block
 block discarded – undo
3613 3613
         }
3614 3614
 
3615 3615
 	if ($ifListForExport) {
3616
-		if(isset($this->field_defs['email1'])) {
3617
-			$ret_array['select'].= " ,email_addresses.email_address email1";
3618
-			$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 ";
3616
+		if (isset($this->field_defs['email1'])) {
3617
+			$ret_array['select'] .= " ,email_addresses.email_address email1";
3618
+			$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 ";
3619 3619
 		}
3620 3620
 	}
3621 3621
 
3622 3622
         $where_auto = '1=1';
3623
-        if($show_deleted == 0)
3623
+        if ($show_deleted == 0)
3624 3624
         {
3625 3625
             $where_auto = "$this->table_name.deleted=0";
3626
-        }else if($show_deleted == 1)
3626
+        } else if ($show_deleted == 1)
3627 3627
         {
3628 3628
             $where_auto = "$this->table_name.deleted=1";
3629 3629
         }
3630
-        if($where != "")
3630
+        if ($where != "")
3631 3631
             $ret_array['where'] = " where ($where) AND $where_auto";
3632 3632
         else
3633 3633
             $ret_array['where'] = " where $where_auto";
@@ -3635,21 +3635,21 @@  discard block
 block discarded – undo
3635 3635
         //make call to process the order by clause
3636 3636
         $order_by = $this->process_order_by($order_by);
3637 3637
         if (!empty($order_by)) {
3638
-            $ret_array['order_by'] = " ORDER BY " . $order_by;
3638
+            $ret_array['order_by'] = " ORDER BY ".$order_by;
3639 3639
         }
3640
-        if($singleSelect)
3640
+        if ($singleSelect)
3641 3641
         {
3642 3642
             unset($ret_array['secondary_where']);
3643 3643
             unset($ret_array['secondary_from']);
3644 3644
             unset($ret_array['secondary_select']);
3645 3645
         }
3646 3646
 
3647
-        if($return_array)
3647
+        if ($return_array)
3648 3648
         {
3649 3649
             return $ret_array;
3650 3650
         }
3651 3651
 
3652
-        return  $ret_array['select'] . $ret_array['from'] . $ret_array['where']. $ret_array['order_by'];
3652
+        return  $ret_array['select'].$ret_array['from'].$ret_array['where'].$ret_array['order_by'];
3653 3653
     }
3654 3654
 
3655 3655
 	// Check if field is defined through a relationship_info field, add this field when not present 
@@ -3680,13 +3680,13 @@  discard block
 block discarded – undo
3680 3680
         global $beanList, $beanFiles;
3681 3681
         $templates = array();
3682 3682
         $parent_child_map = array();
3683
-        foreach($type_info as $children_info)
3683
+        foreach ($type_info as $children_info)
3684 3684
         {
3685
-            foreach($children_info as $child_info)
3685
+            foreach ($children_info as $child_info)
3686 3686
             {
3687
-                if($child_info['type'] == 'parent')
3687
+                if ($child_info['type'] == 'parent')
3688 3688
                 {
3689
-                    if(empty($templates[$child_info['parent_type']]))
3689
+                    if (empty($templates[$child_info['parent_type']]))
3690 3690
                     {
3691 3691
                         //Test emails will have an invalid parent_type, don't try to load the non-existent parent bean
3692 3692
                         if ($child_info['parent_type'] == 'test') {
@@ -3694,7 +3694,7 @@  discard block
 block discarded – undo
3694 3694
                         }
3695 3695
                         $class = $beanList[$child_info['parent_type']];
3696 3696
                         // Added to avoid error below; just silently fail and write message to log
3697
-                        if ( empty($beanFiles[$class]) ) {
3697
+                        if (empty($beanFiles[$class])) {
3698 3698
                             $GLOBALS['log']->error($this->object_name.'::retrieve_parent_fields() - cannot load class "'.$class.'", skip loading.');
3699 3699
                             continue;
3700 3700
                         }
@@ -3702,30 +3702,30 @@  discard block
 block discarded – undo
3702 3702
                         $templates[$child_info['parent_type']] = new $class();
3703 3703
                     }
3704 3704
 
3705
-                    if(empty($queries[$child_info['parent_type']]))
3705
+                    if (empty($queries[$child_info['parent_type']]))
3706 3706
                     {
3707 3707
                         $queries[$child_info['parent_type']] = "SELECT id ";
3708 3708
                         $field_def = $templates[$child_info['parent_type']]->field_defs['name'];
3709
-                        if(isset($field_def['db_concat_fields']))
3709
+                        if (isset($field_def['db_concat_fields']))
3710 3710
                         {
3711
-                            $queries[$child_info['parent_type']] .= ' , ' . $this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']) . ' parent_name';
3711
+                            $queries[$child_info['parent_type']] .= ' , '.$this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']).' parent_name';
3712 3712
                         }
3713 3713
                         else
3714 3714
                         {
3715 3715
                             $queries[$child_info['parent_type']] .= ' , name parent_name';
3716 3716
                         }
3717
-                        if(isset($templates[$child_info['parent_type']]->field_defs['assigned_user_id']))
3717
+                        if (isset($templates[$child_info['parent_type']]->field_defs['assigned_user_id']))
3718 3718
                         {
3719
-                            $queries[$child_info['parent_type']] .= ", assigned_user_id parent_name_owner , '{$child_info['parent_type']}' parent_name_mod";;
3720
-                        }else if(isset($templates[$child_info['parent_type']]->field_defs['created_by']))
3719
+                            $queries[$child_info['parent_type']] .= ", assigned_user_id parent_name_owner , '{$child_info['parent_type']}' parent_name_mod"; ;
3720
+                        } else if (isset($templates[$child_info['parent_type']]->field_defs['created_by']))
3721 3721
                         {
3722 3722
                             $queries[$child_info['parent_type']] .= ", created_by parent_name_owner, '{$child_info['parent_type']}' parent_name_mod";
3723 3723
                         }
3724
-                        $queries[$child_info['parent_type']] .= " FROM " . $templates[$child_info['parent_type']]->table_name ." WHERE id IN ('{$child_info['parent_id']}'";
3724
+                        $queries[$child_info['parent_type']] .= " FROM ".$templates[$child_info['parent_type']]->table_name." WHERE id IN ('{$child_info['parent_id']}'";
3725 3725
                     }
3726 3726
                     else
3727 3727
                     {
3728
-                        if(empty($parent_child_map[$child_info['parent_id']]))
3728
+                        if (empty($parent_child_map[$child_info['parent_id']]))
3729 3729
                         $queries[$child_info['parent_type']] .= " ,'{$child_info['parent_id']}'";
3730 3730
                     }
3731 3731
                     $parent_child_map[$child_info['parent_id']][] = $child_info['child_id'];
@@ -3733,21 +3733,21 @@  discard block
 block discarded – undo
3733 3733
             }
3734 3734
         }
3735 3735
         $results = array();
3736
-        foreach($queries as $query)
3736
+        foreach ($queries as $query)
3737 3737
         {
3738
-            $result = $this->db->query($query . ')');
3739
-            while($row = $this->db->fetchByAssoc($result))
3738
+            $result = $this->db->query($query.')');
3739
+            while ($row = $this->db->fetchByAssoc($result))
3740 3740
             {
3741 3741
                 $results[$row['id']] = $row;
3742 3742
             }
3743 3743
         }
3744 3744
 
3745 3745
         $child_results = array();
3746
-        foreach($parent_child_map as $parent_key=>$parent_child)
3746
+        foreach ($parent_child_map as $parent_key=>$parent_child)
3747 3747
         {
3748
-            foreach($parent_child as $child)
3748
+            foreach ($parent_child as $child)
3749 3749
             {
3750
-                if(isset( $results[$parent_key]))
3750
+                if (isset($results[$parent_key]))
3751 3751
                 {
3752 3752
                     $child_results[$child] = $results[$parent_key];
3753 3753
                 }
@@ -3767,7 +3767,7 @@  discard block
 block discarded – undo
3767 3767
      * @param string $where Optional, additional filter criteria.
3768 3768
      * @return array Fetched data
3769 3769
      */
3770
-    function process_list_query($query, $row_offset, $limit= -1, $max_per_page = -1, $where = '')
3770
+    function process_list_query($query, $row_offset, $limit = -1, $max_per_page = -1, $where = '')
3771 3771
     {
3772 3772
         global $sugar_config;
3773 3773
         $db = DBManagerFactory::getInstance('listviews');
@@ -3776,33 +3776,33 @@  discard block
 block discarded – undo
3776 3776
         */
3777 3777
         $toEnd = strval($row_offset) == 'end';
3778 3778
         $GLOBALS['log']->debug("process_list_query: ".$query);
3779
-        if($max_per_page == -1)
3779
+        if ($max_per_page == -1)
3780 3780
         {
3781
-            $max_per_page 	= $sugar_config['list_max_entries_per_page'];
3781
+            $max_per_page = $sugar_config['list_max_entries_per_page'];
3782 3782
         }
3783 3783
         // Check to see if we have a count query available.
3784
-        if(empty($sugar_config['disable_count_query']) || $toEnd)
3784
+        if (empty($sugar_config['disable_count_query']) || $toEnd)
3785 3785
         {
3786 3786
             $count_query = $this->create_list_count_query($query);
3787
-            if(!empty($count_query) && (empty($limit) || $limit == -1))
3787
+            if (!empty($count_query) && (empty($limit) || $limit == -1))
3788 3788
             {
3789 3789
                 // We have a count query.  Run it and get the results.
3790 3790
                 $result = $db->query($count_query, true, "Error running count query for $this->object_name List: ");
3791 3791
                 $assoc = $db->fetchByAssoc($result);
3792
-                if(!empty($assoc['c']))
3792
+                if (!empty($assoc['c']))
3793 3793
                 {
3794 3794
                     $rows_found = $assoc['c'];
3795 3795
                     $limit = $sugar_config['list_max_entries_per_page'];
3796 3796
                 }
3797
-                if( $toEnd)
3797
+                if ($toEnd)
3798 3798
                 {
3799
-                    $row_offset = (floor(($rows_found -1) / $limit)) * $limit;
3799
+                    $row_offset = (floor(($rows_found - 1) / $limit)) * $limit;
3800 3800
                 }
3801 3801
             }
3802 3802
         }
3803 3803
         else
3804 3804
         {
3805
-            if((empty($limit) || $limit == -1))
3805
+            if ((empty($limit) || $limit == -1))
3806 3806
             {
3807 3807
                 $limit = $max_per_page + 1;
3808 3808
                 $max_per_page = $limit;
@@ -3810,17 +3810,17 @@  discard block
 block discarded – undo
3810 3810
 
3811 3811
         }
3812 3812
 
3813
-        if(empty($row_offset))
3813
+        if (empty($row_offset))
3814 3814
         {
3815 3815
             $row_offset = 0;
3816 3816
         }
3817
-        if(!empty($limit) && $limit != -1 && $limit != -99)
3817
+        if (!empty($limit) && $limit != -1 && $limit != -99)
3818 3818
         {
3819
-            $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $this->object_name list: ");
3819
+            $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $this->object_name list: ");
3820 3820
         }
3821 3821
         else
3822 3822
         {
3823
-            $result = $db->query($query,true,"Error retrieving $this->object_name list: ");
3823
+            $result = $db->query($query, true, "Error retrieving $this->object_name list: ");
3824 3824
         }
3825 3825
 
3826 3826
         $list = Array();
@@ -3843,21 +3843,21 @@  discard block
 block discarded – undo
3843 3843
                 /** @var SugarBean $temp */
3844 3844
                 $temp = new $class();
3845 3845
 
3846
-                foreach($this->field_defs as $field=>$value)
3846
+                foreach ($this->field_defs as $field=>$value)
3847 3847
                 {
3848 3848
                     if (isset($row[$field]))
3849 3849
                     {
3850 3850
                         $temp->$field = $row[$field];
3851
-                        $owner_field = $field . '_owner';
3852
-                        if(isset($row[$owner_field]))
3851
+                        $owner_field = $field.'_owner';
3852
+                        if (isset($row[$owner_field]))
3853 3853
                         {
3854 3854
                             $temp->$owner_field = $row[$owner_field];
3855 3855
                         }
3856 3856
 
3857 3857
                         $GLOBALS['log']->debug("$temp->object_name({$row['id']}): ".$field." = ".$temp->$field);
3858
-                    }else if (isset($row[$this->table_name .'.'.$field]))
3858
+                    } else if (isset($row[$this->table_name.'.'.$field]))
3859 3859
                     {
3860
-                        $temp->$field = $row[$this->table_name .'.'.$field];
3860
+                        $temp->$field = $row[$this->table_name.'.'.$field];
3861 3861
                     }
3862 3862
                     else
3863 3863
                     {
@@ -3867,7 +3867,7 @@  discard block
 block discarded – undo
3867 3867
 
3868 3868
                 $temp->check_date_relationships_load();
3869 3869
                 $temp->fill_in_additional_list_fields();
3870
-                if($temp->hasCustomFields()) $temp->custom_fields->fill_relationships();
3870
+                if ($temp->hasCustomFields()) $temp->custom_fields->fill_relationships();
3871 3871
                 $temp->call_custom_logic("process_record");
3872 3872
 
3873 3873
                 // fix defect #44206. implement the same logic as sugar_currency_format
@@ -3877,17 +3877,17 @@  discard block
 block discarded – undo
3877 3877
 
3878 3878
                 $index++;
3879 3879
             }
3880
-        if(!empty($sugar_config['disable_count_query']) && !empty($limit))
3880
+        if (!empty($sugar_config['disable_count_query']) && !empty($limit))
3881 3881
         {
3882 3882
 
3883 3883
             $rows_found = $row_offset + count($list);
3884 3884
 
3885
-            if(!$toEnd)
3885
+            if (!$toEnd)
3886 3886
             {
3887 3887
                 $next_offset--;
3888 3888
                 $previous_offset++;
3889 3889
             }
3890
-        } else if(!isset($rows_found)){
3890
+        } else if (!isset($rows_found)) {
3891 3891
             $rows_found = $row_offset + count($list);
3892 3892
         }
3893 3893
 
@@ -3896,7 +3896,7 @@  discard block
 block discarded – undo
3896 3896
         $response['row_count'] = $rows_found;
3897 3897
         $response['next_offset'] = $next_offset;
3898 3898
         $response['previous_offset'] = $previous_offset;
3899
-        $response['current_offset'] = $row_offset ;
3899
+        $response['current_offset'] = $row_offset;
3900 3900
         return $response;
3901 3901
     }
3902 3902
 
@@ -3908,18 +3908,18 @@  discard block
 block discarded – undo
3908 3908
      * @param boolean $is_count_query Optional, Default false, set to true if passed query is a count query.
3909 3909
      * @return int count of rows found
3910 3910
     */
3911
-    function _get_num_rows_in_query($query, $is_count_query=false)
3911
+    function _get_num_rows_in_query($query, $is_count_query = false)
3912 3912
     {
3913 3913
         $num_rows_in_query = 0;
3914 3914
         if (!$is_count_query)
3915 3915
         {
3916 3916
             $count_query = SugarBean::create_list_count_query($query);
3917 3917
         } else
3918
-            $count_query=$query;
3918
+            $count_query = $query;
3919 3919
 
3920 3920
         $result = $this->db->query($count_query, true, "Error running count query for $this->object_name List: ");
3921 3921
         $row_num = 0;
3922
-        while($row = $this->db->fetchByAssoc($result, true))
3922
+        while ($row = $this->db->fetchByAssoc($result, true))
3923 3923
         {
3924 3924
             $num_rows_in_query += current($row);
3925 3925
         }
@@ -3944,7 +3944,7 @@  discard block
 block discarded – undo
3944 3944
      * @return array Fetched data.
3945 3945
      */
3946 3946
     function process_union_list_query($parent_bean, $query,
3947
-    $row_offset, $limit= -1, $max_per_page = -1, $where = '', $subpanel_def, $query_row_count='', $secondary_queries = array())
3947
+    $row_offset, $limit = -1, $max_per_page = -1, $where = '', $subpanel_def, $query_row_count = '', $secondary_queries = array())
3948 3948
 
3949 3949
     {
3950 3950
         $db = DBManagerFactory::getInstance('listviews');
@@ -3953,52 +3953,52 @@  discard block
 block discarded – undo
3953 3953
         */
3954 3954
         $toEnd = strval($row_offset) == 'end';
3955 3955
         global $sugar_config;
3956
-        $use_count_query=false;
3957
-        $processing_collection=$subpanel_def->isCollection();
3956
+        $use_count_query = false;
3957
+        $processing_collection = $subpanel_def->isCollection();
3958 3958
 
3959 3959
         $GLOBALS['log']->debug("process_union_list_query: ".$query);
3960
-        if($max_per_page == -1)
3960
+        if ($max_per_page == -1)
3961 3961
         {
3962
-            $max_per_page 	= $sugar_config['list_max_entries_per_subpanel'];
3962
+            $max_per_page = $sugar_config['list_max_entries_per_subpanel'];
3963 3963
         }
3964
-        if(empty($query_row_count))
3964
+        if (empty($query_row_count))
3965 3965
         {
3966 3966
             $query_row_count = $query;
3967 3967
         }
3968
-        $distinct_position=strpos($query_row_count,"DISTINCT");
3968
+        $distinct_position = strpos($query_row_count, "DISTINCT");
3969 3969
 
3970
-        if ($distinct_position!= false)
3970
+        if ($distinct_position != false)
3971 3971
         {
3972
-            $use_count_query=true;
3972
+            $use_count_query = true;
3973 3973
         }
3974 3974
         $performSecondQuery = true;
3975
-        if(empty($sugar_config['disable_count_query']) || $toEnd)
3975
+        if (empty($sugar_config['disable_count_query']) || $toEnd)
3976 3976
         {
3977
-            $rows_found = $this->_get_num_rows_in_query($query_row_count,$use_count_query);
3978
-            if($rows_found < 1)
3977
+            $rows_found = $this->_get_num_rows_in_query($query_row_count, $use_count_query);
3978
+            if ($rows_found < 1)
3979 3979
             {
3980 3980
                 $performSecondQuery = false;
3981 3981
             }
3982
-            if(!empty($rows_found) && (empty($limit) || $limit == -1))
3982
+            if (!empty($rows_found) && (empty($limit) || $limit == -1))
3983 3983
             {
3984 3984
                 $limit = $max_per_page;
3985 3985
             }
3986
-            if( $toEnd)
3986
+            if ($toEnd)
3987 3987
             {
3988
-                $row_offset = (floor(($rows_found -1) / $limit)) * $limit;
3988
+                $row_offset = (floor(($rows_found - 1) / $limit)) * $limit;
3989 3989
 
3990 3990
             }
3991 3991
         }
3992 3992
         else
3993 3993
         {
3994
-            if((empty($limit) || $limit == -1))
3994
+            if ((empty($limit) || $limit == -1))
3995 3995
             {
3996 3996
                 $limit = $max_per_page + 1;
3997 3997
                 $max_per_page = $limit;
3998 3998
             }
3999 3999
         }
4000 4000
 
4001
-        if(empty($row_offset))
4001
+        if (empty($row_offset))
4002 4002
         {
4003 4003
             $row_offset = 0;
4004 4004
         }
@@ -4006,15 +4006,15 @@  discard block
 block discarded – undo
4006 4006
         $previous_offset = $row_offset - $max_per_page;
4007 4007
         $next_offset = $row_offset + $max_per_page;
4008 4008
 
4009
-        if($performSecondQuery)
4009
+        if ($performSecondQuery)
4010 4010
         {
4011
-            if(!empty($limit) && $limit != -1 && $limit != -99)
4011
+            if (!empty($limit) && $limit != -1 && $limit != -99)
4012 4012
             {
4013
-                $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $parent_bean->object_name list: ");
4013
+                $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $parent_bean->object_name list: ");
4014 4014
             }
4015 4015
             else
4016 4016
             {
4017
-                $result = $db->query($query,true,"Error retrieving $this->object_name list: ");
4017
+                $result = $db->query($query, true, "Error retrieving $this->object_name list: ");
4018 4018
             }
4019 4019
                 //use -99 to return all
4020 4020
 
@@ -4024,22 +4024,22 @@  discard block
 block discarded – undo
4024 4024
 
4025 4025
                 $post_retrieve = array();
4026 4026
                 $isFirstTime = true;
4027
-                while($row)
4027
+                while ($row)
4028 4028
                 {
4029 4029
                     $function_fields = array();
4030
-                    if(($index < $row_offset + $max_per_page || $max_per_page == -99))
4030
+                    if (($index < $row_offset + $max_per_page || $max_per_page == -99))
4031 4031
                     {
4032 4032
                         if ($processing_collection)
4033 4033
                         {
4034
-                            $current_bean =$subpanel_def->sub_subpanels[$row['panel_name']]->template_instance;
4035
-                            if(!$isFirstTime)
4034
+                            $current_bean = $subpanel_def->sub_subpanels[$row['panel_name']]->template_instance;
4035
+                            if (!$isFirstTime)
4036 4036
                             {
4037 4037
                                 $class = get_class($subpanel_def->sub_subpanels[$row['panel_name']]->template_instance);
4038 4038
                                 $current_bean = new $class();
4039 4039
                             }
4040 4040
                         } else {
4041
-                            $current_bean=$subpanel_def->template_instance;
4042
-                            if(!$isFirstTime)
4041
+                            $current_bean = $subpanel_def->template_instance;
4042
+                            if (!$isFirstTime)
4043 4043
                             {
4044 4044
                                 $class = get_class($subpanel_def->template_instance);
4045 4045
                                 $current_bean = new $class();
@@ -4049,9 +4049,9 @@  discard block
 block discarded – undo
4049 4049
                         //set the panel name in the bean instance.
4050 4050
                         if (isset($row['panel_name']))
4051 4051
                         {
4052
-                            $current_bean->panel_name=$row['panel_name'];
4052
+                            $current_bean->panel_name = $row['panel_name'];
4053 4053
                         }
4054
-                        foreach($current_bean->field_defs as $field=>$value)
4054
+                        foreach ($current_bean->field_defs as $field=>$value)
4055 4055
                         {
4056 4056
 
4057 4057
                             if (isset($row[$field]))
@@ -4059,60 +4059,60 @@  discard block
 block discarded – undo
4059 4059
                                 $current_bean->$field = $this->convertField($row[$field], $value);
4060 4060
                                 unset($row[$field]);
4061 4061
                             }
4062
-                            else if (isset($row[$this->table_name .'.'.$field]))
4062
+                            else if (isset($row[$this->table_name.'.'.$field]))
4063 4063
                             {
4064
-                                $current_bean->$field = $this->convertField($row[$this->table_name .'.'.$field], $value);
4065
-                                unset($row[$this->table_name .'.'.$field]);
4064
+                                $current_bean->$field = $this->convertField($row[$this->table_name.'.'.$field], $value);
4065
+                                unset($row[$this->table_name.'.'.$field]);
4066 4066
                             }
4067 4067
                             else
4068 4068
                             {
4069 4069
                                 $current_bean->$field = "";
4070 4070
                                 unset($row[$field]);
4071 4071
                             }
4072
-                            if(isset($value['source']) && $value['source'] == 'function')
4072
+                            if (isset($value['source']) && $value['source'] == 'function')
4073 4073
                             {
4074
-                                $function_fields[]=$field;
4074
+                                $function_fields[] = $field;
4075 4075
                             }
4076 4076
                         }
4077
-                        foreach($row as $key=>$value)
4077
+                        foreach ($row as $key=>$value)
4078 4078
                         {
4079 4079
                             $current_bean->$key = $value;
4080 4080
                         }
4081
-                        foreach($function_fields as $function_field)
4081
+                        foreach ($function_fields as $function_field)
4082 4082
                         {
4083 4083
                             $value = $current_bean->field_defs[$function_field];
4084 4084
                             $can_execute = true;
4085 4085
                             $execute_params = array();
4086 4086
                             $execute_function = array();
4087
-                            if(!empty($value['function_class']))
4087
+                            if (!empty($value['function_class']))
4088 4088
                             {
4089
-                                $execute_function[] = 	$value['function_class'];
4090
-                                $execute_function[] = 	$value['function_name'];
4089
+                                $execute_function[] = $value['function_class'];
4090
+                                $execute_function[] = $value['function_name'];
4091 4091
                             }
4092 4092
                             else
4093 4093
                             {
4094
-                                $execute_function	= $value['function_name'];
4094
+                                $execute_function = $value['function_name'];
4095 4095
                             }
4096
-                            foreach($value['function_params'] as $param )
4096
+                            foreach ($value['function_params'] as $param)
4097 4097
                             {
4098
-                                if (empty($value['function_params_source']) or $value['function_params_source']=='parent')
4098
+                                if (empty($value['function_params_source']) or $value['function_params_source'] == 'parent')
4099 4099
                                 {
4100
-                                    if(empty($this->$param))
4100
+                                    if (empty($this->$param))
4101 4101
                                     {
4102 4102
                                         $can_execute = false;
4103
-                                    } else if($param == '$this') {
4103
+                                    } else if ($param == '$this') {
4104 4104
                                         $execute_params[] = $this;
4105 4105
                                     }
4106 4106
                                     else
4107 4107
                                     {
4108 4108
                                         $execute_params[] = $this->$param;
4109 4109
                                     }
4110
-                                } else if ($value['function_params_source']=='this')
4110
+                                } else if ($value['function_params_source'] == 'this')
4111 4111
                                 {
4112
-                                    if(empty($current_bean->$param))
4112
+                                    if (empty($current_bean->$param))
4113 4113
                                     {
4114 4114
                                         $can_execute = false;
4115
-                                    } else if($param == '$this') {
4115
+                                    } else if ($param == '$this') {
4116 4116
                                         $execute_params[] = $current_bean;
4117 4117
                                     }
4118 4118
                                     else
@@ -4126,18 +4126,18 @@  discard block
 block discarded – undo
4126 4126
                                 }
4127 4127
 
4128 4128
                             }
4129
-                            if($can_execute)
4129
+                            if ($can_execute)
4130 4130
                             {
4131
-                                if(!empty($value['function_require']))
4131
+                                if (!empty($value['function_require']))
4132 4132
                                 {
4133 4133
                                     require_once($value['function_require']);
4134 4134
                                 }
4135 4135
                                 $current_bean->$function_field = call_user_func_array($execute_function, $execute_params);
4136 4136
                             }
4137 4137
                         }
4138
-                        if(!empty($current_bean->parent_type) && !empty($current_bean->parent_id))
4138
+                        if (!empty($current_bean->parent_type) && !empty($current_bean->parent_id))
4139 4139
                         {
4140
-                            if(!isset($post_retrieve[$current_bean->parent_type]))
4140
+                            if (!isset($post_retrieve[$current_bean->parent_type]))
4141 4141
                             {
4142 4142
                                 $post_retrieve[$current_bean->parent_type] = array();
4143 4143
                             }
@@ -4151,22 +4151,22 @@  discard block
 block discarded – undo
4151 4151
                     $row = $db->fetchByAssoc($result);
4152 4152
                 }
4153 4153
             //now handle retrieving many-to-many relationships
4154
-            if(!empty($list))
4154
+            if (!empty($list))
4155 4155
             {
4156
-                foreach($secondary_queries as $query2)
4156
+                foreach ($secondary_queries as $query2)
4157 4157
                 {
4158 4158
                     $result2 = $db->query($query2);
4159 4159
 
4160 4160
                     $row2 = $db->fetchByAssoc($result2);
4161
-                    while($row2)
4161
+                    while ($row2)
4162 4162
                     {
4163 4163
                         $id_ref = $row2['ref_id'];
4164 4164
 
4165
-                        if(isset($list[$id_ref]))
4165
+                        if (isset($list[$id_ref]))
4166 4166
                         {
4167
-                            foreach($row2 as $r2key=>$r2value)
4167
+                            foreach ($row2 as $r2key=>$r2value)
4168 4168
                             {
4169
-                                if($r2key != 'ref_id')
4169
+                                if ($r2key != 'ref_id')
4170 4170
                                 {
4171 4171
                                     $list[$id_ref]->$r2key = $r2value;
4172 4172
                                 }
@@ -4178,7 +4178,7 @@  discard block
 block discarded – undo
4178 4178
 
4179 4179
             }
4180 4180
 
4181
-            if(isset($post_retrieve))
4181
+            if (isset($post_retrieve))
4182 4182
             {
4183 4183
                 $parent_fields = $this->retrieve_parent_fields($post_retrieve);
4184 4184
             }
@@ -4186,16 +4186,16 @@  discard block
 block discarded – undo
4186 4186
             {
4187 4187
                 $parent_fields = array();
4188 4188
             }
4189
-            if(!empty($sugar_config['disable_count_query']) && !empty($limit))
4189
+            if (!empty($sugar_config['disable_count_query']) && !empty($limit))
4190 4190
             {
4191 4191
             	//C.L. Bug 43535 - Use the $index value to set the $rows_found value here
4192 4192
                 $rows_found = isset($index) ? $index : $row_offset + count($list);
4193 4193
 
4194
-                if(count($list) >= $limit)
4194
+                if (count($list) >= $limit)
4195 4195
                 {
4196 4196
                     array_pop($list);
4197 4197
                 }
4198
-                if(!$toEnd)
4198
+                if (!$toEnd)
4199 4199
                 {
4200 4200
                     $next_offset--;
4201 4201
                     $previous_offset++;
@@ -4204,7 +4204,7 @@  discard block
 block discarded – undo
4204 4204
         }
4205 4205
         else
4206 4206
         {
4207
-            $row_found 	= 0;
4207
+            $row_found = 0;
4208 4208
             $parent_fields = array();
4209 4209
         }
4210 4210
         $response = array();
@@ -4213,7 +4213,7 @@  discard block
 block discarded – undo
4213 4213
         $response['row_count'] = $rows_found;
4214 4214
         $response['next_offset'] = $next_offset;
4215 4215
         $response['previous_offset'] = $previous_offset;
4216
-        $response['current_offset'] = $row_offset ;
4216
+        $response['current_offset'] = $row_offset;
4217 4217
         $response['query'] = $query;
4218 4218
 
4219 4219
         return $response;
@@ -4233,35 +4233,35 @@  discard block
 block discarded – undo
4233 4233
      * @return array Fetched data.
4234 4234
      *
4235 4235
      */
4236
-    function process_detail_query($query, $row_offset, $limit= -1, $max_per_page = -1, $where = '', $offset = 0)
4236
+    function process_detail_query($query, $row_offset, $limit = -1, $max_per_page = -1, $where = '', $offset = 0)
4237 4237
     {
4238 4238
         global $sugar_config;
4239 4239
         $GLOBALS['log']->debug("process_detail_query: ".$query);
4240
-        if($max_per_page == -1)
4240
+        if ($max_per_page == -1)
4241 4241
         {
4242
-            $max_per_page 	= $sugar_config['list_max_entries_per_page'];
4242
+            $max_per_page = $sugar_config['list_max_entries_per_page'];
4243 4243
         }
4244 4244
 
4245 4245
         // Check to see if we have a count query available.
4246 4246
         $count_query = $this->create_list_count_query($query);
4247 4247
 
4248
-        if(!empty($count_query) && (empty($limit) || $limit == -1))
4248
+        if (!empty($count_query) && (empty($limit) || $limit == -1))
4249 4249
         {
4250 4250
             // We have a count query.  Run it and get the results.
4251 4251
             $result = $this->db->query($count_query, true, "Error running count query for $this->object_name List: ");
4252 4252
             $assoc = $this->db->fetchByAssoc($result);
4253
-            if(!empty($assoc['c']))
4253
+            if (!empty($assoc['c']))
4254 4254
             {
4255 4255
                 $total_rows = $assoc['c'];
4256 4256
             }
4257 4257
         }
4258 4258
 
4259
-        if(empty($row_offset))
4259
+        if (empty($row_offset))
4260 4260
         {
4261 4261
             $row_offset = 0;
4262 4262
         }
4263 4263
 
4264
-        $result = $this->db->limitQuery($query, $offset, 1, true,"Error retrieving $this->object_name list: ");
4264
+        $result = $this->db->limitQuery($query, $offset, 1, true, "Error retrieving $this->object_name list: ");
4265 4265
 
4266 4266
         $previous_offset = $row_offset - $max_per_page;
4267 4267
         $next_offset = $row_offset + $max_per_page;
@@ -4272,7 +4272,7 @@  discard block
 block discarded – undo
4272 4272
         $response = Array();
4273 4273
         $response['bean'] = $this;
4274 4274
         if (empty($total_rows))
4275
-            $total_rows=0;
4275
+            $total_rows = 0;
4276 4276
         $response['row_count'] = $total_rows;
4277 4277
         $response['next_offset'] = $next_offset;
4278 4278
         $response['previous_offset'] = $previous_offset;
@@ -4289,12 +4289,12 @@  discard block
 block discarded – undo
4289 4289
      * @return array Fetched data.
4290 4290
      *
4291 4291
      */
4292
-    function process_full_list_query($query, $check_date=false)
4292
+    function process_full_list_query($query, $check_date = false)
4293 4293
     {
4294 4294
 
4295 4295
         $GLOBALS['log']->debug("process_full_list_query: query is ".$query);
4296 4296
         $result = $this->db->query($query, false);
4297
-        $GLOBALS['log']->debug("process_full_list_query: result is ".print_r($result,true));
4297
+        $GLOBALS['log']->debug("process_full_list_query: result is ".print_r($result, true));
4298 4298
         $class = get_class($this);
4299 4299
         $isFirstTime = true;
4300 4300
         $bean = new $class();
@@ -4303,13 +4303,13 @@  discard block
 block discarded – undo
4303 4303
         while (($row = $bean->db->fetchByAssoc($result)) != null)
4304 4304
         {
4305 4305
             $row = $this->convertRow($row);
4306
-            if(!$isFirstTime)
4306
+            if (!$isFirstTime)
4307 4307
             {
4308 4308
                 $bean = new $class();
4309 4309
             }
4310 4310
             $isFirstTime = false;
4311 4311
 
4312
-            foreach($bean->field_defs as $field=>$value)
4312
+            foreach ($bean->field_defs as $field=>$value)
4313 4313
             {
4314 4314
                 if (isset($row[$field]))
4315 4315
                 {
@@ -4321,7 +4321,7 @@  discard block
 block discarded – undo
4321 4321
                     $bean->$field = '';
4322 4322
                 }
4323 4323
             }
4324
-            if($check_date)
4324
+            if ($check_date)
4325 4325
             {
4326 4326
                 $bean->processed_dates_times = array();
4327 4327
                 $bean->check_date_relationships_load();
@@ -4346,10 +4346,10 @@  discard block
 block discarded – undo
4346 4346
     * @param string $current_module - String value of the module being processed.
4347 4347
     * @param string $current_view - String value of the current view
4348 4348
 	*/
4349
-	function track_view($user_id, $current_module, $current_view='')
4349
+	function track_view($user_id, $current_module, $current_view = '')
4350 4350
 	{
4351 4351
 	    $trackerManager = TrackerManager::getInstance();
4352
-		if($monitor = $trackerManager->getMonitor('tracker')){
4352
+		if ($monitor = $trackerManager->getMonitor('tracker')) {
4353 4353
 	        $monitor->setValue('date_modified', $GLOBALS['timedate']->nowDb());
4354 4354
 	        $monitor->setValue('user_id', $user_id);
4355 4355
 	        $monitor->setValue('module_name', $current_module);
@@ -4378,8 +4378,8 @@  discard block
 block discarded – undo
4378 4378
     * account for instance.  This method is only used for populating extra fields
4379 4379
     * in lists.
4380 4380
     */
4381
-    function fill_in_additional_list_fields(){
4382
-        if(!empty($this->field_defs['parent_name']) && empty($this->parent_name)){
4381
+    function fill_in_additional_list_fields() {
4382
+        if (!empty($this->field_defs['parent_name']) && empty($this->parent_name)) {
4383 4383
             $this->fill_in_additional_parent_fields();
4384 4384
         }
4385 4385
     }
@@ -4393,17 +4393,17 @@  discard block
 block discarded – undo
4393 4393
     */
4394 4394
     function fill_in_additional_detail_fields()
4395 4395
     {
4396
-        if(!empty($this->field_defs['assigned_user_name']) && !empty($this->assigned_user_id)){
4396
+        if (!empty($this->field_defs['assigned_user_name']) && !empty($this->assigned_user_id)) {
4397 4397
 
4398 4398
             $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
4399 4399
 
4400 4400
         }
4401
-		if(!empty($this->field_defs['created_by']) && !empty($this->created_by))
4401
+		if (!empty($this->field_defs['created_by']) && !empty($this->created_by))
4402 4402
 		$this->created_by_name = get_assigned_user_name($this->created_by);
4403
-		if(!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4403
+		if (!empty($this->field_defs['modified_user_id']) && !empty($this->modified_user_id))
4404 4404
 		$this->modified_by_name = get_assigned_user_name($this->modified_user_id);
4405 4405
 
4406
-		if(!empty($this->field_defs['parent_name'])){
4406
+		if (!empty($this->field_defs['parent_name'])) {
4407 4407
 			$this->fill_in_additional_parent_fields();
4408 4408
 		}
4409 4409
     }
@@ -4414,17 +4414,17 @@  discard block
 block discarded – undo
4414 4414
     */
4415 4415
     function fill_in_additional_parent_fields() {
4416 4416
 
4417
-        if(!empty($this->parent_id) && !empty($this->last_parent_id) && $this->last_parent_id == $this->parent_id){
4417
+        if (!empty($this->parent_id) && !empty($this->last_parent_id) && $this->last_parent_id == $this->parent_id) {
4418 4418
             return false;
4419
-        }else{
4419
+        } else {
4420 4420
             $this->parent_name = '';
4421 4421
         }
4422
-        if(!empty($this->parent_type)) {
4422
+        if (!empty($this->parent_type)) {
4423 4423
             $this->last_parent_id = $this->parent_id;
4424 4424
             $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'));
4425
-            if(!empty($this->parent_first_name) || !empty($this->parent_last_name) ){
4425
+            if (!empty($this->parent_first_name) || !empty($this->parent_last_name)) {
4426 4426
                 $this->parent_name = $GLOBALS['locale']->getLocaleFormattedName($this->parent_first_name, $this->parent_last_name);
4427
-            } else if(!empty($this->parent_document_name)){
4427
+            } else if (!empty($this->parent_document_name)) {
4428 4428
                 $this->parent_name = $this->parent_document_name;
4429 4429
             }
4430 4430
         }
@@ -4434,7 +4434,7 @@  discard block
 block discarded – undo
4434 4434
      * Fill in a link field
4435 4435
      */
4436 4436
 
4437
-    function fill_in_link_field( $linkFieldName , $def)
4437
+    function fill_in_link_field($linkFieldName, $def)
4438 4438
     {
4439 4439
         $idField = $linkFieldName;
4440 4440
         //If the id_name provided really was an ID, don't try to load it as a link. Use the normal link
@@ -4444,8 +4444,8 @@  discard block
 block discarded – undo
4444 4444
         }
4445 4445
         if ($this->load_relationship($linkFieldName))
4446 4446
         {
4447
-            $list=$this->$linkFieldName->get();
4448
-            $this->$idField = '' ; // match up with null value in $this->populateFromRow()
4447
+            $list = $this->$linkFieldName->get();
4448
+            $this->$idField = ''; // match up with null value in $this->populateFromRow()
4449 4449
             if (!empty($list))
4450 4450
                 $this->$idField = $list[0];
4451 4451
         }
@@ -4454,22 +4454,22 @@  discard block
 block discarded – undo
4454 4454
     /**
4455 4455
     * Fill in fields where type = relate
4456 4456
     */
4457
-    function fill_in_relationship_fields(){
4457
+    function fill_in_relationship_fields() {
4458 4458
         global $fill_in_rel_depth;
4459
-        if(empty($fill_in_rel_depth) || $fill_in_rel_depth < 0)
4459
+        if (empty($fill_in_rel_depth) || $fill_in_rel_depth < 0)
4460 4460
             $fill_in_rel_depth = 0;
4461 4461
 
4462
-        if($fill_in_rel_depth > 1)
4462
+        if ($fill_in_rel_depth > 1)
4463 4463
             return;
4464 4464
 
4465 4465
         $fill_in_rel_depth++;
4466 4466
 
4467
-        foreach($this->field_defs as $field)
4467
+        foreach ($this->field_defs as $field)
4468 4468
         {
4469
-            if(0 == strcmp($field['type'],'relate') && !empty($field['module']))
4469
+            if (0 == strcmp($field['type'], 'relate') && !empty($field['module']))
4470 4470
             {
4471 4471
                 $name = $field['name'];
4472
-                if(empty($this->$name))
4472
+                if (empty($this->$name))
4473 4473
                 {
4474 4474
                     // 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']
4475 4475
                     $related_module = $field['module'];
@@ -4479,11 +4479,11 @@  discard block
 block discarded – undo
4479 4479
                     {
4480 4480
                        $this->fill_in_link_field($id_name, $field);
4481 4481
                     }
4482
-                    if(!empty($this->$id_name) && ( $this->object_name != $related_module || ( $this->object_name == $related_module && $this->$id_name != $this->id ))){
4483
-                        if(isset($GLOBALS['beanList'][ $related_module])){
4482
+                    if (!empty($this->$id_name) && ($this->object_name != $related_module || ($this->object_name == $related_module && $this->$id_name != $this->id))) {
4483
+                        if (isset($GLOBALS['beanList'][$related_module])) {
4484 4484
                             $class = $GLOBALS['beanList'][$related_module];
4485 4485
 
4486
-                            if(!empty($this->$id_name) && file_exists($GLOBALS['beanFiles'][$class]) && isset($this->$name)){
4486
+                            if (!empty($this->$id_name) && file_exists($GLOBALS['beanFiles'][$class]) && isset($this->$name)) {
4487 4487
                                 require_once($GLOBALS['beanFiles'][$class]);
4488 4488
                                 $mod = new $class();
4489 4489
 
@@ -4500,17 +4500,17 @@  discard block
 block discarded – undo
4500 4500
                             }
4501 4501
                         }
4502 4502
                     }
4503
-                    if(!empty($this->$id_name) && isset($this->$name))
4503
+                    if (!empty($this->$id_name) && isset($this->$name))
4504 4504
                     {
4505
-                        if(!isset($field['additionalFields']))
4505
+                        if (!isset($field['additionalFields']))
4506 4506
                            $field['additionalFields'] = array();
4507
-                        if(!empty($field['rname']))
4507
+                        if (!empty($field['rname']))
4508 4508
                         {
4509
-                            $field['additionalFields'][$field['rname']]= $name;
4509
+                            $field['additionalFields'][$field['rname']] = $name;
4510 4510
                         }
4511 4511
                         else
4512 4512
                         {
4513
-                            $field['additionalFields']['name']= $name;
4513
+                            $field['additionalFields']['name'] = $name;
4514 4514
                         }
4515 4515
                         $this->getRelatedFields($related_module, $this->$id_name, $field['additionalFields']);
4516 4516
                     }
@@ -4540,7 +4540,7 @@  discard block
 block discarded – undo
4540 4540
 		global $current_user;
4541 4541
 		$date_modified = $GLOBALS['timedate']->nowDb();
4542 4542
         $id = $this->db->quote($id);
4543
-		if(isset($_SESSION['show_deleted']))
4543
+		if (isset($_SESSION['show_deleted']))
4544 4544
 		{
4545 4545
 			$this->mark_undeleted($id);
4546 4546
 		}
@@ -4551,7 +4551,7 @@  discard block
 block discarded – undo
4551 4551
 			$this->call_custom_logic("before_delete", $custom_logic_arguments);
4552 4552
             $this->deleted = 1;
4553 4553
             $this->mark_relationships_deleted($id);
4554
-            if ( isset($this->field_defs['modified_user_id']) ) {
4554
+            if (isset($this->field_defs['modified_user_id'])) {
4555 4555
                 if (!empty($current_user)) {
4556 4556
                     $this->modified_user_id = $current_user->id;
4557 4557
                 } else {
@@ -4561,7 +4561,7 @@  discard block
 block discarded – undo
4561 4561
             } else {
4562 4562
                 $query = "UPDATE $this->table_name set deleted=1 , date_modified = '$date_modified' where id='$id'";
4563 4563
             }
4564
-            $this->db->query($query, true,"Error marking record deleted: ");
4564
+            $this->db->query($query, true, "Error marking record deleted: ");
4565 4565
 
4566 4566
             SugarRelationship::resaveRelatedBeans();
4567 4567
 
@@ -4589,8 +4589,8 @@  discard block
 block discarded – undo
4589 4589
         $this->call_custom_logic("before_restore", $custom_logic_arguments);
4590 4590
 
4591 4591
 		$date_modified = $GLOBALS['timedate']->nowDb();
4592
-		$query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='" . $this->db->quote($id) ."'";
4593
-		$this->db->query($query, true,"Error marking record undeleted: ");
4592
+		$query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='".$this->db->quote($id)."'";
4593
+		$this->db->query($query, true, "Error marking record undeleted: ");
4594 4594
 
4595 4595
         $this->restoreFiles();
4596 4596
 
@@ -4643,19 +4643,19 @@  discard block
 block discarded – undo
4643 4643
 
4644 4644
         $directory = $this->deleteFileDirectory();
4645 4645
 
4646
-        $isCreated = sugar_is_dir('upload://deleted/' . $directory);
4646
+        $isCreated = sugar_is_dir('upload://deleted/'.$directory);
4647 4647
         if (!$isCreated) {
4648
-            sugar_mkdir('upload://deleted/' . $directory, 0777, true);
4649
-            $isCreated = sugar_is_dir('upload://deleted/' . $directory);
4648
+            sugar_mkdir('upload://deleted/'.$directory, 0777, true);
4649
+            $isCreated = sugar_is_dir('upload://deleted/'.$directory);
4650 4650
         }
4651 4651
         if (!$isCreated) {
4652 4652
             return false;
4653 4653
         }
4654 4654
 
4655 4655
         foreach ($files as $file) {
4656
-            if (file_exists('upload://' . $file)) {
4657
-                if (!sugar_rename('upload://' . $file, 'upload://deleted/' . $directory . '/' . $file)) {
4658
-                    $GLOBALS['log']->error('Could not move file ' . $file . ' to deleted directory');
4656
+            if (file_exists('upload://'.$file)) {
4657
+                if (!sugar_rename('upload://'.$file, 'upload://deleted/'.$directory.'/'.$file)) {
4658
+                    $GLOBALS['log']->error('Could not move file '.$file.' to deleted directory');
4659 4659
                 }
4660 4660
             }
4661 4661
         }
@@ -4675,7 +4675,7 @@  discard block
 block discarded – undo
4675 4675
         }
4676 4676
         if (empty($record['id'])) {
4677 4677
             $record['id'] = $db->quoted(create_guid());
4678
-            $db->query('INSERT INTO cron_remove_documents (' . implode(', ', array_keys($record)) . ') VALUES(' . implode(', ', $record) . ')');
4678
+            $db->query('INSERT INTO cron_remove_documents ('.implode(', ', array_keys($record)).') VALUES('.implode(', ', $record).')');
4679 4679
         } else {
4680 4680
             $db->query("UPDATE cron_remove_documents SET date_modified={$record['date_modified']} WHERE id={$record['id']}");
4681 4681
         }
@@ -4704,9 +4704,9 @@  discard block
 block discarded – undo
4704 4704
         $directory = $this->deleteFileDirectory();
4705 4705
 
4706 4706
         foreach ($files as $file) {
4707
-            if (sugar_is_file('upload://deleted/' . $directory . '/' . $file)) {
4708
-                if (!sugar_rename('upload://deleted/' . $directory . '/' . $file, 'upload://' . $file)) {
4709
-                    $GLOBALS['log']->error('Could not move file ' . $directory . '/' . $file . ' from deleted directory');
4707
+            if (sugar_is_file('upload://deleted/'.$directory.'/'.$file)) {
4708
+                if (!sugar_rename('upload://deleted/'.$directory.'/'.$file, 'upload://'.$file)) {
4709
+                    $GLOBALS['log']->error('Could not move file '.$directory.'/'.$file.' from deleted directory');
4710 4710
                 }
4711 4711
             }
4712 4712
         }
@@ -4715,7 +4715,7 @@  discard block
 block discarded – undo
4715 4715
          * @var DBManager $db
4716 4716
          */
4717 4717
         global $db;
4718
-        $db->query('DELETE FROM cron_remove_documents WHERE bean_id=' . $db->quoted($this->id));
4718
+        $db->query('DELETE FROM cron_remove_documents WHERE bean_id='.$db->quoted($this->id));
4719 4719
 
4720 4720
         return true;
4721 4721
     }
@@ -4803,9 +4803,9 @@  discard block
 block discarded – undo
4803 4803
         $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
4804 4804
         $db = DBManagerFactory::getInstance('listviews');
4805 4805
 
4806
-        if(!empty($row_offset) && $row_offset != 0 && !empty($limit) && $limit != -1)
4806
+        if (!empty($row_offset) && $row_offset != 0 && !empty($limit) && $limit != -1)
4807 4807
         {
4808
-            $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $template->object_name list: ");
4808
+            $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $template->object_name list: ");
4809 4809
         }
4810 4810
         else
4811 4811
         {
@@ -4815,16 +4815,16 @@  discard block
 block discarded – undo
4815 4815
         $list = Array();
4816 4816
         $isFirstTime = true;
4817 4817
         $class = get_class($template);
4818
-        while($row = $this->db->fetchByAssoc($result))
4818
+        while ($row = $this->db->fetchByAssoc($result))
4819 4819
         {
4820
-            if(!$isFirstTime)
4820
+            if (!$isFirstTime)
4821 4821
             {
4822 4822
                 $template = new $class();
4823 4823
             }
4824 4824
             $isFirstTime = false;
4825 4825
             $record = $template->retrieve($row['id']);
4826 4826
 
4827
-            if($record != null)
4827
+            if ($record != null)
4828 4828
             {
4829 4829
                 // this copies the object into the array
4830 4830
                 $list[] = $template;
@@ -4842,12 +4842,12 @@  discard block
 block discarded – undo
4842 4842
     * @param string $query - the query that should be executed to build the list
4843 4843
     * @param object $template - The object that should be used to copy the records.
4844 4844
     */
4845
-  function build_related_list_where($query, &$template, $where='', $in='', $order_by, $limit='', $row_offset = 0)
4845
+  function build_related_list_where($query, &$template, $where = '', $in = '', $order_by, $limit = '', $row_offset = 0)
4846 4846
   {
4847 4847
     $db = DBManagerFactory::getInstance('listviews');
4848 4848
     // No need to do an additional query
4849 4849
     $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
4850
-    if(empty($in) && !empty($query))
4850
+    if (empty($in) && !empty($query))
4851 4851
     {
4852 4852
         $idList = $this->build_related_in($query);
4853 4853
         $in = $idList['in'];
@@ -4863,19 +4863,19 @@  discard block
 block discarded – undo
4863 4863
     $query .= $custom_join['join'];
4864 4864
 
4865 4865
     $query .= " WHERE deleted=0 AND id IN $in";
4866
-    if(!empty($where))
4866
+    if (!empty($where))
4867 4867
     {
4868 4868
         $query .= " AND $where";
4869 4869
     }
4870 4870
 
4871 4871
 
4872
-    if(!empty($order_by))
4872
+    if (!empty($order_by))
4873 4873
     {
4874 4874
         $query .= "ORDER BY $order_by";
4875 4875
     }
4876 4876
     if (!empty($limit))
4877 4877
     {
4878
-        $result = $db->limitQuery($query, $row_offset, $limit,true,"Error retrieving $this->object_name list: ");
4878
+        $result = $db->limitQuery($query, $row_offset, $limit, true, "Error retrieving $this->object_name list: ");
4879 4879
     }
4880 4880
     else
4881 4881
     {
@@ -4887,16 +4887,16 @@  discard block
 block discarded – undo
4887 4887
     $class = get_class($template);
4888 4888
 
4889 4889
     $disable_security_flag = ($template->disable_row_level_security) ? true : false;
4890
-    while($row = $db->fetchByAssoc($result))
4890
+    while ($row = $db->fetchByAssoc($result))
4891 4891
     {
4892
-        if(!$isFirstTime)
4892
+        if (!$isFirstTime)
4893 4893
         {
4894 4894
             $template = new $class();
4895 4895
             $template->disable_row_level_security = $disable_security_flag;
4896 4896
         }
4897 4897
         $isFirstTime = false;
4898 4898
         $record = $template->retrieve($row['id']);
4899
-        if($record != null)
4899
+        if ($record != null)
4900 4900
         {
4901 4901
             // this copies the object into the array
4902 4902
             $list[] = $template;
@@ -4917,22 +4917,22 @@  discard block
 block discarded – undo
4917 4917
         $idList = array();
4918 4918
         $result = $this->db->query($query, true);
4919 4919
         $ids = '';
4920
-        while($row = $this->db->fetchByAssoc($result))
4920
+        while ($row = $this->db->fetchByAssoc($result))
4921 4921
         {
4922 4922
             $idList[] = $row['id'];
4923
-            if(empty($ids))
4923
+            if (empty($ids))
4924 4924
             {
4925
-                $ids = "('" . $row['id'] . "'";
4925
+                $ids = "('".$row['id']."'";
4926 4926
             }
4927 4927
             else
4928 4928
             {
4929
-                $ids .= ",'" . $row['id'] . "'";
4929
+                $ids .= ",'".$row['id']."'";
4930 4930
             }
4931 4931
         }
4932
-        if(empty($ids))
4932
+        if (empty($ids))
4933 4933
         {
4934 4934
             $ids = "('')";
4935
-        }else{
4935
+        } else {
4936 4936
             $ids .= ')';
4937 4937
         }
4938 4938
 
@@ -4958,16 +4958,16 @@  discard block
 block discarded – undo
4958 4958
         $list = Array();
4959 4959
         $isFirstTime = true;
4960 4960
         $class = get_class($template);
4961
-        while($row = $this->db->fetchByAssoc($result))
4961
+        while ($row = $this->db->fetchByAssoc($result))
4962 4962
         {
4963 4963
             // Create a blank copy
4964 4964
             $copy = $template;
4965
-            if(!$isFirstTime)
4965
+            if (!$isFirstTime)
4966 4966
             {
4967 4967
                 $copy = new $class();
4968 4968
             }
4969 4969
             $isFirstTime = false;
4970
-            foreach($field_list as $field)
4970
+            foreach ($field_list as $field)
4971 4971
             {
4972 4972
                 // Copy the relevant fields
4973 4973
                 $copy->$field = $row[$field];
@@ -4999,14 +4999,14 @@  discard block
 block discarded – undo
4999 4999
 
5000 5000
         $return_array = Array();
5001 5001
         global $app_list_strings, $mod_strings;
5002
-        foreach($this->field_defs as $field=>$value){
5002
+        foreach ($this->field_defs as $field=>$value) {
5003 5003
 
5004
-            if(isset($this->$field)){
5004
+            if (isset($this->$field)) {
5005 5005
 
5006 5006
                 // cn: bug 12270 - sensitive fields being passed arbitrarily in listViews
5007
-                if(isset($sensitiveFields[$field]))
5007
+                if (isset($sensitiveFields[$field]))
5008 5008
                     continue;
5009
-                if(!isset($cache[$field]))
5009
+                if (!isset($cache[$field]))
5010 5010
                     $cache[$field] = strtoupper($field);
5011 5011
 
5012 5012
                 //Fields hidden by Dependent Fields
@@ -5016,30 +5016,30 @@  discard block
 block discarded – undo
5016 5016
                 }
5017 5017
                 //cn: if $field is a _dom, detect and return VALUE not KEY
5018 5018
                 //cl: empty function check for meta-data enum types that have values loaded from a function
5019
-                else if (((!empty($value['type']) && ($value['type'] == 'enum' || $value['type'] == 'radioenum') ))  && empty($value['function'])){
5020
-                    if(!empty($value['options']) && !empty($app_list_strings[$value['options']][$this->$field])){
5019
+                else if (((!empty($value['type']) && ($value['type'] == 'enum' || $value['type'] == 'radioenum'))) && empty($value['function'])) {
5020
+                    if (!empty($value['options']) && !empty($app_list_strings[$value['options']][$this->$field])) {
5021 5021
                         $return_array[$cache[$field]] = $app_list_strings[$value['options']][$this->$field];
5022 5022
                     }
5023 5023
                     //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.
5024
-                    elseif(!empty($value['options']) && !empty($mod_strings[$value['options']][$this->$field]))
5024
+                    elseif (!empty($value['options']) && !empty($mod_strings[$value['options']][$this->$field]))
5025 5025
                     {
5026 5026
                         $return_array[$cache[$field]] = $mod_strings[$value['options']][$this->$field];
5027 5027
                     }
5028
-                    else{
5028
+                    else {
5029 5029
                         $return_array[$cache[$field]] = $this->$field;
5030 5030
                     }
5031 5031
                     //end bug 21672
5032 5032
 // tjy: no need to do this str_replace as the changes in 29994 for ListViewGeneric.tpl for translation handle this now
5033 5033
 //				}elseif(!empty($value['type']) && $value['type'] == 'multienum'&& empty($value['function'])){
5034 5034
 //					$return_array[strtoupper($field)] = str_replace('^,^', ', ', $this->$field );
5035
-                }elseif(!empty($value['custom_module']) && $value['type'] != 'currency'){
5035
+                }elseif (!empty($value['custom_module']) && $value['type'] != 'currency') {
5036 5036
 //					$this->format_field($value);
5037 5037
                     $return_array[$cache[$field]] = $this->$field;
5038
-                }else{
5038
+                } else {
5039 5039
                     $return_array[$cache[$field]] = $this->$field;
5040 5040
                 }
5041 5041
                 // handle "Assigned User Name"
5042
-                if($field == 'assigned_user_name'){
5042
+                if ($field == 'assigned_user_name') {
5043 5043
                     $return_array['ASSIGNED_USER_NAME'] = get_assigned_user_name($this->assigned_user_id);
5044 5044
                 }
5045 5045
             }
@@ -5061,7 +5061,7 @@  discard block
 block discarded – undo
5061 5061
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
5062 5062
      * @return string The WHERE clause
5063 5063
      */
5064
-    function get_where($fields_array, $deleted=true)
5064
+    function get_where($fields_array, $deleted = true)
5065 5065
     {
5066 5066
         $where_clause = "";
5067 5067
         foreach ($fields_array as $name=>$value)
@@ -5071,10 +5071,10 @@  discard block
 block discarded – undo
5071 5071
             }
5072 5072
             $name = $this->db->getValidDBName($name);
5073 5073
 
5074
-            $where_clause .= "$name = ".$this->db->quoted($value,false);
5074
+            $where_clause .= "$name = ".$this->db->quoted($value, false);
5075 5075
         }
5076
-        if(!empty($where_clause)) {
5077
-            if($deleted) {
5076
+        if (!empty($where_clause)) {
5077
+            if ($deleted) {
5078 5078
                 return "WHERE $where_clause AND deleted=0";
5079 5079
             } else {
5080 5080
                 return "WHERE $where_clause";
@@ -5094,24 +5094,24 @@  discard block
 block discarded – undo
5094 5094
      * @param boolean $deleted Optional, default true, if set to false deleted filter will not be added.
5095 5095
      * @return object Instance of this bean with fetched data.
5096 5096
      */
5097
-    function retrieve_by_string_fields($fields_array, $encode=true, $deleted=true)
5097
+    function retrieve_by_string_fields($fields_array, $encode = true, $deleted = true)
5098 5098
     {
5099 5099
         $where_clause = $this->get_where($fields_array, $deleted);
5100 5100
         $custom_join = $this->getCustomJoin();
5101
-        $query = "SELECT $this->table_name.*". $custom_join['select']. " FROM $this->table_name " . $custom_join['join'];
5101
+        $query = "SELECT $this->table_name.*".$custom_join['select']." FROM $this->table_name ".$custom_join['join'];
5102 5102
         $query .= " $where_clause";
5103 5103
         $GLOBALS['log']->debug("Retrieve $this->object_name: ".$query);
5104 5104
         //requireSingleResult has been deprecated.
5105 5105
         //$result = $this->db->requireSingleResult($query, true, "Retrieving record $where_clause:");
5106
-        $result = $this->db->limitQuery($query,0,1,true, "Retrieving record $where_clause:");
5106
+        $result = $this->db->limitQuery($query, 0, 1, true, "Retrieving record $where_clause:");
5107 5107
 
5108 5108
 
5109
-        if( empty($result))
5109
+        if (empty($result))
5110 5110
         {
5111 5111
             return null;
5112 5112
         }
5113 5113
         $row = $this->db->fetchByAssoc($result, $encode);
5114
-        if(empty($row))
5114
+        if (empty($row))
5115 5115
         {
5116 5116
             return null;
5117 5117
         }
@@ -5138,7 +5138,7 @@  discard block
 block discarded – undo
5138 5138
     {
5139 5139
         foreach ($this->special_functions as $func_name)
5140 5140
         {
5141
-            if ( method_exists($this,$func_name) )
5141
+            if (method_exists($this, $func_name))
5142 5142
             {
5143 5143
                 $this->$func_name();
5144 5144
             }
@@ -5153,52 +5153,52 @@  discard block
 block discarded – undo
5153 5153
     {
5154 5154
     }
5155 5155
 
5156
-    function getRelatedFields($module, $id, $fields, $return_array = false){
5157
-        if(empty($GLOBALS['beanList'][$module]))return '';
5156
+    function getRelatedFields($module, $id, $fields, $return_array = false) {
5157
+        if (empty($GLOBALS['beanList'][$module]))return '';
5158 5158
         $object = BeanFactory::getObjectName($module);
5159 5159
 
5160 5160
         VardefManager::loadVardef($module, $object);
5161
-        if(empty($GLOBALS['dictionary'][$object]['table']))return '';
5161
+        if (empty($GLOBALS['dictionary'][$object]['table']))return '';
5162 5162
         $table = $GLOBALS['dictionary'][$object]['table'];
5163
-        $query  = 'SELECT id';
5164
-        foreach($fields as $field=>$alias){
5165
-            if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])){
5166
-                $query .= ' ,' .$this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']) .  ' as ' . $alias ;
5167
-            }else if(!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
5163
+        $query = 'SELECT id';
5164
+        foreach ($fields as $field=>$alias) {
5165
+            if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])) {
5166
+                $query .= ' ,'.$this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']).' as '.$alias;
5167
+            } else if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
5168 5168
                 (empty($GLOBALS['dictionary'][$object]['fields'][$field]['source']) ||
5169 5169
                 $GLOBALS['dictionary'][$object]['fields'][$field]['source'] != "non-db"))
5170 5170
             {
5171
-                $query .= ' ,' .$table . '.' . $field . ' as ' . $alias;
5171
+                $query .= ' ,'.$table.'.'.$field.' as '.$alias;
5172 5172
             }
5173
-            if(!$return_array)$this->$alias = '';
5173
+            if (!$return_array)$this->$alias = '';
5174 5174
         }
5175
-        if($query == 'SELECT id' || empty($id)){
5175
+        if ($query == 'SELECT id' || empty($id)) {
5176 5176
             return '';
5177 5177
         }
5178 5178
 
5179 5179
 
5180
-        if(isset($GLOBALS['dictionary'][$object]['fields']['assigned_user_id']))
5180
+        if (isset($GLOBALS['dictionary'][$object]['fields']['assigned_user_id']))
5181 5181
         {
5182
-            $query .= " , ".	$table  . ".assigned_user_id owner";
5182
+            $query .= " , ".$table.".assigned_user_id owner";
5183 5183
 
5184 5184
         }
5185
-        else if(isset($GLOBALS['dictionary'][$object]['fields']['created_by']))
5185
+        else if (isset($GLOBALS['dictionary'][$object]['fields']['created_by']))
5186 5186
         {
5187
-            $query .= " , ".	$table . ".created_by owner";
5187
+            $query .= " , ".$table.".created_by owner";
5188 5188
 
5189 5189
         }
5190
-        $query .=  ' FROM ' . $table . ' WHERE deleted=0 AND id=';
5191
-        $result = $GLOBALS['db']->query($query . "'$id'" );
5190
+        $query .= ' FROM '.$table.' WHERE deleted=0 AND id=';
5191
+        $result = $GLOBALS['db']->query($query."'$id'");
5192 5192
         $row = $GLOBALS['db']->fetchByAssoc($result);
5193
-        if($return_array){
5193
+        if ($return_array) {
5194 5194
             return $row;
5195 5195
         }
5196
-        $owner = (empty($row['owner']))?'':$row['owner'];
5197
-        foreach($fields as $alias){
5198
-            $this->$alias = (!empty($row[$alias]))? $row[$alias]: '';
5199
-            $alias = $alias  .'_owner';
5196
+        $owner = (empty($row['owner'])) ? '' : $row['owner'];
5197
+        foreach ($fields as $alias) {
5198
+            $this->$alias = (!empty($row[$alias])) ? $row[$alias] : '';
5199
+            $alias = $alias.'_owner';
5200 5200
             $this->$alias = $owner;
5201
-            $a_mod = $alias  .'_mod';
5201
+            $a_mod = $alias.'_mod';
5202 5202
             $this->$a_mod = $module;
5203 5203
         }
5204 5204
 
@@ -5214,39 +5214,39 @@  discard block
 block discarded – undo
5214 5214
     function assign_display_fields($currentModule)
5215 5215
     {
5216 5216
         global $timedate;
5217
-        foreach($this->column_fields as $field)
5217
+        foreach ($this->column_fields as $field)
5218 5218
         {
5219
-            if(isset($this->field_name_map[$field]) && empty($this->$field))
5219
+            if (isset($this->field_name_map[$field]) && empty($this->$field))
5220 5220
             {
5221
-                if($this->field_name_map[$field]['type'] != 'date' && $this->field_name_map[$field]['type'] != 'enum')
5221
+                if ($this->field_name_map[$field]['type'] != 'date' && $this->field_name_map[$field]['type'] != 'enum')
5222 5222
                 $this->$field = $field;
5223
-                if($this->field_name_map[$field]['type'] == 'date')
5223
+                if ($this->field_name_map[$field]['type'] == 'date')
5224 5224
                 {
5225 5225
                     $this->$field = $timedate->to_display_date('1980-07-09');
5226 5226
                 }
5227
-                if($this->field_name_map[$field]['type'] == 'enum')
5227
+                if ($this->field_name_map[$field]['type'] == 'enum')
5228 5228
                 {
5229 5229
                     $dom = $this->field_name_map[$field]['options'];
5230 5230
                     global $current_language, $app_list_strings;
5231 5231
                     $mod_strings = return_module_language($current_language, $currentModule);
5232 5232
 
5233
-                    if(isset($mod_strings[$dom]))
5233
+                    if (isset($mod_strings[$dom]))
5234 5234
                     {
5235 5235
                         $options = $mod_strings[$dom];
5236
-                        foreach($options as $key=>$value)
5236
+                        foreach ($options as $key=>$value)
5237 5237
                         {
5238
-                            if(!empty($key) && empty($this->$field ))
5238
+                            if (!empty($key) && empty($this->$field))
5239 5239
                             {
5240 5240
                                 $this->$field = $key;
5241 5241
                             }
5242 5242
                         }
5243 5243
                     }
5244
-                    if(isset($app_list_strings[$dom]))
5244
+                    if (isset($app_list_strings[$dom]))
5245 5245
                     {
5246 5246
                         $options = $app_list_strings[$dom];
5247
-                        foreach($options as $key=>$value)
5247
+                        foreach ($options as $key=>$value)
5248 5248
                         {
5249
-                            if(!empty($key) && empty($this->$field ))
5249
+                            if (!empty($key) && empty($this->$field))
5250 5250
                             {
5251 5251
                                 $this->$field = $key;
5252 5252
                             }
@@ -5263,61 +5263,61 @@  discard block
 block discarded – undo
5263 5263
     * 	RELATIONSHIP HANDLING
5264 5264
     */
5265 5265
 
5266
-    function set_relationship($table, $relate_values, $check_duplicates = true,$do_update=false,$data_values=null)
5266
+    function set_relationship($table, $relate_values, $check_duplicates = true, $do_update = false, $data_values = null)
5267 5267
     {
5268 5268
         $where = '';
5269 5269
 
5270 5270
 		// make sure there is a date modified
5271 5271
 		$date_modified = $this->db->convert("'".$GLOBALS['timedate']->nowDb()."'", 'datetime');
5272 5272
 
5273
-        $row=null;
5274
-        if($check_duplicates)
5273
+        $row = null;
5274
+        if ($check_duplicates)
5275 5275
         {
5276 5276
             $query = "SELECT * FROM $table ";
5277 5277
             $where = "WHERE deleted = '0'  ";
5278
-            foreach($relate_values as $name=>$value)
5278
+            foreach ($relate_values as $name=>$value)
5279 5279
             {
5280 5280
                 $where .= " AND $name = '$value' ";
5281 5281
             }
5282 5282
             $query .= $where;
5283
-            $result = $this->db->query($query, false, "Looking For Duplicate Relationship:" . $query);
5284
-            $row=$this->db->fetchByAssoc($result);
5283
+            $result = $this->db->query($query, false, "Looking For Duplicate Relationship:".$query);
5284
+            $row = $this->db->fetchByAssoc($result);
5285 5285
         }
5286 5286
 
5287
-        if(!$check_duplicates || empty($row) )
5287
+        if (!$check_duplicates || empty($row))
5288 5288
         {
5289 5289
             unset($relate_values['id']);
5290
-            if ( isset($data_values))
5290
+            if (isset($data_values))
5291 5291
             {
5292
-                $relate_values = array_merge($relate_values,$data_values);
5292
+                $relate_values = array_merge($relate_values, $data_values);
5293 5293
             }
5294
-            $query = "INSERT INTO $table (id, ". implode(',', array_keys($relate_values)) . ", date_modified) VALUES ('" . create_guid() . "', " . "'" . implode("', '", $relate_values) . "', ".$date_modified.")" ;
5294
+            $query = "INSERT INTO $table (id, ".implode(',', array_keys($relate_values)).", date_modified) VALUES ('".create_guid()."', "."'".implode("', '", $relate_values)."', ".$date_modified.")";
5295 5295
 
5296
-            $this->db->query($query, false, "Creating Relationship:" . $query);
5296
+            $this->db->query($query, false, "Creating Relationship:".$query);
5297 5297
         }
5298 5298
         else if ($do_update)
5299 5299
         {
5300 5300
             $conds = array();
5301
-            foreach($data_values as $key=>$value)
5301
+            foreach ($data_values as $key=>$value)
5302 5302
             {
5303
-                array_push($conds,$key."='".$this->db->quote($value)."'");
5303
+                array_push($conds, $key."='".$this->db->quote($value)."'");
5304 5304
             }
5305
-            $query = "UPDATE $table SET ". implode(',', $conds).",date_modified=".$date_modified." ".$where;
5306
-            $this->db->query($query, false, "Updating Relationship:" . $query);
5305
+            $query = "UPDATE $table SET ".implode(',', $conds).",date_modified=".$date_modified." ".$where;
5306
+            $this->db->query($query, false, "Updating Relationship:".$query);
5307 5307
         }
5308 5308
     }
5309 5309
 
5310 5310
     function retrieve_relationships($table, $values, $select_id)
5311 5311
     {
5312 5312
         $query = "SELECT $select_id FROM $table WHERE deleted = 0  ";
5313
-        foreach($values as $name=>$value)
5313
+        foreach ($values as $name=>$value)
5314 5314
         {
5315 5315
             $query .= " AND $name = '$value' ";
5316 5316
         }
5317 5317
         $query .= " ORDER BY $select_id ";
5318
-        $result = $this->db->query($query, false, "Retrieving Relationship:" . $query);
5318
+        $result = $this->db->query($query, false, "Retrieving Relationship:".$query);
5319 5319
         $ids = array();
5320
-        while($row = $this->db->fetchByAssoc($result))
5320
+        while ($row = $this->db->fetchByAssoc($result))
5321 5321
         {
5322 5322
             $ids[] = $row;
5323 5323
         }
@@ -5328,16 +5328,16 @@  discard block
 block discarded – undo
5328 5328
     function loadLayoutDefs()
5329 5329
     {
5330 5330
         global $layout_defs;
5331
-        if(empty( $this->layout_def) && file_exists('modules/'. $this->module_dir . '/layout_defs.php'))
5331
+        if (empty($this->layout_def) && file_exists('modules/'.$this->module_dir.'/layout_defs.php'))
5332 5332
         {
5333
-            include_once('modules/'. $this->module_dir . '/layout_defs.php');
5334
-            if(file_exists('custom/modules/'. $this->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php'))
5333
+            include_once('modules/'.$this->module_dir.'/layout_defs.php');
5334
+            if (file_exists('custom/modules/'.$this->module_dir.'/Ext/Layoutdefs/layoutdefs.ext.php'))
5335 5335
             {
5336
-                include_once('custom/modules/'. $this->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php');
5336
+                include_once('custom/modules/'.$this->module_dir.'/Ext/Layoutdefs/layoutdefs.ext.php');
5337 5337
             }
5338
-            if ( empty( $layout_defs[get_class($this)]))
5338
+            if (empty($layout_defs[get_class($this)]))
5339 5339
             {
5340
-                echo "\$layout_defs[" . get_class($this) . "]; does not exist";
5340
+                echo "\$layout_defs[".get_class($this)."]; does not exist";
5341 5341
             }
5342 5342
 
5343 5343
             $this->layout_def = $layout_defs[get_class($this)];
@@ -5371,12 +5371,12 @@  discard block
 block discarded – undo
5371 5371
     */
5372 5372
     function call_custom_logic($event, $arguments = null)
5373 5373
     {
5374
-        if(!isset($this->processed) || $this->processed == false){
5374
+        if (!isset($this->processed) || $this->processed == false) {
5375 5375
             //add some logic to ensure we do not get into an infinite loop
5376
-            if(!empty($this->logicHookDepth[$event])) {
5377
-                if($this->logicHookDepth[$event] > $this->max_logic_depth)
5376
+            if (!empty($this->logicHookDepth[$event])) {
5377
+                if ($this->logicHookDepth[$event] > $this->max_logic_depth)
5378 5378
                     return;
5379
-            }else
5379
+            } else
5380 5380
                 $this->logicHookDepth[$event] = 0;
5381 5381
 
5382 5382
             //we have to put the increment operator here
@@ -5421,7 +5421,7 @@  discard block
 block discarded – undo
5421 5421
             $GLOBALS['log']->fatal("SUGARBEAN: cannot find Real Key for custom field of type dropdown - cannot return Value.");
5422 5422
             return false;
5423 5423
         }
5424
-        if(isset($realKey))
5424
+        if (isset($realKey))
5425 5425
         {
5426 5426
             return $this->custom_fields->avail_fields[$name][$realKey];
5427 5427
         }
@@ -5440,17 +5440,17 @@  discard block
 block discarded – undo
5440 5440
 	/**
5441 5441
     function ACLAccess($view,$is_owner='not_set')
5442 5442
 	*/
5443
-    function ACLAccess($view,$is_owner='not_set',$in_group='not_set')
5443
+    function ACLAccess($view, $is_owner = 'not_set', $in_group = 'not_set')
5444 5444
     {
5445 5445
         global $current_user;
5446
-        if($current_user->isAdmin()) {
5446
+        if ($current_user->isAdmin()) {
5447 5447
             return true;
5448 5448
         }
5449 5449
         $not_set = false;
5450 5450
 		/**
5451 5451
         if($is_owner == 'not_set')
5452 5452
 		*/
5453
-    	if($is_owner === 'not_set') //eggsurplus: should be ===
5453
+    	if ($is_owner === 'not_set') //eggsurplus: should be ===
5454 5454
         {
5455 5455
             $not_set = true;
5456 5456
             $is_owner = $this->isOwner($current_user->id);
@@ -5461,7 +5461,7 @@  discard block
 block discarded – undo
5461 5461
 		$view = strtolower($view);
5462 5462
 		$action = '';
5463 5463
 		// DJM - OBS Customizations - END CHANGE
5464
-    	if($in_group === 'not_set')
5464
+    	if ($in_group === 'not_set')
5465 5465
     	{
5466 5466
 			require_once("modules/SecurityGroups/SecurityGroup.php");
5467 5467
 			// DJM - OBS Customizations - May 2009
@@ -5487,7 +5487,7 @@  discard block
 block discarded – undo
5487 5487
  		   			$action = "view";
5488 5488
 					break;
5489 5489
  		   		case 'delete':
5490
- 		   			$action = "delete" ;
5490
+ 		   			$action = "delete";
5491 5491
 					break;
5492 5492
  		   		case 'export':
5493 5493
  		   			$action = "export";
@@ -5499,11 +5499,11 @@  discard block
 block discarded – undo
5499 5499
 					$action = "";
5500 5500
 					break;
5501 5501
     			}
5502
-			$in_group = SecurityGroup::groupHasAccess($this->module_dir,$this->id, $action); 
5502
+			$in_group = SecurityGroup::groupHasAccess($this->module_dir, $this->id, $action); 
5503 5503
 			// DJM - OBS Customizations - END CHANGE
5504 5504
     	}
5505 5505
         //if we don't implent acls return true
5506
-        if(!$this->bean_implements('ACL'))
5506
+        if (!$this->bean_implements('ACL'))
5507 5507
         return true;
5508 5508
         $view = strtolower($view);
5509 5509
         switch ($view)
@@ -5514,15 +5514,15 @@  discard block
 block discarded – undo
5514 5514
 				/**
5515 5515
                 return ACLController::checkAccess($this->module_dir,'list', true);
5516 5516
 				*/
5517
-    			return ACLController::checkAccess($this->module_dir,'list', true, $this->acltype, $in_group);
5517
+    			return ACLController::checkAccess($this->module_dir, 'list', true, $this->acltype, $in_group);
5518 5518
             case 'edit':
5519 5519
             case 'save':
5520
-                if( !$is_owner && $not_set && !empty($this->id)){
5520
+                if (!$is_owner && $not_set && !empty($this->id)) {
5521 5521
                     $class = get_class($this);
5522 5522
                     $temp = new $class();
5523
-                    if(!empty($this->fetched_row) && !empty($this->fetched_row['id']) && !empty($this->fetched_row['assigned_user_id']) && !empty($this->fetched_row['created_by'])){
5523
+                    if (!empty($this->fetched_row) && !empty($this->fetched_row['id']) && !empty($this->fetched_row['assigned_user_id']) && !empty($this->fetched_row['created_by'])) {
5524 5524
                         $temp->populateFromRow($this->fetched_row);
5525
-                    }else{
5525
+                    } else {
5526 5526
                         $temp->retrieve($this->id);
5527 5527
                     }
5528 5528
                     $is_owner = $temp->isOwner($current_user->id);
@@ -5532,29 +5532,29 @@  discard block
 block discarded – undo
5532 5532
 				/**
5533 5533
                 return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype);
5534 5534
 				*/
5535
-    			return ACLController::checkAccess($this->module_dir,'edit', $is_owner, $this->acltype, $in_group);
5535
+    			return ACLController::checkAccess($this->module_dir, 'edit', $is_owner, $this->acltype, $in_group);
5536 5536
             case 'view':
5537 5537
             case 'detail':
5538 5538
             case 'detailview':
5539 5539
 				/**
5540 5540
                 return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype);
5541 5541
 				*/
5542
-    			return ACLController::checkAccess($this->module_dir,'view', $is_owner, $this->acltype, $in_group);
5542
+    			return ACLController::checkAccess($this->module_dir, 'view', $is_owner, $this->acltype, $in_group);
5543 5543
             case 'delete':
5544 5544
 				/**
5545 5545
                 return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype);
5546 5546
 				*/
5547
-    			return ACLController::checkAccess($this->module_dir,'delete', $is_owner, $this->acltype, $in_group);
5547
+    			return ACLController::checkAccess($this->module_dir, 'delete', $is_owner, $this->acltype, $in_group);
5548 5548
             case 'export':
5549 5549
 				/**
5550 5550
                 return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype);
5551 5551
 				*/
5552
-    			return ACLController::checkAccess($this->module_dir,'export', $is_owner, $this->acltype, $in_group);
5552
+    			return ACLController::checkAccess($this->module_dir, 'export', $is_owner, $this->acltype, $in_group);
5553 5553
             case 'import':
5554 5554
 				/**
5555 5555
                 return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype);
5556 5556
 				*/
5557
-    			return ACLController::checkAccess($this->module_dir,'import', true, $this->acltype, $in_group);
5557
+    			return ACLController::checkAccess($this->module_dir, 'import', true, $this->acltype, $in_group);
5558 5558
         }
5559 5559
         //if it is not one of the above views then it should be implemented on the page level
5560 5560
         return true;
@@ -5570,12 +5570,12 @@  discard block
 block discarded – undo
5570 5570
     {
5571 5571
         if (isset($this->field_defs['assigned_user_id']))
5572 5572
         {
5573
-            return $returnFieldName? 'assigned_user_id': $this->assigned_user_id;
5573
+            return $returnFieldName ? 'assigned_user_id' : $this->assigned_user_id;
5574 5574
         }
5575 5575
 
5576 5576
         if (isset($this->field_defs['created_by']))
5577 5577
         {
5578
-            return $returnFieldName? 'created_by': $this->created_by;
5578
+            return $returnFieldName ? 'created_by' : $this->created_by;
5579 5579
         }
5580 5580
 
5581 5581
         return '';
@@ -5590,7 +5590,7 @@  discard block
 block discarded – undo
5590 5590
     function isOwner($user_id)
5591 5591
     {
5592 5592
         //if we don't have an id we must be the owner as we are creating it
5593
-        if(!isset($this->id))
5593
+        if (!isset($this->id))
5594 5594
         {
5595 5595
             return true;
5596 5596
         }
@@ -5601,13 +5601,13 @@  discard block
 block discarded – undo
5601 5601
             }
5602 5602
             return false;
5603 5603
         } elseif (isset($this->assigned_user_id)) {
5604
-            if($this->assigned_user_id == $user_id) return true;
5604
+            if ($this->assigned_user_id == $user_id) return true;
5605 5605
             return false;
5606 5606
         }
5607 5607
         else
5608 5608
         {
5609 5609
             //other wise if there is a created_by that is the owner
5610
-            if(isset($this->created_by) && $this->created_by == $user_id)
5610
+            if (isset($this->created_by) && $this->created_by == $user_id)
5611 5611
             {
5612 5612
                 return true;
5613 5613
             }
@@ -5622,11 +5622,11 @@  discard block
 block discarded – undo
5622 5622
     */
5623 5623
     function getOwnerWhere($user_id)
5624 5624
     {
5625
-        if(isset($this->field_defs['assigned_user_id']))
5625
+        if (isset($this->field_defs['assigned_user_id']))
5626 5626
         {
5627 5627
             return " $this->table_name.assigned_user_id ='$user_id' ";
5628 5628
         }
5629
-        if(isset($this->field_defs['created_by']))
5629
+        if (isset($this->field_defs['created_by']))
5630 5630
         {
5631 5631
             return " $this->table_name.created_by ='$user_id' ";
5632 5632
         }
@@ -5643,7 +5643,7 @@  discard block
 block discarded – undo
5643 5643
     function listviewACLHelper()
5644 5644
     {
5645 5645
         $array_assign = array();
5646
-        if($this->ACLAccess('DetailView'))
5646
+        if ($this->ACLAccess('DetailView'))
5647 5647
         {
5648 5648
             $array_assign['MAIN'] = 'a';
5649 5649
         }
@@ -5659,27 +5659,27 @@  discard block
 block discarded – undo
5659 5659
     *
5660 5660
     * @return array of fields with id, name, access and category
5661 5661
     */
5662
-    function toArray($dbOnly = false, $stringOnly = false, $upperKeys=false)
5662
+    function toArray($dbOnly = false, $stringOnly = false, $upperKeys = false)
5663 5663
     {
5664 5664
         static $cache = array();
5665 5665
         $arr = array();
5666 5666
 
5667
-        foreach($this->field_defs as $field=>$data)
5667
+        foreach ($this->field_defs as $field=>$data)
5668 5668
         {
5669
-            if( !$dbOnly || !isset($data['source']) || $data['source'] == 'db')
5670
-            if(!$stringOnly || is_string($this->$field))
5671
-            if($upperKeys)
5669
+            if (!$dbOnly || !isset($data['source']) || $data['source'] == 'db')
5670
+            if (!$stringOnly || is_string($this->$field))
5671
+            if ($upperKeys)
5672 5672
             {
5673
-                                if(!isset($cache[$field])){
5673
+                                if (!isset($cache[$field])) {
5674 5674
                                     $cache[$field] = strtoupper($field);
5675 5675
                                 }
5676 5676
                 $arr[$cache[$field]] = $this->$field;
5677 5677
             }
5678 5678
             else
5679 5679
             {
5680
-                if(isset($this->$field)){
5680
+                if (isset($this->$field)) {
5681 5681
                     $arr[$field] = $this->$field;
5682
-                }else{
5682
+                } else {
5683 5683
                     $arr[$field] = '';
5684 5684
                 }
5685 5685
             }
@@ -5694,7 +5694,7 @@  discard block
 block discarded – undo
5694 5694
     */
5695 5695
     function fromArray($arr)
5696 5696
     {
5697
-        foreach($arr as $name=>$value)
5697
+        foreach ($arr as $name=>$value)
5698 5698
         {
5699 5699
             $this->$name = $value;
5700 5700
         }
@@ -5708,7 +5708,7 @@  discard block
 block discarded – undo
5708 5708
      */
5709 5709
     public function convertRow($row)
5710 5710
     {
5711
-        foreach($this->field_defs as $name => $fieldDef)
5711
+        foreach ($this->field_defs as $name => $fieldDef)
5712 5712
 		{
5713 5713
 		    // skip empty fields and non-db fields
5714 5714
             if (isset($name) && !empty($row[$name])) {
@@ -5754,7 +5754,7 @@  discard block
 block discarded – undo
5754 5754
 
5755 5755
         $this->fill_in_additional_list_fields();
5756 5756
 
5757
-        if($this->hasCustomFields())$this->custom_fields->fill_relationships();
5757
+        if ($this->hasCustomFields())$this->custom_fields->fill_relationships();
5758 5758
         $this->call_custom_logic("process_record");
5759 5759
     }
5760 5760
 
@@ -5773,7 +5773,7 @@  discard block
 block discarded – undo
5773 5773
     *
5774 5774
     * Internal function do not override.
5775 5775
     */
5776
-   function create_qualified_order_by( $order_by, $qualify)
5776
+   function create_qualified_order_by($order_by, $qualify)
5777 5777
    {	// 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
5778 5778
     if (empty($order_by))
5779 5779
     {
@@ -5782,10 +5782,10 @@  discard block
 block discarded – undo
5782 5782
     $order_by_clause = " ORDER BY ";
5783 5783
     $tmp = explode(",", $order_by);
5784 5784
     $comma = ' ';
5785
-    foreach ( $tmp as $stmp)
5785
+    foreach ($tmp as $stmp)
5786 5786
     {
5787
-        $stmp = (substr_count($stmp, ".") > 0?trim($stmp):"$qualify." . trim($stmp));
5788
-        $order_by_clause .= $comma . $stmp;
5787
+        $stmp = (substr_count($stmp, ".") > 0 ? trim($stmp) : "$qualify.".trim($stmp));
5788
+        $order_by_clause .= $comma.$stmp;
5789 5789
         $comma = ", ";
5790 5790
     }
5791 5791
     return $order_by_clause;
@@ -5805,16 +5805,16 @@  discard block
 block discarded – undo
5805 5805
             $street_field_2 = $street_field.'_2';
5806 5806
             $street_field_3 = $street_field.'_3';
5807 5807
             $street_field_4 = $street_field.'_4';
5808
-            if ( isset($this->$street_field_2)) {
5809
-                $this->$street_field .= "\n". $this->$street_field_2;
5808
+            if (isset($this->$street_field_2)) {
5809
+                $this->$street_field .= "\n".$this->$street_field_2;
5810 5810
                 unset($this->$street_field_2);
5811 5811
             }
5812
-            if ( isset($this->$street_field_3)) {
5813
-                $this->$street_field .= "\n". $this->$street_field_3;
5812
+            if (isset($this->$street_field_3)) {
5813
+                $this->$street_field .= "\n".$this->$street_field_3;
5814 5814
                 unset($this->$street_field_3);
5815 5815
             }
5816
-            if ( isset($this->$street_field_4)) {
5817
-                $this->$street_field .= "\n". $this->$street_field_4;
5816
+            if (isset($this->$street_field_4)) {
5817
+                $this->$street_field .= "\n".$this->$street_field_4;
5818 5818
                 unset($this->$street_field_4);
5819 5819
             }
5820 5820
             $this->$street_field = trim($this->$street_field, "\n");
@@ -5823,7 +5823,7 @@  discard block
 block discarded – undo
5823 5823
 
5824 5824
     protected function getEncryptKey()
5825 5825
     {
5826
-        if(empty(self::$field_key)) {
5826
+        if (empty(self::$field_key)) {
5827 5827
             self::$field_key = blowfishGetKey('encrypt_field');
5828 5828
         }
5829 5829
         return self::$field_key;
@@ -5847,7 +5847,7 @@  discard block
 block discarded – undo
5847 5847
  */
5848 5848
     function decrypt_after_retrieve($value)
5849 5849
     {
5850
-        if(empty($value)) return $value; // no need to decrypt empty
5850
+        if (empty($value)) return $value; // no need to decrypt empty
5851 5851
         require_once("include/utils/encryption_utils.php");
5852 5852
         return blowfishDecode($this->getEncryptKey(), $value);
5853 5853
     }
@@ -5856,19 +5856,19 @@  discard block
 block discarded – undo
5856 5856
     * Moved from save() method, functionality is the same, but this is intended to handle
5857 5857
     * Optimistic locking functionality.
5858 5858
     */
5859
-    private function _checkOptimisticLocking($action, $isUpdate){
5860
-        if($this->optimistic_lock && !isset($_SESSION['o_lock_fs'])){
5861
-            if(isset($_SESSION['o_lock_id']) && $_SESSION['o_lock_id'] == $this->id && $_SESSION['o_lock_on'] == $this->object_name)
5859
+    private function _checkOptimisticLocking($action, $isUpdate) {
5860
+        if ($this->optimistic_lock && !isset($_SESSION['o_lock_fs'])) {
5861
+            if (isset($_SESSION['o_lock_id']) && $_SESSION['o_lock_id'] == $this->id && $_SESSION['o_lock_on'] == $this->object_name)
5862 5862
             {
5863
-                if($action == 'Save' && $isUpdate && isset($this->modified_user_id) && $this->has_been_modified_since($_SESSION['o_lock_dm'], $this->modified_user_id))
5863
+                if ($action == 'Save' && $isUpdate && isset($this->modified_user_id) && $this->has_been_modified_since($_SESSION['o_lock_dm'], $this->modified_user_id))
5864 5864
                 {
5865 5865
                     $_SESSION['o_lock_class'] = get_class($this);
5866 5866
                     $_SESSION['o_lock_module'] = $this->module_dir;
5867 5867
                     $_SESSION['o_lock_object'] = $this->toArray();
5868 5868
                     $saveform = "<form name='save' id='save' method='POST'>";
5869
-                    foreach($_POST as $key=>$arg)
5869
+                    foreach ($_POST as $key=>$arg)
5870 5870
                     {
5871
-                        $saveform .= "<input type='hidden' name='". addslashes($key) ."' value='". addslashes($arg) ."'>";
5871
+                        $saveform .= "<input type='hidden' name='".addslashes($key)."' value='".addslashes($arg)."'>";
5872 5872
                     }
5873 5873
                     $saveform .= "</form><script>document.getElementById('save').submit();</script>";
5874 5874
                     $_SESSION['o_lock_save'] = $saveform;
@@ -5885,20 +5885,20 @@  discard block
 block discarded – undo
5885 5885
         }
5886 5886
         else
5887 5887
         {
5888
-            if(isset($_SESSION['o_lock_object']))	{ unset ($_SESSION['o_lock_object']); }
5889
-            if(isset($_SESSION['o_lock_id']))		{ unset ($_SESSION['o_lock_id']); }
5890
-            if(isset($_SESSION['o_lock_dm']))		{ unset ($_SESSION['o_lock_dm']); }
5891
-            if(isset($_SESSION['o_lock_fs']))		{ unset ($_SESSION['o_lock_fs']); }
5892
-            if(isset($_SESSION['o_lock_save']))		{ unset ($_SESSION['o_lock_save']); }
5888
+            if (isset($_SESSION['o_lock_object'])) { unset ($_SESSION['o_lock_object']); }
5889
+            if (isset($_SESSION['o_lock_id'])) { unset ($_SESSION['o_lock_id']); }
5890
+            if (isset($_SESSION['o_lock_dm'])) { unset ($_SESSION['o_lock_dm']); }
5891
+            if (isset($_SESSION['o_lock_fs'])) { unset ($_SESSION['o_lock_fs']); }
5892
+            if (isset($_SESSION['o_lock_save'])) { unset ($_SESSION['o_lock_save']); }
5893 5893
         }
5894 5894
     }
5895 5895
 
5896 5896
     /**
5897 5897
     * Send assignment notifications and invites for meetings and calls
5898 5898
     */
5899
-    private function _sendNotifications($check_notify){
5900
-        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.
5901
-           && !$this->isOwner($this->created_by) )  // cn: bug 42727 no need to send email to owner (within workflow)
5899
+    private function _sendNotifications($check_notify) {
5900
+        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.
5901
+           && !$this->isOwner($this->created_by))  // cn: bug 42727 no need to send email to owner (within workflow)
5902 5902
         {
5903 5903
             $admin = new Administration();
5904 5904
             $admin->retrieveSettings();
@@ -5909,7 +5909,7 @@  discard block
 block discarded – undo
5909 5909
                 $GLOBALS['log']->info("Notifications: user assignment has changed, checking if user receives notifications");
5910 5910
                 $sendNotifications = true;
5911 5911
             }
5912
-            elseif(isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1)
5912
+            elseif (isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1)
5913 5913
             {
5914 5914
                 // cn: bug 5795 Send Invites failing for Contacts
5915 5915
                 $sendNotifications = true;
@@ -5920,7 +5920,7 @@  discard block
 block discarded – undo
5920 5920
             }
5921 5921
 
5922 5922
 
5923
-            if($sendNotifications == true)
5923
+            if ($sendNotifications == true)
5924 5924
             {
5925 5925
                 $notify_list = $this->get_notification_recipients();
5926 5926
                 foreach ($notify_list as $notify_user)
@@ -5981,10 +5981,10 @@  discard block
 block discarded – undo
5981 5981
 
5982 5982
         $cache_key = "load_cached_array.$module_dir.$module.$key";
5983 5983
         $result = sugar_cache_retrieve($cache_key);
5984
-        if(!empty($result))
5984
+        if (!empty($result))
5985 5985
         {
5986 5986
         	// Use SugarCache::EXTERNAL_CACHE_NULL_VALUE to store null values in the cache.
5987
-        	if($result == SugarCache::EXTERNAL_CACHE_NULL_VALUE)
5987
+        	if ($result == SugarCache::EXTERNAL_CACHE_NULL_VALUE)
5988 5988
         	{
5989 5989
         		return null;
5990 5990
         	}
@@ -5992,16 +5992,16 @@  discard block
 block discarded – undo
5992 5992
             return $result;
5993 5993
         }
5994 5994
 
5995
-        if(file_exists('modules/'.$module_dir.'/'.$fileName))
5995
+        if (file_exists('modules/'.$module_dir.'/'.$fileName))
5996 5996
         {
5997 5997
             // If the data was not loaded, try loading again....
5998
-            if(!isset($moduleDefs[$module]))
5998
+            if (!isset($moduleDefs[$module]))
5999 5999
             {
6000 6000
                 include('modules/'.$module_dir.'/'.$fileName);
6001 6001
                 $moduleDefs[$module] = $fields_array;
6002 6002
             }
6003 6003
             // Now that we have tried loading, make sure it was loaded
6004
-            if(empty($moduleDefs[$module]) || empty($moduleDefs[$module][$module][$key]))
6004
+            if (empty($moduleDefs[$module]) || empty($moduleDefs[$module][$module][$key]))
6005 6005
             {
6006 6006
                 // It was not loaded....  Fail.  Cache null to prevent future repeats of this calculation
6007 6007
 				sugar_cache_put($cache_key, SugarCache::EXTERNAL_CACHE_NULL_VALUE);
@@ -6026,7 +6026,7 @@  discard block
 block discarded – undo
6026 6026
      */
6027 6027
     public function getACLCategory()
6028 6028
     {
6029
-        return !empty($this->acl_category)?$this->acl_category:$this->module_dir;
6029
+        return !empty($this->acl_category) ? $this->acl_category : $this->module_dir;
6030 6030
     }
6031 6031
 
6032 6032
     /**
@@ -6075,7 +6075,7 @@  discard block
 block discarded – undo
6075 6075
             'select' => '',
6076 6076
             'join' => ''
6077 6077
         );
6078
-        if(isset($this->custom_fields))
6078
+        if (isset($this->custom_fields))
6079 6079
         {
6080 6080
             $result = $this->custom_fields->getJOIN($expandedList, $includeRelates, $where);
6081 6081
         }
@@ -6097,7 +6097,7 @@  discard block
 block discarded – undo
6097 6097
                 // walk through all currency-related fields
6098 6098
                 foreach ($this->field_defs as $this_field) {
6099 6099
                     if (isset($this_field['type']) && $this_field['type'] == 'relate'
6100
-                        && isset($this_field['module'])  && $this_field['module'] == 'Currencies'
6100
+                        && isset($this_field['module']) && $this_field['module'] == 'Currencies'
6101 6101
                         && isset($this_field['id_name']) && $this_field['id_name'] == 'currency_id') {
6102 6102
                         // populate related properties manually
6103 6103
                         $this_property = $this_field['name'];
Please login to merge, or discard this patch.
modules/ACLActions/ACLAction.php 1 patch
Spacing   +96 added lines, -96 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.
@@ -38,19 +38,19 @@  discard block
 block discarded – undo
38 38
  * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39 39
  ********************************************************************************/
40 40
 /* BEGIN - SECURITY GROUPS */
41
-if(file_exists("modules/ACLActions/actiondefs.override.php")){
41
+if (file_exists("modules/ACLActions/actiondefs.override.php")) {
42 42
 	require_once("modules/ACLActions/actiondefs.override.php");
43 43
 } else {
44 44
 require_once('modules/ACLActions/actiondefs.php');
45 45
 }
46 46
 /* END - SECURITY GROUPS */
47
-class ACLAction  extends SugarBean{
47
+class ACLAction  extends SugarBean {
48 48
     var $module_dir = 'ACLActions';
49 49
     var $object_name = 'ACLAction';
50 50
     var $table_name = 'acl_actions';
51 51
     var $new_schema = true;
52 52
     var $disable_custom_fields = true;
53
-    function ACLAction(){
53
+    function ACLAction() {
54 54
         parent::SugarBean();
55 55
     }
56 56
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
     * @param STRING $category - the category (e.g module name - Accounts, Contacts)
62 62
     * @param STRING $type - the type (e.g. 'module', 'field')
63 63
     */
64
-    static function addActions($category, $type='module'){
64
+    static function addActions($category, $type = 'module') {
65 65
         global $ACLActions;
66 66
         $db = DBManagerFactory::getInstance();
67
-        if(isset($ACLActions[$type])){
68
-            foreach($ACLActions[$type]['actions'] as $action_name =>$action_def){
67
+        if (isset($ACLActions[$type])) {
68
+            foreach ($ACLActions[$type]['actions'] as $action_name =>$action_def) {
69 69
 
70 70
                 $action = new ACLAction();
71
-                $query = "SELECT * FROM " . $action->table_name . " WHERE name='$action_name' AND category = '$category' AND acltype='$type' AND deleted=0 ";
71
+                $query = "SELECT * FROM ".$action->table_name." WHERE name='$action_name' AND category = '$category' AND acltype='$type' AND deleted=0 ";
72 72
                 $result = $db->query($query);
73 73
                 //only add if an action with that name and category don't exist
74
-                $row=$db->fetchByAssoc($result);
74
+                $row = $db->fetchByAssoc($result);
75 75
                 if ($row == null) {
76 76
                     $action->name = $action_name;
77 77
                     $action->category = $category;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                 }
85 85
             }
86 86
 
87
-        }else{
87
+        } else {
88 88
             sugar_die("FAILED TO ADD: $category - TYPE $type NOT DEFINED IN modules/ACLActions/actiondefs.php");
89 89
         }
90 90
 
@@ -97,22 +97,22 @@  discard block
 block discarded – undo
97 97
     * @param STRING $category - the category (e.g module name - Accounts, Contacts)
98 98
     * @param STRING $type - the type (e.g. 'module', 'field')
99 99
     */
100
-    public static function removeActions($category, $type='module'){
100
+    public static function removeActions($category, $type = 'module') {
101 101
         global $ACLActions;
102 102
         $db = DBManagerFactory::getInstance();
103
-        if(isset($ACLActions[$type])){
104
-            foreach($ACLActions[$type]['actions'] as $action_name =>$action_def){
103
+        if (isset($ACLActions[$type])) {
104
+            foreach ($ACLActions[$type]['actions'] as $action_name =>$action_def) {
105 105
 
106 106
                 $action = new ACLAction();
107
-                $query = "SELECT * FROM " . $action->table_name . " WHERE name='$action_name' AND category = '$category' AND acltype='$type' and deleted=0";
107
+                $query = "SELECT * FROM ".$action->table_name." WHERE name='$action_name' AND category = '$category' AND acltype='$type' and deleted=0";
108 108
                 $result = $db->query($query);
109 109
                 //only add if an action with that name and category don't exist
110
-                $row=$db->fetchByAssoc($result);
110
+                $row = $db->fetchByAssoc($result);
111 111
                 if ($row != null) {
112 112
                     $action->mark_deleted($row['id']);
113 113
                 }
114 114
             }
115
-        }else{
115
+        } else {
116 116
             sugar_die("FAILED TO REMOVE: $category : $name - TYPE $type NOT DEFINED IN modules/ACLActions/actiondefs.php");
117 117
         }
118 118
     }
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
     * @param INT $access - the access level you want the color for
126 126
     * @return the color either name or hex representation or false if the level does not exist
127 127
     */
128
-    protected static function AccessColor($access){
128
+    protected static function AccessColor($access) {
129 129
         global $ACLActionAccessLevels;
130
-        if(isset($ACLActionAccessLevels[$access])){
130
+        if (isset($ACLActionAccessLevels[$access])) {
131 131
 
132 132
             return $ACLActionAccessLevels[$access]['color'];
133 133
         }
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
     * @param INT $access - the access level you want the color for
144 144
     * @return the translated access level name or false if the level does not exist
145 145
     */
146
-    static function AccessName($access){
146
+    static function AccessName($access) {
147 147
         global $ACLActionAccessLevels;
148
-        if(isset($ACLActionAccessLevels[$access])){
148
+        if (isset($ACLActionAccessLevels[$access])) {
149 149
             return translate($ACLActionAccessLevels[$access]['label'], 'ACLActions');
150 150
         }
151 151
         return false;
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
      * @param INT $access - the access level you want the color for
161 161
      * @return the access level label or false if the level does not exist
162 162
      */
163
-    protected static function AccessLabel($access){
163
+    protected static function AccessLabel($access) {
164 164
         global $ACLActionAccessLevels;
165
-        if(isset($ACLActionAccessLevels[$access])){
166
-            $label=preg_replace('/(LBL_ACCESS_)(.*)/', '$2', $ACLActionAccessLevels[$access]['label']);
165
+        if (isset($ACLActionAccessLevels[$access])) {
166
+            $label = preg_replace('/(LBL_ACCESS_)(.*)/', '$2', $ACLActionAccessLevels[$access]['label']);
167 167
             return strtolower($label);
168 168
 
169 169
         }
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
     * this is used for building select boxes
177 177
     * @return array containg access levels (ints) as keys and access names as values
178 178
     */
179
-    protected static function getAccessOptions( $action, $type='module'){
179
+    protected static function getAccessOptions($action, $type = 'module') {
180 180
         global $ACLActions;
181 181
         $options = array();
182 182
 
183
-        if(empty($ACLActions[$type]['actions'][$action]['aclaccess']))return $options;
184
-        foreach($ACLActions[$type]['actions'][$action]['aclaccess'] as $action){
183
+        if (empty($ACLActions[$type]['actions'][$action]['aclaccess']))return $options;
184
+        foreach ($ACLActions[$type]['actions'][$action]['aclaccess'] as $action) {
185 185
             $options[$action] = ACLAction::AccessName($action);
186 186
         }
187 187
         return $options;
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
     *
195 195
     *
196 196
     */
197
-    public static function getDefaultActions($type='module', $action=''){
197
+    public static function getDefaultActions($type = 'module', $action = '') {
198 198
         $query = "SELECT * FROM acl_actions WHERE deleted=0 ";
199
-        if(!empty($type)){
199
+        if (!empty($type)) {
200 200
             $query .= " AND acltype='$type'";
201 201
         }
202
-        if(!empty($action)){
202
+        if (!empty($action)) {
203 203
             $query .= "AND name='$action'";
204 204
         }
205 205
         $query .= " ORDER BY category";
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
         $db = DBManagerFactory::getInstance();
208 208
         $result = $db->query($query);
209 209
         $default_actions = array();
210
-        while($row = $db->fetchByAssoc($result) ){
210
+        while ($row = $db->fetchByAssoc($result)) {
211 211
             $acl = new ACLAction();
212 212
             $acl->populateFromRow($row);
213 213
             $default_actions[] = $acl;
@@ -226,19 +226,19 @@  discard block
 block discarded – undo
226 226
     * @return ARRAY of ACLActionsArray
227 227
     */
228 228
 
229
-    static function getUserActions($user_id,$refresh=false, $category='',$type='', $action=''){
229
+    static function getUserActions($user_id, $refresh = false, $category = '', $type = '', $action = '') {
230 230
         //check in the session if we already have it loaded
231
-        if(!$refresh && !empty($_SESSION['ACL'][$user_id])){
232
-            if(empty($category) && empty($action)){
231
+        if (!$refresh && !empty($_SESSION['ACL'][$user_id])) {
232
+            if (empty($category) && empty($action)) {
233 233
                 return $_SESSION['ACL'][$user_id];
234
-            }else{
235
-                if(!empty($category) && isset($_SESSION['ACL'][$user_id][$category])){
236
-                    if(empty($action)){
237
-                        if(empty($type)){
234
+            } else {
235
+                if (!empty($category) && isset($_SESSION['ACL'][$user_id][$category])) {
236
+                    if (empty($action)) {
237
+                        if (empty($type)) {
238 238
                             return $_SESSION['ACL'][$user_id][$category];
239 239
                         }
240 240
                         return $_SESSION['ACL'][$user_id][$category][$type];
241
-                    }else if(!empty($type) && isset($_SESSION['ACL'][$user_id][$category][$type][$action])){
241
+                    } else if (!empty($type) && isset($_SESSION['ACL'][$user_id][$category][$type][$action])) {
242 242
                         return $_SESSION['ACL'][$user_id][$category][$type][$action];
243 243
                     }
244 244
                 }
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
         //if we don't have it loaded then lets check against the db
248 248
         $additional_where = '';
249 249
         $db = DBManagerFactory::getInstance();
250
-        if(!empty($category)){
250
+        if (!empty($category)) {
251 251
             $additional_where .= " AND acl_actions.category = '$category' ";
252 252
         }
253
-        if(!empty($action)){
253
+        if (!empty($action)) {
254 254
             $additional_where .= " AND acl_actions.name = '$action' ";
255 255
         }
256
-        if(!empty($type)){
256
+        if (!empty($type)) {
257 257
             $additional_where .= " AND acl_actions.acltype = '$type' ";
258 258
         }
259 259
 		/* BEGIN - SECURITY GROUPS */ 
@@ -294,38 +294,38 @@  discard block
 block discarded – undo
294 294
 		$has_user_role = false; //used for user_role_precedence
295 295
 		$has_role = false; //used to determine if default actions can be ignored. If a user has a defined role don't use the defaults
296 296
 		/* END - SECURITY GROUPS */
297
-        while($row = $db->fetchByAssoc($result, FALSE) ){
297
+        while ($row = $db->fetchByAssoc($result, FALSE)) {
298 298
 			/* BEGIN - SECURITY GROUPS */ 
299
-			if($has_user_role == false && $row['user_role'] == 1) {
299
+			if ($has_user_role == false && $row['user_role'] == 1) {
300 300
 				$has_user_role = true;
301 301
 			}
302
-			if($has_role == false && ($row['user_role'] == 1 || $row['user_role'] ==0)) {
302
+			if ($has_role == false && ($row['user_role'] == 1 || $row['user_role'] == 0)) {
303 303
 				$has_role = true;
304 304
 			}
305 305
 			//if user roles should take precedence over group roles and we have a user role 
306 306
 			//break when we get to processing the group roles
307
-			if($has_user_role == true && $row['user_role'] == 0 
307
+			if ($has_user_role == true && $row['user_role'] == 0 
308 308
 					&& isset($sugar_config['securitysuite_user_role_precedence'])
309
-					&& $sugar_config['securitysuite_user_role_precedence'] == true ) 
309
+					&& $sugar_config['securitysuite_user_role_precedence'] == true) 
310 310
 			{
311 311
 				break; 
312 312
 			}
313
-			if($row['user_role'] == -1 && $has_role == true) {
313
+			if ($row['user_role'] == -1 && $has_role == true) {
314 314
 				break; //no need for default actions when a role is assigned to the user or user's group already
315 315
 			}
316 316
 			/* END - SECURITY GROUPS */
317 317
             $acl = new ACLAction();
318
-            $isOverride  = false;
318
+            $isOverride = false;
319 319
             $acl->populateFromRow($row);
320
-            if(!empty($row['access_override'])){
320
+            if (!empty($row['access_override'])) {
321 321
                 $acl->aclaccess = $row['access_override'];
322 322
                 $isOverride = true;
323 323
             }
324
-            if(!isset($selected_actions[$acl->category])){
324
+            if (!isset($selected_actions[$acl->category])) {
325 325
                 $selected_actions[$acl->category] = array();
326 326
 
327 327
             }
328
-            if(!isset($selected_actions[$acl->category][$acl->acltype][$acl->name])
328
+            if (!isset($selected_actions[$acl->category][$acl->acltype][$acl->name])
329 329
 				|| (
330 330
 					/* BEGIN - SECURITY GROUPS - additive security*/
331 331
 					(
@@ -353,18 +353,18 @@  discard block
 block discarded – undo
353 353
         }
354 354
 
355 355
         //only set the session variable if it was a full list;
356
-        if(empty($category) && empty($action)){
357
-            if(!isset($_SESSION['ACL'])){
356
+        if (empty($category) && empty($action)) {
357
+            if (!isset($_SESSION['ACL'])) {
358 358
                 $_SESSION['ACL'] = array();
359 359
             }
360 360
             $_SESSION['ACL'][$user_id] = $selected_actions;
361
-        }else{
362
-            if(empty($action) && !empty($category)){
363
-                if(!empty($type)){
364
-                    $_SESSION['ACL'][$user_id][$category][$type] = $selected_actions[$category][$type];}
361
+        } else {
362
+            if (empty($action) && !empty($category)) {
363
+                if (!empty($type)) {
364
+                    $_SESSION['ACL'][$user_id][$category][$type] = $selected_actions[$category][$type]; }
365 365
                 $_SESSION['ACL'][$user_id][$category] = $selected_actions[$category];
366
-            }else{
367
-                if(!empty($action) && !empty($category) && !empty($type)){
366
+            } else {
367
+                if (!empty($action) && !empty($category) && !empty($type)) {
368 368
                 $_SESSION['ACL'][$user_id][$category][$type][$action] = $selected_actions[$category][$action];
369 369
 
370 370
             }
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	/**
401 401
     static function hasAccess($is_owner=false, $access = 0){
402 402
 	*/
403
-	static function hasAccess($is_owner=false, $in_group=false, $access = 0, ACLAction $action = null){
403
+	static function hasAccess($is_owner = false, $in_group = false, $access = 0, ACLAction $action = null) {
404 404
 		/**
405 405
         if($access != 0 && $access == ACL_ALLOW_ALL || ($is_owner && $access == ACL_ALLOW_OWNER))return true;
406 406
        //if this exists, then this function is not static, so check the aclaccess parameter
@@ -409,14 +409,14 @@  discard block
 block discarded – undo
409 409
             return true;
410 410
         }
411 411
 		*/
412
-		if($access != 0 && ($access == ACL_ALLOW_ALL 
413
-			|| ($is_owner && ($access == ACL_ALLOW_OWNER || $access == ACL_ALLOW_GROUP) )  //if owner that's better than in group so count it...better way to clean this up?
412
+		if ($access != 0 && ($access == ACL_ALLOW_ALL 
413
+			|| ($is_owner && ($access == ACL_ALLOW_OWNER || $access == ACL_ALLOW_GROUP))  //if owner that's better than in group so count it...better way to clean this up?
414 414
 			|| ($in_group && $access == ACL_ALLOW_GROUP) //need to pass if in group with access somehow
415 415
 		)) {
416 416
 			return true;
417 417
 		}
418
-        if(!is_null($action) && isset($action->aclaccess)){
419
-			if($action->aclaccess == ACL_ALLOW_ALL
418
+        if (!is_null($action) && isset($action->aclaccess)) {
419
+			if ($action->aclaccess == ACL_ALLOW_ALL
420 420
 				|| ($is_owner && $action->aclaccess == ($access == ACL_ALLOW_OWNER || $access == ACL_ALLOW_GROUP))
421 421
 				|| ($in_group && $access == ACL_ALLOW_GROUP) //need to pass if in group with access somehow
422 422
 			) {
@@ -438,15 +438,15 @@  discard block
 block discarded – undo
438 438
 	 * @param STRING $type
439 439
 	 * @return boolean
440 440
 	 */
441
-	static function userNeedsSecurityGroup($user_id, $category, $action,$type='module'){
441
+	static function userNeedsSecurityGroup($user_id, $category, $action, $type = 'module') {
442 442
 		//check if we don't have it set in the cache if not lets reload the cache
443 443
 		
444
-		if(empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
444
+		if (empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
445 445
 			ACLAction::getUserActions($user_id, false);
446 446
 			
447 447
 		}
448 448
 		
449
-		if(!empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
449
+		if (!empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
450 450
 			return $_SESSION['ACL'][$user_id][$category][$type][$action]['aclaccess'] == ACL_ALLOW_GROUP;
451 451
 		}
452 452
         return false;
@@ -472,19 +472,19 @@  discard block
 block discarded – undo
472 472
 	/**
473 473
     public static function userHasAccess($user_id, $category, $action,$type='module', $is_owner = false){
474 474
 	*/
475
-	public static function userHasAccess($user_id, $category, $action,$type='module', $is_owner = false, $in_group = false){
475
+	public static function userHasAccess($user_id, $category, $action, $type = 'module', $is_owner = false, $in_group = false) {
476 476
        global $current_user;
477
-       if($current_user->isAdminForModule($category)&& !isset($_SESSION['ACL'][$user_id][$category][$type][$action]['aclaccess'])){
477
+       if ($current_user->isAdminForModule($category) && !isset($_SESSION['ACL'][$user_id][$category][$type][$action]['aclaccess'])) {
478 478
         return true;
479 479
         }
480 480
         //check if we don't have it set in the cache if not lets reload the cache
481
-        if(ACLAction::getUserAccessLevel($user_id, $category, 'access', $type) < ACL_ALLOW_ENABLED) return false;
482
-        if(empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
481
+        if (ACLAction::getUserAccessLevel($user_id, $category, 'access', $type) < ACL_ALLOW_ENABLED) return false;
482
+        if (empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
483 483
             ACLAction::getUserActions($user_id, false);
484 484
 
485 485
         }
486 486
 
487
-        if(!empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
487
+        if (!empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
488 488
 /**
489 489
             return ACLAction::hasAccess($is_owner, $_SESSION['ACL'][$user_id][$category][$type][$action]['aclaccess']);
490 490
 */
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
     * @param STRING $type
505 505
     * @return INT (ACCESS LEVEL)
506 506
     */
507
-    public static function getUserAccessLevel($user_id, $category, $action,$type='module'){
508
-        if(empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
507
+    public static function getUserAccessLevel($user_id, $category, $action, $type = 'module') {
508
+        if (empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
509 509
             ACLAction::getUserActions($user_id, false);
510 510
 
511 511
         }
512
-        if(!empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
512
+        if (!empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
513 513
             if (!empty($_SESSION['ACL'][$user_id][$category][$type]['admin']) && $_SESSION['ACL'][$user_id][$category][$type]['admin']['aclaccess'] >= ACL_ALLOW_ADMIN)
514 514
             {
515 515
                 // If you have admin access for a module, all ACL's are allowed
@@ -529,16 +529,16 @@  discard block
 block discarded – undo
529 529
     * @param STRING $type
530 530
     * @return boolean
531 531
     */
532
-    public static function userNeedsOwnership($user_id, $category, $action,$type='module'){
532
+    public static function userNeedsOwnership($user_id, $category, $action, $type = 'module') {
533 533
         //check if we don't have it set in the cache if not lets reload the cache
534 534
 
535
-        if(empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
535
+        if (empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
536 536
             ACLAction::getUserActions($user_id, false);
537 537
 
538 538
         }
539 539
 
540 540
 
541
-        if(!empty($_SESSION['ACL'][$user_id][$category][$type][$action])){
541
+        if (!empty($_SESSION['ACL'][$user_id][$category][$type][$action])) {
542 542
             return $_SESSION['ACL'][$user_id][$category][$type][$action]['aclaccess'] == ACL_ALLOW_OWNER;
543 543
         }
544 544
         return false;
@@ -551,18 +551,18 @@  discard block
 block discarded – undo
551 551
     *
552 552
     * @param unknown_type $categories
553 553
     */
554
-    public static function setupCategoriesMatrix(&$categories){
554
+    public static function setupCategoriesMatrix(&$categories) {
555 555
         global $ACLActions, $current_user;
556 556
         $names = array();
557 557
         $disabled = array();
558
-        foreach($categories as $cat_name=>$category){
559
-            foreach($category as $type_name=>$type){
560
-                foreach($type as $act_name=>$action){
558
+        foreach ($categories as $cat_name=>$category) {
559
+            foreach ($category as $type_name=>$type) {
560
+                foreach ($type as $act_name=>$action) {
561 561
                     $names[$act_name] = translate($ACLActions[$type_name]['actions'][$act_name]['label'], 'ACLActions');
562 562
                     $categories[$cat_name][$type_name][$act_name]['accessColor'] = ACLAction::AccessColor($action['aclaccess']);
563
-                    if($type_name== 'module'){
563
+                    if ($type_name == 'module') {
564 564
 
565
-                        if($act_name != 'aclaccess' && $categories[$cat_name]['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED){
565
+                        if ($act_name != 'aclaccess' && $categories[$cat_name]['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED) {
566 566
                             $categories[$cat_name][$type_name][$act_name]['accessColor'] = 'darkgray';
567 567
                             $disabled[] = $cat_name;
568 568
                         }
@@ -571,19 +571,19 @@  discard block
 block discarded – undo
571 571
                     $categories[$cat_name][$type_name][$act_name]['accessName'] = ACLAction::AccessName($action['aclaccess']);
572 572
                     $categories[$cat_name][$type_name][$act_name]['accessLabel'] = ACLAction::AccessLabel($action['aclaccess']);
573 573
 
574
-                    if($cat_name=='Users'&& $act_name=='admin'){
575
-                        $categories[$cat_name][$type_name][$act_name]['accessOptions'][ACL_ALLOW_DEFAULT]=ACLAction::AccessName(ACL_ALLOW_DEFAULT);;
576
-                        $categories[$cat_name][$type_name][$act_name]['accessOptions'][ACL_ALLOW_DEV]=ACLAction::AccessName(ACL_ALLOW_DEV);;
574
+                    if ($cat_name == 'Users' && $act_name == 'admin') {
575
+                        $categories[$cat_name][$type_name][$act_name]['accessOptions'][ACL_ALLOW_DEFAULT] = ACLAction::AccessName(ACL_ALLOW_DEFAULT); ;
576
+                        $categories[$cat_name][$type_name][$act_name]['accessOptions'][ACL_ALLOW_DEV] = ACLAction::AccessName(ACL_ALLOW_DEV); ;
577 577
                     }
578
-                    else{
579
-                    $categories[$cat_name][$type_name][$act_name]['accessOptions'] =  ACLAction::getAccessOptions($act_name, $type_name);
578
+                    else {
579
+                    $categories[$cat_name][$type_name][$act_name]['accessOptions'] = ACLAction::getAccessOptions($act_name, $type_name);
580 580
                     }
581 581
                 }
582 582
             }
583 583
         }
584 584
 
585
-        if(!is_admin($current_user)){
586
-            foreach($disabled as $cat_name){
585
+        if (!is_admin($current_user)) {
586
+            foreach ($disabled as $cat_name) {
587 587
                 unset($categories[$cat_name]);
588 588
             }
589 589
         }
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
     *
599 599
     * @return array of fields with id, name, access and category
600 600
     */
601
-    function toArray($dbOnly = false, $stringOnly = false, $upperKeys = false){
601
+    function toArray($dbOnly = false, $stringOnly = false, $upperKeys = false) {
602 602
         $array_fields = array('id', 'aclaccess');
603 603
         $arr = array();
604
-        foreach($array_fields as $field){
604
+        foreach ($array_fields as $field) {
605 605
             $arr[$field] = $this->$field;
606 606
         }
607 607
         return $arr;
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
     *
614 614
     * @param Array $arr
615 615
     */
616
-    function fromArray($arr){
617
-        foreach($arr as $name=>$value){
616
+    function fromArray($arr) {
617
+        foreach ($arr as $name=>$value) {
618 618
             $this->$name = $value;
619 619
         }
620 620
     }
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
     * clears the session variable storing the cache information for acls
625 625
     *
626 626
     */
627
-    function clearSessionCache(){
627
+    function clearSessionCache() {
628 628
         unset($_SESSION['ACL']);
629 629
     }
630 630
 
Please login to merge, or discard this patch.
modules/AOS_Products_Quotes/Line_Items.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  * @author SalesAgility <[email protected]>
23 23
  */
24 24
 
25
-function display_lines($focus, $field, $value, $view){
25
+function display_lines($focus, $field, $value, $view) {
26 26
 
27 27
     global $sugar_config, $locale, $app_list_strings, $mod_strings;
28 28
 
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
 
32 32
     $html = '';
33 33
 
34
-    if($view == 'EditView'){
34
+    if ($view == 'EditView') {
35 35
 
36 36
         $html .= '<script src="modules/AOS_Products_Quotes/line_items.js"></script>';
37
-        if(file_exists('custom/modules/AOS_Products_Quotes/line_items.js')){
37
+        if (file_exists('custom/modules/AOS_Products_Quotes/line_items.js')) {
38 38
             $html .= '<script src="custom/modules/AOS_Products_Quotes/line_items.js"></script>';
39 39
         }
40 40
         $html .= '<script language="javascript">var sig_digits = '.$locale->getPrecision().';';
@@ -45,18 +45,18 @@  discard block
 block discarded – undo
45 45
 
46 46
         $html .= "<table border='0' cellspacing='4' width='37.5%' id='lineItems'></table>";
47 47
 
48
-        if($enable_groups){
48
+        if ($enable_groups) {
49 49
             $html .= "<div style='padding-top: 10px; padding-bottom:10px;'>";
50 50
             $html .= "<input type=\"button\" tabindex=\"116\" class=\"button\" value=\"".$mod_strings['LBL_ADD_GROUP']."\" id=\"addGroup\" onclick=\"insertGroup(0)\" />";
51 51
             $html .= "</div>";
52 52
         }
53 53
         $html .= '<input type="hidden" name="vathidden" id="vathidden" value="'.get_select_options_with_id($app_list_strings['vat_list'], '').'">
54 54
 				  <input type="hidden" name="discounthidden" id="discounthidden" value="'.get_select_options_with_id($app_list_strings['discount_list'], '').'">';
55
-        if($focus->id != '') {
55
+        if ($focus->id != '') {
56 56
             require_once('modules/AOS_Products_Quotes/AOS_Products_Quotes.php');
57 57
             require_once('modules/AOS_Line_Item_Groups/AOS_Line_Item_Groups.php');
58 58
 
59
-            $sql = "SELECT pg.id, pg.group_id FROM aos_products_quotes pg LEFT JOIN aos_line_item_groups lig ON pg.group_id = lig.id WHERE pg.parent_type = '" . $focus->object_name . "' AND pg.parent_id = '" . $focus->id . "' AND pg.deleted = 0 ORDER BY lig.number ASC, pg.number ASC";
59
+            $sql = "SELECT pg.id, pg.group_id FROM aos_products_quotes pg LEFT JOIN aos_line_item_groups lig ON pg.group_id = lig.id WHERE pg.parent_type = '".$focus->object_name."' AND pg.parent_id = '".$focus->id."' AND pg.deleted = 0 ORDER BY lig.number ASC, pg.number ASC";
60 60
 
61 61
             $result = $focus->db->query($sql);
62 62
             $html .= "<script>
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
                     $group_item = json_encode($group_item->toArray());
76 76
                 }
77 77
                 $html .= "<script>
78
-                        insertLineItems(" . $line_item . "," . $group_item . ");
78
+                        insertLineItems(" . $line_item.",".$group_item.");
79 79
                     </script>";
80 80
 
81 81
             }
82 82
         }
83
-        if(!$enable_groups){
83
+        if (!$enable_groups) {
84 84
             $html .= '<script>insertGroup();</script>';
85 85
         }
86 86
 
87 87
     }
88
-    else if($view == 'DetailView'){
88
+    else if ($view == 'DetailView') {
89 89
         $params = array('currency_id' => $focus->currency_id);
90 90
 
91 91
         $sql = "SELECT pg.id, pg.group_id FROM aos_products_quotes pg LEFT JOIN aos_line_item_groups lig ON pg.group_id = lig.id WHERE pg.parent_type = '".$focus->object_name."' AND pg.parent_id = '".$focus->id."' AND pg.deleted = 0 ORDER BY lig.number ASC, pg.number ASC";
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
             $line_item->retrieve($row['id']);
110 110
 
111 111
 
112
-            if($enable_groups && ($group_id != $row['group_id'] || $i == 0)){
112
+            if ($enable_groups && ($group_id != $row['group_id'] || $i == 0)) {
113 113
                 $html .= $groupStart.$product.$service.$groupEnd;
114
-                if($i != 0)$html .= "<tr><td colspan='9' nowrap='nowrap'><br></td></tr>";
114
+                if ($i != 0)$html .= "<tr><td colspan='9' nowrap='nowrap'><br></td></tr>";
115 115
                 $groupStart = '';
116 116
                 $groupEnd = '';
117 117
                 $product = '';
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
                 $groupEnd .= "<td class='tabDetailViewDL' style='text-align: right;padding:2px;'>".currency_format_number($group_item->total_amount, $params)."</td>";
153 153
                 $groupEnd .= "</tr>";
154 154
             }
155
-            if($line_item->product_id != '0' && $line_item->product_id != null){
156
-                if($productCount == 0)
155
+            if ($line_item->product_id != '0' && $line_item->product_id != null) {
156
+                if ($productCount == 0)
157 157
                 {
158 158
                     $product .= "<tr>";
159 159
                     $product .= "<td width='5%' class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>&nbsp;</td>";
@@ -169,26 +169,26 @@  discard block
 block discarded – undo
169 169
                 }
170 170
 
171 171
                 $product .= "<tr>";
172
-                $product_note = wordwrap($line_item->description,40,"<br />\n");
172
+                $product_note = wordwrap($line_item->description, 40, "<br />\n");
173 173
                 $product .= "<td class='tabDetailViewDF' style='text-align: left; padding:2px;'>".++$productCount."</td>";
174
-                $product .= "<td class='tabDetailViewDF' style='padding:2px;'>".stripDecimalPointsAndTrailingZeroes(format_number($line_item->product_qty),$sep[1])."</td>";
174
+                $product .= "<td class='tabDetailViewDF' style='padding:2px;'>".stripDecimalPointsAndTrailingZeroes(format_number($line_item->product_qty), $sep[1])."</td>";
175 175
 
176 176
                 $product .= "<td class='tabDetailViewDF' style='padding:2px;'><a href='index.php?module=AOS_Products&action=DetailView&record=".$line_item->product_id."' class='tabDetailViewDFLink'>".$line_item->name."</a><br />".$product_note."</td>";
177
-                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_list_price,$params)."</td>";
177
+                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_list_price, $params)."</td>";
178 178
 
179 179
                 $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".get_discount_string($line_item->discount, $line_item->product_discount, $params, $locale, $sep)."</td>";
180 180
 
181
-                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_unit_price,$params )."</td>";
182
-                if($locale->getPrecision()){
183
-                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".rtrim(rtrim(format_number($line_item->vat), '0'),$sep[1])."%</td>";
181
+                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_unit_price, $params)."</td>";
182
+                if ($locale->getPrecision()) {
183
+                    $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".rtrim(rtrim(format_number($line_item->vat), '0'), $sep[1])."%</td>";
184 184
                 } else {
185 185
                     $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".format_number($line_item->vat)."%</td>";
186 186
                 }
187
-                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->vat_amt,$params )."</td>";
188
-                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_total_price,$params )."</td>";
187
+                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->vat_amt, $params)."</td>";
188
+                $product .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_total_price, $params)."</td>";
189 189
                 $product .= "</tr>";
190 190
             } else {
191
-                if($serviceCount == 0)
191
+                if ($serviceCount == 0)
192 192
                 {
193 193
                     $service .= "<tr>";
194 194
                     $service .= "<td width='5%' class='tabDetailViewDL' style='text-align: left;padding:2px;' scope='row'>&nbsp;</td>";
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
                 $service .= "<tr>";
206 206
                 $service .= "<td class='tabDetailViewDF' style='text-align: left; padding:2px;'>".++$serviceCount."</td>";
207 207
                 $service .= "<td class='tabDetailViewDF' style='padding:2px;' colspan='2'>".$line_item->name."</td>";
208
-                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_list_price,$params)."</td>";
208
+                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_list_price, $params)."</td>";
209 209
 
210 210
                 $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".get_discount_string($line_item->discount, $line_item->product_discount, $params, $locale, $sep)."</td>";
211 211
 
212 212
 
213
-                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_unit_price,$params)."</td>";
213
+                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_unit_price, $params)."</td>";
214 214
                 $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".rtrim(rtrim(format_number($line_item->vat), '0'), $sep[1])."%</td>";
215
-                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->vat_amt,$params )."</td>";
216
-                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_total_price,$params )."</td>";
215
+                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->vat_amt, $params)."</td>";
216
+                $service .= "<td class='tabDetailViewDF' style='text-align: right; padding:2px;'>".currency_format_number($line_item->product_total_price, $params)."</td>";
217 217
                 $service .= "</tr>";
218 218
 
219 219
             }
@@ -230,22 +230,22 @@  discard block
 block discarded – undo
230 230
 //field was 0.
231 231
 //The approach below will strip off the fractional part if it is only zeroes (and in this case the decimal separator
232 232
 //will also be stripped off) The custom decimal separator is passed in to the function from the locale settings
233
-function stripDecimalPointsAndTrailingZeroes($inputString,$decimalSeparator)
233
+function stripDecimalPointsAndTrailingZeroes($inputString, $decimalSeparator)
234 234
 {
235
-    return preg_replace('/'.preg_quote($decimalSeparator).'[0]+$/','',$inputString);
235
+    return preg_replace('/'.preg_quote($decimalSeparator).'[0]+$/', '', $inputString);
236 236
 }
237 237
 
238
-function get_discount_string($type, $amount, $params, $locale, $sep){
239
-    if($amount != '' && $amount != '0.00')
238
+function get_discount_string($type, $amount, $params, $locale, $sep) {
239
+    if ($amount != '' && $amount != '0.00')
240 240
     {
241
-        if($type == 'Amount')
241
+        if ($type == 'Amount')
242 242
         {
243
-            return currency_format_number($amount,$params )."</td>";
243
+            return currency_format_number($amount, $params)."</td>";
244 244
         }
245
-        else if($locale->getPrecision())
245
+        else if ($locale->getPrecision())
246 246
         {
247
-            return rtrim(rtrim(format_number($amount), '0'),$sep[1])."%";
248
-        } else{
247
+            return rtrim(rtrim(format_number($amount), '0'), $sep[1])."%";
248
+        } else {
249 249
             return format_number($amount)."%";
250 250
         }
251 251
     }
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
     }
256 256
 }
257 257
 
258
-function display_shipping_vat($focus, $field, $value, $view){
258
+function display_shipping_vat($focus, $field, $value, $view) {
259 259
 
260
-    if($view == 'EditView'){
260
+    if ($view == 'EditView') {
261 261
         global $app_list_strings;
262 262
 
263
-        if($value != '') $value = format_number($value);
263
+        if ($value != '') $value = format_number($value);
264 264
 
265 265
         $html = "<input id='shipping_tax_amt' type='text' tabindex='0' title='' value='".$value."' maxlength='26,6' size='22' name='shipping_tax_amt' onblur='calculateTotal(\"lineItems\");'>";
266 266
         $html .= "<select name='shipping_tax' id='shipping_tax' onchange='calculateTotal(\"lineItems\");' >".get_select_options_with_id($app_list_strings['vat_list'], (isset($focus->shipping_tax) ? $focus->shipping_tax : ''))."</select>";
Please login to merge, or discard this patch.
modules/AOS_Products_Quotes/AOS_Products_Quotes.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,22 +51,22 @@  discard block
 block discarded – undo
51 51
     function save_lines($post_data, $parent, $groups = array(), $key = '')
52 52
     {
53 53
 
54
-        $line_count = isset($post_data[$key . 'name']) ? count($post_data[$key . 'name']) : 0;
54
+        $line_count = isset($post_data[$key.'name']) ? count($post_data[$key.'name']) : 0;
55 55
         $j = 0;
56 56
         for ($i = 0; $i < $line_count; ++$i) {
57 57
 
58
-            if ($post_data[$key . 'deleted'][$i] == 1) {
59
-                $this->mark_deleted($post_data[$key . 'id'][$i]);
58
+            if ($post_data[$key.'deleted'][$i] == 1) {
59
+                $this->mark_deleted($post_data[$key.'id'][$i]);
60 60
             } else {
61 61
                 $product_quote = new AOS_Products_Quotes();
62 62
                 foreach ($this->field_defs as $field_def) {
63 63
                     $field_name = $field_def['name'];
64
-                    if (isset($post_data[$key . $field_name][$i])) {
65
-                        $product_quote->$field_name = $post_data[$key . $field_name][$i];
64
+                    if (isset($post_data[$key.$field_name][$i])) {
65
+                        $product_quote->$field_name = $post_data[$key.$field_name][$i];
66 66
                     }
67 67
                 }
68
-                if (isset($post_data[$key . 'group_number'][$i])) {
69
-                    $product_quote->group_id = $groups[$post_data[$key . 'group_number'][$i]];
68
+                if (isset($post_data[$key.'group_number'][$i])) {
69
+                    $product_quote->group_id = $groups[$post_data[$key.'group_number'][$i]];
70 70
                 }
71 71
                 if (trim($product_quote->product_id) != '' && trim($product_quote->name) != '' && trim($product_quote->product_unit_price) != '') {
72 72
                     $product_quote->number = ++$j;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
                     $product_quote->currency_id = $parent->currency_id;
76 76
                     $product_quote->parent_type = $parent->object_name;
77 77
                     $product_quote->save();
78
-                    $_POST[$key . 'id'][$i] = $product_quote->id;
78
+                    $_POST[$key.'id'][$i] = $product_quote->id;
79 79
                 }
80 80
             }
81 81
         }
Please login to merge, or discard this patch.
modules/Reminders/Reminder.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
                             $timeRemind = $popupReminder->timer_popup;
323 323
                             $timeStart -= $timeRemind;
324 324
 
325
-                            $url = 'index.php?action=DetailView&module=' . $popupReminder->related_event_module . '&record=' . $popupReminder->related_event_module_id;
325
+                            $url = 'index.php?action=DetailView&module='.$popupReminder->related_event_module.'&record='.$popupReminder->related_event_module_id;
326 326
                             $instructions = $app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING_MSG'];
327 327
 
328 328
                             if ($popupReminder->related_event_module == 'Meetings') {
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
 
343 343
                             $relatedToMeeting = $alert->getRelatedName($popupReminder->related_event_module, $popupReminder->related_event_module_id);
344 344
 
345
-                            $description = empty($desc1) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'] . $desc1 . "\n";
346
-                            $description = $description . "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'] . (isset($relatedEvent->status) ? $relatedEvent->status : '') . "\n" . $app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO'] . $relatedToMeeting;
345
+                            $description = empty($desc1) ? '' : $app_strings['MSG_JS_ALERT_MTG_REMINDER_AGENDA'].$desc1."\n";
346
+                            $description = $description."\n".$app_strings['MSG_JS_ALERT_MTG_REMINDER_STATUS'].(isset($relatedEvent->status) ? $relatedEvent->status : '')."\n".$app_strings['MSG_JS_ALERT_MTG_REMINDER_RELATED_TO'].$relatedToMeeting;
347 347
 
348 348
 
349 349
                             if (isset($relatedEvent->date_start)) {
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
 
362 362
                             // standard functionality
363 363
                             $alert->addAlert($app_strings['MSG_JS_ALERT_MTG_REMINDER_MEETING'], $meetingName,
364
-                                $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'] . $time,
365
-                                $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'] . $location .
366
-                                $description .
364
+                                $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'].$time,
365
+                                $app_strings['MSG_JS_ALERT_MTG_REMINDER_LOC'].$location.
366
+                                $description.
367 367
                                 $instructions,
368 368
                                 $timeStart - strtotime($alertDateTimeNow),
369 369
                                 $url
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
     private function upgradeEventPersonQuery(SugarBean $event, $person_table)
428 428
     {
429
-        $eventIdField = strtolower($event->object_name) . '_id';
429
+        $eventIdField = strtolower($event->object_name).'_id';
430 430
         $query = "
431 431
 			SELECT * FROM {$event->table_name}_{$person_table}
432 432
 			WHERE
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
     {
441 441
         $eventIdField = array_search($event->table_name, $event->relationship_fields);
442 442
         if (!$eventIdField) {
443
-            $eventIdField = strtolower($event->object_name . '_id');
443
+            $eventIdField = strtolower($event->object_name.'_id');
444 444
         }
445
-        $personIdField = strtolower($person->object_name) . '_id';
445
+        $personIdField = strtolower($person->object_name).'_id';
446 446
         $query = "
447 447
 			SELECT * FROM {$event->table_name}_{$person->table_name}
448 448
 			WHERE
Please login to merge, or discard this patch.
modules/AOR_Reports/controller.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
     protected function action_getModuleFields()
32 32
     {
33 33
         if (!empty($_REQUEST['aor_module']) && $_REQUEST['aor_module'] != '') {
34
-            if(isset($_REQUEST['rel_field']) &&  $_REQUEST['rel_field'] != ''){
35
-                $module = getRelatedModule($_REQUEST['aor_module'],$_REQUEST['rel_field']);
34
+            if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') {
35
+                $module = getRelatedModule($_REQUEST['aor_module'], $_REQUEST['rel_field']);
36 36
             } else {
37 37
                 $module = $_REQUEST['aor_module'];
38 38
             }
39 39
             $val = !empty($_REQUEST['aor_value']) ? $_REQUEST['aor_value'] : '';
40
-            echo getModuleFields($module,$_REQUEST['view'],$val);
40
+            echo getModuleFields($module, $_REQUEST['view'], $val);
41 41
         }
42 42
         die;
43 43
 
44 44
     }
45
-    function action_getVarDefs(){
46
-        if($_REQUEST['aor_module']){
45
+    function action_getVarDefs() {
46
+        if ($_REQUEST['aor_module']) {
47 47
             $bean = BeanFactory::getBean($_REQUEST['aor_module']);
48 48
             echo json_encode((array)$bean->field_defs[$_REQUEST['aor_request']]);
49 49
             die();
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
         die;
70 70
     }
71 71
 
72
-    protected function action_changeReportPage(){
72
+    protected function action_changeReportPage() {
73 73
         $tableId = !empty($_REQUEST['table_id']) ? $_REQUEST['table_id'] : '';
74 74
         $group = !empty($_REQUEST['group']) ? $_REQUEST['group'] : '';
75 75
         $offset = !empty($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
76
-        if(!empty($this->bean->id)){
76
+        if (!empty($this->bean->id)) {
77 77
             $this->bean->user_parameters = requestToUserParameters();
78 78
             //echo $this->bean->build_report_html($offset, true,$group,$tableId);
79 79
             echo $this->bean->build_group_report($offset, true);
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
         die();
83 83
     }
84 84
 
85
-    protected function action_getParametersForReport(){
86
-        if(empty($_REQUEST['record'])){
85
+    protected function action_getParametersForReport() {
86
+        if (empty($_REQUEST['record'])) {
87 87
             echo json_encode(array());
88 88
             return;
89 89
         }
90
-        $report = BeanFactory::getBean('AOR_Reports',$_REQUEST['record']);
91
-        if(!$report){
90
+        $report = BeanFactory::getBean('AOR_Reports', $_REQUEST['record']);
91
+        if (!$report) {
92 92
             echo json_encode(array());
93 93
             return;
94 94
         }
95
-        if(empty($report->id)) {
95
+        if (empty($report->id)) {
96 96
             echo json_encode(array());
97 97
             return;
98 98
         }
@@ -100,24 +100,24 @@  discard block
 block discarded – undo
100 100
         echo json_encode($conditions);
101 101
     }
102 102
 
103
-    protected function action_getChartsForReport(){
104
-        if(empty($_REQUEST['record'])){
103
+    protected function action_getChartsForReport() {
104
+        if (empty($_REQUEST['record'])) {
105 105
             echo json_encode(array());
106 106
             return;
107 107
         }
108
-        $report = BeanFactory::getBean('AOR_Reports',$_REQUEST['record']);
109
-        if(!$report){
108
+        $report = BeanFactory::getBean('AOR_Reports', $_REQUEST['record']);
109
+        if (!$report) {
110 110
             echo json_encode(array());
111 111
             return;
112 112
         }
113 113
         $charts = array();
114
-        foreach($report->get_linked_beans('aor_charts','AOR_Charts') as $chart){
114
+        foreach ($report->get_linked_beans('aor_charts', 'AOR_Charts') as $chart) {
115 115
             $charts[$chart->id] = $chart->name;
116 116
         }
117 117
         echo json_encode($charts);
118 118
     }
119 119
 
120
-    protected function action_addToProspectList(){
120
+    protected function action_addToProspectList() {
121 121
         global $beanList;
122 122
 
123 123
         require_once('modules/Relationships/Relationship.php');
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
             $result = $this->bean->db->query($sql);
136 136
             $beans = array();
137 137
             while ($row = $this->bean->db->fetchByAssoc($result)) {
138
-                if (isset($row[$module->table_name.'_id'])){
138
+                if (isset($row[$module->table_name.'_id'])) {
139 139
                     $beans[] = $row[$module->table_name.'_id'];
140 140
                 }
141 141
             }
142
-            if(!empty($beans)){
143
-                foreach($prospectList->field_defs as $field=>$def){
144
-                    if($def['type'] == 'link' && !empty($def['relationship']) && $def['relationship'] == $key){
142
+            if (!empty($beans)) {
143
+                foreach ($prospectList->field_defs as $field=>$def) {
144
+                    if ($def['type'] == 'link' && !empty($def['relationship']) && $def['relationship'] == $key) {
145 145
                         $prospectList->load_relationship($field);
146 146
                         $prospectList->$field->add($beans);
147 147
                     }
@@ -170,41 +170,41 @@  discard block
 block discarded – undo
170 170
         error_reporting(0);
171 171
         require_once('modules/AOS_PDF_Templates/PDF_Lib/mpdf.php');
172 172
 
173
-        $d_image = explode('?',SugarThemeRegistry::current()->getImageURL('company_logo.png'));
173
+        $d_image = explode('?', SugarThemeRegistry::current()->getImageURL('company_logo.png'));
174 174
         $graphs = $_POST["graphsForPDF"];
175 175
         $graphHtml = "<div class='reportGraphs' style='width:100%; text-align:center;'>";
176 176
 
177 177
         $chartsPerRow = $this->bean->graphs_per_row;
178 178
         $countOfCharts = count($graphs);
179
-        if($countOfCharts > 0)
179
+        if ($countOfCharts > 0)
180 180
         {
181
-            $width = ((int)100/$chartsPerRow);
181
+            $width = ((int)100 / $chartsPerRow);
182 182
 
183 183
             $modulusRemainder = $countOfCharts % $chartsPerRow;
184 184
 
185
-            if($modulusRemainder > 0)
185
+            if ($modulusRemainder > 0)
186 186
             {
187
-                $modulusWidth = ((int)100/$modulusRemainder);
187
+                $modulusWidth = ((int)100 / $modulusRemainder);
188 188
                 $itemsWithModulus = $countOfCharts - $modulusRemainder;
189 189
             }
190 190
 
191 191
 
192
-            for($x =0; $x < $countOfCharts; $x++)
192
+            for ($x = 0; $x < $countOfCharts; $x++)
193 193
             {
194
-                if(is_null($itemsWithModulus) ||  $x < $itemsWithModulus)
195
-                    $graphHtml.="<img src='.$graphs[$x].' style='width:$width%;' />";
194
+                if (is_null($itemsWithModulus) || $x < $itemsWithModulus)
195
+                    $graphHtml .= "<img src='.$graphs[$x].' style='width:$width%;' />";
196 196
                 else
197
-                    $graphHtml.="<img src='.$graphs[$x].' style='width:$modulusWidth%;' />";
197
+                    $graphHtml .= "<img src='.$graphs[$x].' style='width:$modulusWidth%;' />";
198 198
             }
199 199
 
200 200
 /*            foreach($graphs as $g)
201 201
             {
202 202
                 $graphHtml.="<img src='.$g.' style='width:$width%;' />";
203 203
             }*/
204
-            $graphHtml.="</div>";
204
+            $graphHtml .= "</div>";
205 205
         }
206 206
 
207
-        $head =  '<table style="width: 100%; font-family: Arial; text-align: center;" border="0" cellpadding="2" cellspacing="2">
207
+        $head = '<table style="width: 100%; font-family: Arial; text-align: center;" border="0" cellpadding="2" cellspacing="2">
208 208
                 <tbody style="text-align: left;">
209 209
                 <tr style="text-align: left;">
210 210
                 <td style="text-align: left;">
@@ -229,25 +229,25 @@  discard block
 block discarded – undo
229 229
 
230 230
         $this->bean->user_parameters = requestToUserParameters();
231 231
 
232
-        $printable = $this->bean->build_group_report(-1,false);
233
-        $stylesheet = file_get_contents(SugarThemeRegistry::current()->getCSSURL('style.css',false));
232
+        $printable = $this->bean->build_group_report(-1, false);
233
+        $stylesheet = file_get_contents(SugarThemeRegistry::current()->getCSSURL('style.css', false));
234 234
         ob_clean();
235
-        try{
236
-            $pdf=new mPDF('en','A4','','DejaVuSansCondensed');
235
+        try {
236
+            $pdf = new mPDF('en', 'A4', '', 'DejaVuSansCondensed');
237 237
             $pdf->setAutoFont();
238
-            $pdf->WriteHTML($stylesheet,1);
239
-            $pdf->WriteHTML($head,2);
240
-            $pdf->WriteHTML($printable,3);
238
+            $pdf->WriteHTML($stylesheet, 1);
239
+            $pdf->WriteHTML($head, 2);
240
+            $pdf->WriteHTML($printable, 3);
241 241
             $pdf->Output($this->bean->name.'.pdf', "D");
242 242
 
243
-        }catch(mPDF_exception $e){
243
+        }catch (mPDF_exception $e) {
244 244
             echo $e;
245 245
         }
246 246
 
247 247
         die;
248 248
     }
249 249
 
250
-    protected function action_getModuleFunctionField(){
250
+    protected function action_getModuleFunctionField() {
251 251
         global $app_list_strings;
252 252
 
253 253
         $view = $_REQUEST['view'];
@@ -256,31 +256,31 @@  discard block
 block discarded – undo
256 256
         $fieldname = $_REQUEST['aor_fieldname'];
257 257
         $aor_field = $_REQUEST['aor_newfieldname'];
258 258
 
259
-        if($view == 'EditView'){
260
-            echo "<select type='text' style='width:100px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aor_function_list'], $value) ."</select>";
261
-        }else{
259
+        if ($view == 'EditView') {
260
+            echo "<select type='text' style='width:100px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aor_function_list'], $value)."</select>";
261
+        } else {
262 262
             echo $app_list_strings['aor_function_list'][$value];
263 263
         }
264 264
         die;
265 265
     }
266 266
 
267 267
 
268
-    protected function action_getModuleOperatorField(){
268
+    protected function action_getModuleOperatorField() {
269 269
 
270 270
         global $app_list_strings, $beanFiles, $beanList;
271 271
 
272
-        if(isset($_REQUEST['rel_field']) &&  $_REQUEST['rel_field'] != ''){
273
-            $module = getRelatedModule($_REQUEST['aor_module'],$_REQUEST['rel_field']);
272
+        if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') {
273
+            $module = getRelatedModule($_REQUEST['aor_module'], $_REQUEST['rel_field']);
274 274
         } else {
275 275
             $module = $_REQUEST['aor_module'];
276 276
         }
277 277
         $fieldname = $_REQUEST['aor_fieldname'];
278 278
         $aor_field = $_REQUEST['aor_newfieldname'];
279 279
 
280
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
281
-        else $view= 'EditView';
280
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
281
+        else $view = 'EditView';
282 282
 
283
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
283
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
284 284
         else $value = '';
285 285
 
286 286
 
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
         $focus = new $beanList[$module];
289 289
         $vardef = $focus->getFieldDefinition($fieldname);
290 290
 
291
-        switch($vardef['type']) {
291
+        switch ($vardef['type']) {
292 292
             case 'double':
293 293
             case 'decimal':
294 294
             case 'float':
295 295
             case 'currency':
296
-                $valid_opp = array('Equal_To','Not_Equal_To','Greater_Than','Less_Than','Greater_Than_or_Equal_To','Less_Than_or_Equal_To');
296
+                $valid_opp = array('Equal_To', 'Not_Equal_To', 'Greater_Than', 'Less_Than', 'Greater_Than_or_Equal_To', 'Less_Than_or_Equal_To');
297 297
                 break;
298 298
             case 'uint':
299 299
             case 'ulong':
@@ -301,24 +301,24 @@  discard block
 block discarded – undo
301 301
             case 'short':
302 302
             case 'tinyint':
303 303
             case 'int':
304
-                $valid_opp = array('Equal_To','Not_Equal_To','Greater_Than','Less_Than','Greater_Than_or_Equal_To','Less_Than_or_Equal_To');
304
+                $valid_opp = array('Equal_To', 'Not_Equal_To', 'Greater_Than', 'Less_Than', 'Greater_Than_or_Equal_To', 'Less_Than_or_Equal_To');
305 305
                 break;
306 306
             case 'date':
307 307
             case 'datetime':
308 308
             case 'datetimecombo':
309
-                $valid_opp = array('Equal_To','Not_Equal_To','Greater_Than','Less_Than','Greater_Than_or_Equal_To','Less_Than_or_Equal_To');
309
+                $valid_opp = array('Equal_To', 'Not_Equal_To', 'Greater_Than', 'Less_Than', 'Greater_Than_or_Equal_To', 'Less_Than_or_Equal_To');
310 310
                 break;
311 311
             case 'enum':
312 312
             case 'multienum':
313
-                $valid_opp = array('Equal_To','Not_Equal_To');
313
+                $valid_opp = array('Equal_To', 'Not_Equal_To');
314 314
                 break;
315 315
             default:
316
-                $valid_opp = array('Equal_To','Not_Equal_To','Contains', 'Starts_With', 'Ends_With',);
316
+                $valid_opp = array('Equal_To', 'Not_Equal_To', 'Contains', 'Starts_With', 'Ends_With',);
317 317
                 break;
318 318
         }
319 319
 
320
-        foreach($app_list_strings['aor_operator_list'] as $key => $keyValue){
321
-            if(!in_array($key, $valid_opp)){
320
+        foreach ($app_list_strings['aor_operator_list'] as $key => $keyValue) {
321
+            if (!in_array($key, $valid_opp)) {
322 322
                 unset($app_list_strings['aor_operator_list'][$key]);
323 323
             }
324 324
         }
@@ -326,31 +326,31 @@  discard block
 block discarded – undo
326 326
 
327 327
 
328 328
         $app_list_strings['aor_operator_list'];
329
-        if($view == 'EditView'){
330
-            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aor_operator_list'], $value) ."</select>";
331
-        }else{
329
+        if ($view == 'EditView') {
330
+            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aor_operator_list'], $value)."</select>";
331
+        } else {
332 332
             echo $app_list_strings['aor_operator_list'][$value];
333 333
         }
334 334
         die;
335 335
 
336 336
     }
337 337
 
338
-    protected function action_getFieldTypeOptions(){
338
+    protected function action_getFieldTypeOptions() {
339 339
 
340 340
         global $app_list_strings, $beanFiles, $beanList;
341 341
 
342
-        if(isset($_REQUEST['rel_field']) &&  $_REQUEST['rel_field'] != ''){
343
-            $module = getRelatedModule($_REQUEST['aor_module'],$_REQUEST['rel_field']);
342
+        if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') {
343
+            $module = getRelatedModule($_REQUEST['aor_module'], $_REQUEST['rel_field']);
344 344
         } else {
345 345
             $module = $_REQUEST['aor_module'];
346 346
         }
347 347
         $fieldname = $_REQUEST['aor_fieldname'];
348 348
         $aor_field = $_REQUEST['aor_newfieldname'];
349 349
 
350
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
351
-        else $view= 'EditView';
350
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
351
+        else $view = 'EditView';
352 352
 
353
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
353
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
354 354
         else $value = '';
355 355
 
356 356
 
@@ -358,12 +358,12 @@  discard block
 block discarded – undo
358 358
         $focus = new $beanList[$module];
359 359
         $vardef = $focus->getFieldDefinition($fieldname);
360 360
 
361
-        switch($vardef['type']) {
361
+        switch ($vardef['type']) {
362 362
             case 'double':
363 363
             case 'decimal':
364 364
             case 'float':
365 365
             case 'currency':
366
-                $valid_opp = array('Value','Field');
366
+                $valid_opp = array('Value', 'Field');
367 367
                 break;
368 368
             case 'uint':
369 369
             case 'ulong':
@@ -371,50 +371,50 @@  discard block
 block discarded – undo
371 371
             case 'short':
372 372
             case 'tinyint':
373 373
             case 'int':
374
-                $valid_opp = array('Value','Field');
374
+                $valid_opp = array('Value', 'Field');
375 375
                 break;
376 376
             case 'date':
377 377
             case 'datetime':
378 378
             case 'datetimecombo':
379
-                $valid_opp = array('Value','Field', 'Date', 'Period');
379
+                $valid_opp = array('Value', 'Field', 'Date', 'Period');
380 380
                 break;
381 381
             case 'enum':
382 382
             case 'dynamicenum':
383 383
             case 'multienum':
384
-                $valid_opp = array('Value','Field', 'Multi');
384
+                $valid_opp = array('Value', 'Field', 'Multi');
385 385
                 break;
386 386
             default:
387 387
                 // Added to compare fields like assinged to with the current user
388
-                if( (isset($vardef['module']) && $vardef['module'] == "Users") || $vardef['name'] = 'id') {
389
-                    $valid_opp = array('Value','Field', 'CurrentUserID');
388
+                if ((isset($vardef['module']) && $vardef['module'] == "Users") || $vardef['name'] = 'id') {
389
+                    $valid_opp = array('Value', 'Field', 'CurrentUserID');
390 390
                 } else {
391
-                    $valid_opp = array('Value','Field');
391
+                    $valid_opp = array('Value', 'Field');
392 392
                 }
393 393
 
394 394
                 break;
395 395
         }
396 396
 
397
-        foreach($app_list_strings['aor_condition_type_list'] as $key => $keyValue){
398
-            if(!in_array($key, $valid_opp)){
397
+        foreach ($app_list_strings['aor_condition_type_list'] as $key => $keyValue) {
398
+            if (!in_array($key, $valid_opp)) {
399 399
                 unset($app_list_strings['aor_condition_type_list'][$key]);
400 400
             }
401 401
         }
402 402
 
403
-        if($view == 'EditView'){
404
-            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aor_condition_type_list'], $value) ."</select>";
405
-        }else{
403
+        if ($view == 'EditView') {
404
+            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aor_condition_type_list'], $value)."</select>";
405
+        } else {
406 406
             echo $app_list_strings['aor_condition_type_list'][$value];
407 407
         }
408 408
         die;
409 409
 
410 410
     }
411 411
 
412
-    protected function action_getActionFieldTypeOptions(){
412
+    protected function action_getActionFieldTypeOptions() {
413 413
 
414 414
         global $app_list_strings, $beanFiles, $beanList;
415 415
 
416
-        if(isset($_REQUEST['rel_field']) &&  $_REQUEST['rel_field'] != ''){
417
-            $module = getRelatedModule($_REQUEST['aor_module'],$_REQUEST['rel_field']);
416
+        if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') {
417
+            $module = getRelatedModule($_REQUEST['aor_module'], $_REQUEST['rel_field']);
418 418
         } else {
419 419
             $module = $_REQUEST['aor_module'];
420 420
         }
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
         $fieldname = $_REQUEST['aor_fieldname'];
423 423
         $aor_field = $_REQUEST['aor_newfieldname'];
424 424
 
425
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
426
-        else $view= 'EditView';
425
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
426
+        else $view = 'EditView';
427 427
 
428
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
428
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
429 429
         else $value = '';
430 430
 
431 431
 
@@ -433,12 +433,12 @@  discard block
 block discarded – undo
433 433
         $focus = new $beanList[$module];
434 434
         $vardef = $focus->getFieldDefinition($fieldname);
435 435
 
436
-        switch($vardef['type']) {
436
+        switch ($vardef['type']) {
437 437
             case 'double':
438 438
             case 'decimal':
439 439
             case 'float':
440 440
             case 'currency':
441
-                $valid_opp = array('Value','Field');
441
+                $valid_opp = array('Value', 'Field');
442 442
                 break;
443 443
             case 'uint':
444 444
             case 'ulong':
@@ -446,35 +446,35 @@  discard block
 block discarded – undo
446 446
             case 'short':
447 447
             case 'tinyint':
448 448
             case 'int':
449
-                $valid_opp = array('Value','Field');
449
+                $valid_opp = array('Value', 'Field');
450 450
                 break;
451 451
             case 'date':
452 452
             case 'datetime':
453 453
             case 'datetimecombo':
454
-                $valid_opp = array('Value','Field', 'Date');
454
+                $valid_opp = array('Value', 'Field', 'Date');
455 455
                 break;
456 456
             case 'enum':
457 457
             case 'multienum':
458
-                $valid_opp = array('Value','Field');
458
+                $valid_opp = array('Value', 'Field');
459 459
                 break;
460 460
             case 'relate':
461
-                $valid_opp = array('Value','Field');
462
-                if($vardef['module'] == 'Users') $valid_opp = array('Value','Field','Round_Robin','Least_Busy','Random');
461
+                $valid_opp = array('Value', 'Field');
462
+                if ($vardef['module'] == 'Users') $valid_opp = array('Value', 'Field', 'Round_Robin', 'Least_Busy', 'Random');
463 463
                 break;
464 464
             default:
465
-                $valid_opp = array('Value','Field');
465
+                $valid_opp = array('Value', 'Field');
466 466
                 break;
467 467
         }
468 468
 
469
-        foreach($app_list_strings['aor_action_type_list'] as $key => $keyValue){
470
-            if(!in_array($key, $valid_opp)){
469
+        foreach ($app_list_strings['aor_action_type_list'] as $key => $keyValue) {
470
+            if (!in_array($key, $valid_opp)) {
471 471
                 unset($app_list_strings['aor_action_type_list'][$key]);
472 472
             }
473 473
         }
474 474
 
475
-        if($view == 'EditView'){
476
-            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aor_action_type_list'], $value) ."</select>";
477
-        }else{
475
+        if ($view == 'EditView') {
476
+            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aor_action_type_list'], $value)."</select>";
477
+        } else {
478 478
             echo $app_list_strings['aor_action_type_list'][$value];
479 479
         }
480 480
         die;
@@ -483,8 +483,8 @@  discard block
 block discarded – undo
483 483
 
484 484
     protected function action_getModuleFieldType()
485 485
     {
486
-        if(isset($_REQUEST['rel_field']) &&  $_REQUEST['rel_field'] != ''){
487
-            $rel_module = getRelatedModule($_REQUEST['aor_module'],$_REQUEST['rel_field']);
486
+        if (isset($_REQUEST['rel_field']) && $_REQUEST['rel_field'] != '') {
487
+            $rel_module = getRelatedModule($_REQUEST['aor_module'], $_REQUEST['rel_field']);
488 488
         } else {
489 489
             $rel_module = $_REQUEST['aor_module'];
490 490
         }
@@ -493,18 +493,18 @@  discard block
 block discarded – undo
493 493
         $fieldname = $_REQUEST['aor_fieldname'];
494 494
         $aor_field = $_REQUEST['aor_newfieldname'];
495 495
 
496
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
497
-        else $view= 'EditView';
496
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
497
+        else $view = 'EditView';
498 498
 
499
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
499
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
500 500
         else $value = '';
501 501
 
502
-        switch($_REQUEST['aor_type']) {
502
+        switch ($_REQUEST['aor_type']) {
503 503
             case 'Field':
504
-                if(isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
505
-                if($view == 'EditView'){
506
-                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". getModuleFields($module, $view, $value) ."</select>";
507
-                }else{
504
+                if (isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
505
+                if ($view == 'EditView') {
506
+                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".getModuleFields($module, $view, $value)."</select>";
507
+                } else {
508 508
                     echo getModuleFields($module, $view, $value);
509 509
                 }
510 510
                 break;
@@ -512,13 +512,13 @@  discard block
 block discarded – undo
512 512
                 echo getDateField($module, $aor_field, $view, $value, false);
513 513
                 break;
514 514
             case 'Multi':
515
-                echo getModuleField($rel_module,$fieldname, $aor_field, $view, $value,'multienum');
515
+                echo getModuleField($rel_module, $fieldname, $aor_field, $view, $value, 'multienum');
516 516
                 break;
517 517
             case 'Period':
518
-                if($view == 'EditView'){
519
-                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". getDropdownList('date_time_period_list',$_REQUEST['aor_value']) ."</select>";
520
-                }else{
521
-                    echo getDropdownList('date_time_period_list',$_REQUEST['aor_value']);
518
+                if ($view == 'EditView') {
519
+                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".getDropdownList('date_time_period_list', $_REQUEST['aor_value'])."</select>";
520
+                } else {
521
+                    echo getDropdownList('date_time_period_list', $_REQUEST['aor_value']);
522 522
                 }
523 523
 
524 524
                 break;
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
                 break;
527 527
             case 'Value':
528 528
             default:
529
-                echo getModuleField($rel_module,$fieldname, $aor_field, $view, $value );
529
+                echo getModuleField($rel_module, $fieldname, $aor_field, $view, $value);
530 530
                 break;
531 531
         }
532 532
         die;
@@ -539,23 +539,23 @@  discard block
 block discarded – undo
539 539
         $fieldname = $_REQUEST['aor_fieldname'];
540 540
         $aor_field = $_REQUEST['aor_newfieldname'];
541 541
 
542
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
543
-        else $view= 'EditView';
542
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
543
+        else $view = 'EditView';
544 544
 
545
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
545
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
546 546
         else $value = '';
547 547
 
548
-        switch($_REQUEST['aor_type']) {
548
+        switch ($_REQUEST['aor_type']) {
549 549
             case 'Field':
550
-                if(isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
551
-                if($view == 'EditView'){
552
-                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". getModuleFields($module, $view, $value) ."</select>";
553
-                }else{
550
+                if (isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
551
+                if ($view == 'EditView') {
552
+                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".getModuleFields($module, $view, $value)."</select>";
553
+                } else {
554 554
                     echo getModuleFields($module, $view, $value);
555 555
                 }
556 556
                 break;
557 557
             case 'Date':
558
-                if(isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
558
+                if (isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
559 559
                 echo getDateField($module, $aor_field, $view, $value);
560 560
                 break;
561 561
             Case 'Round_Robin';
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
                 break;
566 566
             case 'Value':
567 567
             default:
568
-                echo getModuleField($module,$fieldname, $aor_field, $view, $value );
568
+                echo getModuleField($module, $fieldname, $aor_field, $view, $value);
569 569
                 break;
570 570
         }
571 571
         die;
@@ -574,13 +574,13 @@  discard block
 block discarded – undo
574 574
 
575 575
     protected function action_getModuleField()
576 576
     {
577
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
578
-        else $view= 'EditView';
577
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
578
+        else $view = 'EditView';
579 579
 
580
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
580
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
581 581
         else $value = '';
582 582
 
583
-        echo getModuleField($_REQUEST['aor_module'],$_REQUEST['aor_fieldname'], $_REQUEST['aor_newfieldname'], $view, $value );
583
+        echo getModuleField($_REQUEST['aor_module'], $_REQUEST['aor_fieldname'], $_REQUEST['aor_newfieldname'], $view, $value);
584 584
         die;
585 585
     }
586 586
 
@@ -590,31 +590,31 @@  discard block
 block discarded – undo
590 590
         $fieldname = $_REQUEST['aor_fieldname'];
591 591
         $aor_field = $_REQUEST['aor_newfieldname'];
592 592
 
593
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
594
-        else $view= 'EditView';
593
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
594
+        else $view = 'EditView';
595 595
 
596
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
596
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
597 597
         else $value = '';
598 598
 
599
-        switch($_REQUEST['aor_type']) {
599
+        switch ($_REQUEST['aor_type']) {
600 600
             case 'Field':
601
-                if(isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
602
-                if($view == 'EditView'){
603
-                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". getModuleFields($module, $view, $value) ."</select>";
604
-                }else{
601
+                if (isset($_REQUEST['alt_module']) && $_REQUEST['alt_module'] != '') $module = $_REQUEST['alt_module'];
602
+                if ($view == 'EditView') {
603
+                    echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".getModuleFields($module, $view, $value)."</select>";
604
+                } else {
605 605
                     echo getModuleFields($module, $view, $value);
606 606
                 }
607 607
                 break;
608 608
             case 'Value':
609 609
             default:
610
-                echo getModuleField($module,$fieldname, $aor_field, $view, $value );
610
+                echo getModuleField($module, $fieldname, $aor_field, $view, $value);
611 611
                 break;
612 612
         }
613 613
         die;
614 614
 
615 615
     }
616 616
 
617
-    protected function action_getRelActionFieldTypeOptions(){
617
+    protected function action_getRelActionFieldTypeOptions() {
618 618
 
619 619
         global $app_list_strings, $beanFiles, $beanList;
620 620
 
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
         $fieldname = $_REQUEST['aor_fieldname'];
624 624
         $aor_field = $_REQUEST['aor_newfieldname'];
625 625
 
626
-        if(isset($_REQUEST['view'])) $view = $_REQUEST['view'];
627
-        else $view= 'EditView';
626
+        if (isset($_REQUEST['view'])) $view = $_REQUEST['view'];
627
+        else $view = 'EditView';
628 628
 
629
-        if(isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
629
+        if (isset($_REQUEST['aor_value'])) $value = $_REQUEST['aor_value'];
630 630
         else $value = '';
631 631
 
632 632
 
@@ -643,15 +643,15 @@  discard block
 block discarded – undo
643 643
         }*/
644 644
         $valid_opp = array('Value');
645 645
 
646
-        foreach($app_list_strings['aor_rel_action_type_list'] as $key => $keyValue){
647
-            if(!in_array($key, $valid_opp)){
646
+        foreach ($app_list_strings['aor_rel_action_type_list'] as $key => $keyValue) {
647
+            if (!in_array($key, $valid_opp)) {
648 648
                 unset($app_list_strings['aor_rel_action_type_list'][$key]);
649 649
             }
650 650
         }
651 651
 
652
-        if($view == 'EditView'){
653
-            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aor_rel_action_type_list'], $value) ."</select>";
654
-        }else{
652
+        if ($view == 'EditView') {
653
+            echo "<select type='text' style='width:178px;' name='$aor_field' id='$aor_field' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aor_rel_action_type_list'], $value)."</select>";
654
+        } else {
655 655
             echo $app_list_strings['aor_rel_action_type_list'][$value];
656 656
         }
657 657
         die;
Please login to merge, or discard this patch.
modules/AOR_Reports/AOR_Report.php 1 patch
Spacing   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	var $object_name = 'AOR_Report';
29 29
 	var $table_name = 'aor_reports';
30 30
 	var $importable = true;
31
-	var $disable_row_level_security = true ;
31
+	var $disable_row_level_security = true;
32 32
 
33 33
 	var $id;
34 34
 	var $name;
@@ -47,25 +47,25 @@  discard block
 block discarded – undo
47 47
 	var $assigned_user_link;
48 48
 	var $report_module;
49 49
 
50
-	function AOR_Report(){
50
+	function AOR_Report() {
51 51
 		parent::Basic();
52 52
         $this->load_report_beans();
53 53
         require_once('modules/AOW_WorkFlow/aow_utils.php');
54 54
 	}
55 55
 
56
-	function bean_implements($interface){
57
-		switch($interface){
56
+	function bean_implements($interface) {
57
+		switch ($interface) {
58 58
 			case 'ACL': return true;
59 59
 		}
60 60
 		return false;
61 61
 	}
62 62
 
63
-    function save($check_notify = FALSE){
63
+    function save($check_notify = FALSE) {
64 64
 
65 65
         // TODO: process of saveing the fields and conditions is too long so we will have to make some optimization on save_lines functions
66 66
         set_time_limit(3600);
67 67
 
68
-        if (empty($this->id)){
68
+        if (empty($this->id)) {
69 69
             unset($_POST['aor_conditions_id']);
70 70
             unset($_POST['aor_fields_id']);
71 71
         }
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
         $chart->save_lines($_POST, $this, 'aor_chart_');
86 86
     }
87 87
 
88
-    function load_report_beans(){
88
+    function load_report_beans() {
89 89
         global $beanList, $app_list_strings;
90 90
 
91 91
         $app_list_strings['aor_moduleList'] = $app_list_strings['moduleList'];
92 92
 
93
-        foreach($app_list_strings['aor_moduleList'] as $mkey => $mvalue){
94
-            if(!isset($beanList[$mkey]) || str_begin($mkey, 'AOR_') || str_begin($mkey, 'AOW_')){
93
+        foreach ($app_list_strings['aor_moduleList'] as $mkey => $mvalue) {
94
+            if (!isset($beanList[$mkey]) || str_begin($mkey, 'AOR_') || str_begin($mkey, 'AOW_')) {
95 95
                 unset($app_list_strings['aor_moduleList'][$mkey]);
96 96
             }
97 97
         }
@@ -102,12 +102,12 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
 
105
-    function getReportFields(){
105
+    function getReportFields() {
106 106
         $fields = array();
107
-        foreach($this->get_linked_beans('aor_fields','AOR_Fields') as $field){
107
+        foreach ($this->get_linked_beans('aor_fields', 'AOR_Fields') as $field) {
108 108
             $fields[] = $field;
109 109
         }
110
-        usort($fields,function($a,$b){
110
+        usort($fields, function($a, $b) {
111 111
             return $a->field_order - $b->field_order;
112 112
         });
113 113
         return $fields;
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
     const CHART_TYPE_RGRAPH = 'rgraph';
119 119
 
120 120
 
121
-    function build_report_chart($chartIds = null, $chartType = self::CHART_TYPE_PCHART){
121
+    function build_report_chart($chartIds = null, $chartType = self::CHART_TYPE_PCHART) {
122 122
         global $beanList;
123
-        $linkedCharts = $this->get_linked_beans('aor_charts','AOR_Charts');
124
-	if(!$linkedCharts){
123
+        $linkedCharts = $this->get_linked_beans('aor_charts', 'AOR_Charts');
124
+	if (!$linkedCharts) {
125 125
             //No charts to display
126 126
             return '';
127 127
         }
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
 
146 146
             $field_module = $this->report_module;
147 147
             $field_alias = $field_bean->table_name;
148
-            if($path[0] != $this->report_module){
149
-                foreach($path as $rel){
150
-                    if(empty($rel)){
148
+            if ($path[0] != $this->report_module) {
149
+                foreach ($path as $rel) {
150
+                    if (empty($rel)) {
151 151
                         continue;
152 152
                     }
153
-                    $field_module = getRelatedModule($field_module,$rel);
154
-                    $field_alias = $field_alias . ':'.$rel;
153
+                    $field_module = getRelatedModule($field_module, $rel);
154
+                    $field_alias = $field_alias.':'.$rel;
155 155
                 }
156 156
             }
157
-            $label = str_replace(' ','_',$field->label).$i;
157
+            $label = str_replace(' ', '_', $field->label).$i;
158 158
             $fields[$label]['field'] = $field->field;
159 159
             $fields[$label]['label'] = $field->label;
160 160
             $fields[$label]['display'] = $field->display;
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 
170 170
             // get the main group
171 171
 
172
-            if($field->group_display) {
172
+            if ($field->group_display) {
173 173
 
174 174
                 // if we have a main group already thats wrong cause only one main grouping field possible
175
-                if(!is_null($mainGroupField)) {
175
+                if (!is_null($mainGroupField)) {
176 176
                     $GLOBALS['log']->fatal('main group already found');
177 177
                 }
178 178
 
@@ -187,18 +187,18 @@  discard block
 block discarded – undo
187 187
         $query = $this->build_report_query();
188 188
         $result = $this->db->query($query);
189 189
         $data = array();
190
-        while($row = $this->db->fetchByAssoc($result, false))
190
+        while ($row = $this->db->fetchByAssoc($result, false))
191 191
         {
192
-            foreach($fields as $name => $att){
192
+            foreach ($fields as $name => $att) {
193 193
 
194 194
                 $currency_id = isset($row[$att['alias'].'_currency_id']) ? $row[$att['alias'].'_currency_id'] : '';
195 195
 
196
-                switch ($att['function']){
196
+                switch ($att['function']) {
197 197
                     case 'COUNT':
198 198
                         break;
199 199
                     default:
200
-                        if(!is_numeric($row[$name])) {
201
-                            $row[$name] = trim(strip_tags(getModuleField($att['module'], $att['field'], $att['field'], 'DetailView', $row[$name], '', $currency_id,$att['params'])));
200
+                        if (!is_numeric($row[$name])) {
201
+                            $row[$name] = trim(strip_tags(getModuleField($att['module'], $att['field'], $att['field'], 'DetailView', $row[$name], '', $currency_id, $att['params'])));
202 202
 
203 203
                         }
204 204
                         break;
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         }
209 209
         $fields = $this->getReportFields();
210 210
 
211
-        switch($chartType) {
211
+        switch ($chartType) {
212 212
             case self::CHART_TYPE_PCHART:
213 213
                 $html = '<script src="modules/AOR_Charts/lib/pChart/imagemap.js"></script>';
214 214
                 break;
@@ -216,17 +216,17 @@  discard block
 block discarded – undo
216 216
                 $html = '<script src="modules/AOR_Reports/js/Chart.js"></script>';
217 217
                 break;
218 218
             case self::CHART_TYPE_RGRAPH:
219
-                if($_REQUEST['module']!= 'Home')//Need the require_once for the rgraphincludes as they are only loaded when the home page is hit
219
+                if ($_REQUEST['module'] != 'Home')//Need the require_once for the rgraphincludes as they are only loaded when the home page is hit
220 220
                     require_once('include/SuiteGraphs/RGraphIncludes.php');
221 221
 
222 222
                 break;
223 223
         }
224 224
         $x = 0;
225
-        foreach($linkedCharts as $chart){
226
-            if($chartIds !== null && !in_array($chart->id,$chartIds)){
225
+        foreach ($linkedCharts as $chart) {
226
+            if ($chartIds !== null && !in_array($chart->id, $chartIds)) {
227 227
                 continue;
228 228
             }
229
-            $html .= $chart->buildChartHTML($data,$fields,$x, $chartType, $mainGroupField);
229
+            $html .= $chart->buildChartHTML($data, $fields, $x, $chartType, $mainGroupField);
230 230
             $x++;
231 231
         }
232 232
         return $html;
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
 
239 239
         $rows = $this->getGroupDisplayFieldByReportId($this->id, $level);
240 240
 
241
-        if(count($rows) > 1) {
242
-            $GLOBALS['log']->fatal('ambiguous group display for report ' . $this->id);
241
+        if (count($rows) > 1) {
242
+            $GLOBALS['log']->fatal('ambiguous group display for report '.$this->id);
243 243
         }
244
-        else if(count($rows) == 1){
244
+        else if (count($rows) == 1) {
245 245
             $rows[0]['module_path'] = unserialize(base64_decode($rows[0]['module_path']));
246
-            if(!$rows[0]['module_path'][0]) {
246
+            if (!$rows[0]['module_path'][0]) {
247 247
                 $module = new $beanList[$this->report_module]();
248 248
                 $rows[0]['field_id_name'] = $module->field_defs[$rows[0]['field']]['id_name'] ? $module->field_defs[$rows[0]['field']]['id_name'] : $module->field_defs[$rows[0]['field']]['name'];
249 249
                 $rows[0]['module_path'][0] = $module->table_name;
@@ -253,23 +253,23 @@  discard block
 block discarded – undo
253 253
             }
254 254
             $path[] = $rows[0];
255 255
 
256
-            if($level>10) {
256
+            if ($level > 10) {
257 257
                 $msg = 'Too many nested groups';
258 258
                 $GLOBALS['log']->fatal($msg);
259 259
                 return null;
260 260
             }
261 261
 
262
-            return $this->buildMultiGroupReport($offset, $links, $level+1, $path);
262
+            return $this->buildMultiGroupReport($offset, $links, $level + 1, $path);
263 263
         }
264
-        else if(!$rows) {
265
-            if($path) {
264
+        else if (!$rows) {
265
+            if ($path) {
266 266
                 $html = '';
267 267
                 foreach ($path as $pth) {
268 268
                     $_fieldIdName = $this->db->quoteIdentifier($pth['field_id_name']);
269
-                    $query = "SELECT $_fieldIdName FROM " . $this->db->quoteIdentifier($pth['module_path'][0]) . " GROUP BY $_fieldIdName;";
269
+                    $query = "SELECT $_fieldIdName FROM ".$this->db->quoteIdentifier($pth['module_path'][0])." GROUP BY $_fieldIdName;";
270 270
                     $values = $this->dbSelect($query);
271 271
 
272
-                    foreach($values as $value) {
272
+                    foreach ($values as $value) {
273 273
 
274 274
                         //$where = [ $this->db->quote($pth['module_path'][0]) . '.' . $_fieldIdName . ' = \'' . $this->db->quote($value[$pth['field_id_name']]) . '\'' ];
275 275
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
         // escape values for query
306 306
 
307 307
         $_id = $this->db->quote($reportId);
308
-        $_level = (int) $level;
308
+        $_level = (int)$level;
309 309
 
310 310
         // get results array
311 311
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         $results = $this->db->query($query);
321 321
 
322 322
         $rows = array();
323
-        while($row = $this->db->fetchByAssoc($results)) {
323
+        while ($row = $this->db->fetchByAssoc($results)) {
324 324
             $rows[] = $row;
325 325
         }
326 326
 
@@ -329,20 +329,20 @@  discard block
 block discarded – undo
329 329
 
330 330
     private function getMultiGroupFrameHTML($header, $body) {
331 331
         $html = '<div class="multi-group-list" style="border: 1px solid black; padding: 10px;">
332
-                    <h3>' . $header . '</h3>
333
-                    <div class="multi-group-list-inner">' . $body . '</div>
332
+                    <h3>' . $header.'</h3>
333
+                    <div class="multi-group-list-inner">' . $body.'</div>
334 334
                 </div>';
335 335
         return $html;
336 336
     }
337 337
 
338 338
     private function addDataIdValueToInnertext($html) {
339 339
         preg_match('/\sdata-id-value\s*=\s*"([^"]*)"/', $html, $match);
340
-        $html = preg_replace('/(>)([^<]*)(<\/\w+>$)/', '$1$2' . $match[1] . '$3', $html);
340
+        $html = preg_replace('/(>)([^<]*)(<\/\w+>$)/', '$1$2'.$match[1].'$3', $html);
341 341
         return $html;
342 342
     }
343 343
 
344 344
 
345
-    function build_group_report($offset = -1, $links = true, $extra = array()){
345
+    function build_group_report($offset = -1, $links = true, $extra = array()) {
346 346
         global $beanList;
347 347
 
348 348
         $html = '';
@@ -353,23 +353,23 @@  discard block
 block discarded – undo
353 353
         $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '".$this->id."' AND group_display = 1 AND deleted = 0 ORDER BY field_order ASC";
354 354
         $field_id = $this->db->getOne($sql);
355 355
 
356
-        if(!$field_id) {
357
-            $query_array['select'][] = $module->table_name . ".id AS '" . $module->table_name . "_id'";
356
+        if (!$field_id) {
357
+            $query_array['select'][] = $module->table_name.".id AS '".$module->table_name."_id'";
358 358
         }
359 359
 
360
-        if($field_id != ''){
360
+        if ($field_id != '') {
361 361
             $field = new AOR_Field();
362 362
             $field->retrieve($field_id);
363 363
 
364
-            $field_label = str_replace(' ','_',$field->label);
364
+            $field_label = str_replace(' ', '_', $field->label);
365 365
 
366 366
             $path = unserialize(base64_decode($field->module_path));
367 367
 
368 368
             $field_module = $module;
369 369
             $table_alias = $field_module->table_name;
370
-            if(!empty($path[0]) && $path[0] != $module->module_dir){
371
-                foreach($path as $rel){
372
-                    $new_field_module = new $beanList[getRelatedModule($field_module->module_dir,$rel)];
370
+            if (!empty($path[0]) && $path[0] != $module->module_dir) {
371
+                foreach ($path as $rel) {
372
+                    $new_field_module = new $beanList[getRelatedModule($field_module->module_dir, $rel)];
373 373
                     $oldAlias = $table_alias;
374 374
                     $table_alias = $table_alias.":".$rel;
375 375
 
@@ -383,71 +383,71 @@  discard block
 block discarded – undo
383 383
 
384 384
             $data = $field_module->field_defs[$field->field];
385 385
 
386
-            if($data['type'] == 'relate' && isset($data['id_name'])) {
386
+            if ($data['type'] == 'relate' && isset($data['id_name'])) {
387 387
                 $field->field = $data['id_name'];
388 388
             }
389 389
 
390
-            if($data['type'] == 'currency' && !stripos($field->field, '_USD') && isset($field_module->field_defs['currency_id'])) {
391
-                if((isset($field_module->field_defs['currency_id']['source']) && $field_module->field_defs['currency_id']['source'] == 'custom_fields')) {
390
+            if ($data['type'] == 'currency' && !stripos($field->field, '_USD') && isset($field_module->field_defs['currency_id'])) {
391
+                if ((isset($field_module->field_defs['currency_id']['source']) && $field_module->field_defs['currency_id']['source'] == 'custom_fields')) {
392 392
                     $query['select'][$table_alias.'_currency_id'] = $table_alias.'_cstm'.".currency_id AS '".$table_alias."_currency_id'";
393 393
                 } else {
394
-                    $query_array['select'][$table_alias . '_currency_id'] = $table_alias . ".currency_id AS '" . $table_alias . "_currency_id'";
394
+                    $query_array['select'][$table_alias.'_currency_id'] = $table_alias.".currency_id AS '".$table_alias."_currency_id'";
395 395
                 }
396 396
             }
397 397
 
398
-            if(  (isset($data['source']) && $data['source'] == 'custom_fields')) {
398
+            if ((isset($data['source']) && $data['source'] == 'custom_fields')) {
399 399
                 $select_field = $this->db->quoteIdentifier($table_alias.'_cstm').'.'.$field->field;
400 400
                 // ? $query_array = $this->build_report_query_join($table_alias.'_cstm', $table_alias.'_cstm',$table_alias, $field_module, 'custom', $query);
401 401
                 $query_array = $this->build_report_query_join($table_alias.'_cstm', $table_alias.'_cstm', $field_module, 'custom', $query);
402 402
             } else {
403
-                $select_field= $this->db->quoteIdentifier($table_alias).'.'.$field->field;
403
+                $select_field = $this->db->quoteIdentifier($table_alias).'.'.$field->field;
404 404
             }
405 405
 
406
-            if($field->sort_by != ''){
406
+            if ($field->sort_by != '') {
407 407
                 $query_array['sort_by'][] = $field_label.' '.$field->sort_by;
408 408
             }
409 409
 
410
-            if($field->group_by == 1){
410
+            if ($field->group_by == 1) {
411 411
                 $query_array['group_by'][] = $select_field;
412 412
             }
413 413
 
414
-            if($field->field_function != null){
414
+            if ($field->field_function != null) {
415 415
                 $select_field = $field->field_function.'('.$select_field.')';
416 416
             }
417 417
 
418
-            $query_array['select'][] = $select_field ." AS '".$field_label."'";
419
-            if(isset($extra['select']) && $extra['select']) {
420
-                foreach($extra['select'] as $selectField => $selectAlias) {
421
-                    if($selectAlias) {
422
-                        $query_array['select'][] = $selectField . " AS " . $selectAlias;
418
+            $query_array['select'][] = $select_field." AS '".$field_label."'";
419
+            if (isset($extra['select']) && $extra['select']) {
420
+                foreach ($extra['select'] as $selectField => $selectAlias) {
421
+                    if ($selectAlias) {
422
+                        $query_array['select'][] = $selectField." AS ".$selectAlias;
423 423
                     }
424 424
                     else {
425 425
                         $query_array['select'][] = $selectField;
426 426
                     }
427 427
                 }
428 428
             }
429
-            $query_array['where'][] = $select_field ." IS NOT NULL AND ";
430
-            if(isset($extra['where']) && $extra['where']) {
431
-                $query_array['where'][] = implode(' AND ', $extra['where']) . ' AND ';
429
+            $query_array['where'][] = $select_field." IS NOT NULL AND ";
430
+            if (isset($extra['where']) && $extra['where']) {
431
+                $query_array['where'][] = implode(' AND ', $extra['where']).' AND ';
432 432
             }
433 433
 
434 434
             $query_array = $this->build_report_query_where($query_array);
435 435
 
436
-            foreach ($query_array['select'] as $select){
437
-                $query .=  ($query == '' ? 'SELECT ' : ', ').$select;
436
+            foreach ($query_array['select'] as $select) {
437
+                $query .= ($query == '' ? 'SELECT ' : ', ').$select;
438 438
             }
439 439
 
440 440
             $query .= ' FROM '.$module->table_name.' ';
441 441
 
442
-            if(isset($query_array['join'])){
443
-                foreach ($query_array['join'] as $join){
442
+            if (isset($query_array['join'])) {
443
+                foreach ($query_array['join'] as $join) {
444 444
                     $query .= $join;
445 445
                 }
446 446
             }
447
-            if(isset($query_array['where'])){
447
+            if (isset($query_array['where'])) {
448 448
                 $query_where = '';
449
-                foreach ($query_array['where'] as $where){
450
-                    $query_where .=  ($query_where == '' ? 'WHERE ' : ' ').$where;
449
+                foreach ($query_array['where'] as $where) {
450
+                    $query_where .= ($query_where == '' ? 'WHERE ' : ' ').$where;
451 451
                 }
452 452
 
453 453
                 $query_where = $this->queryWhereRepair($query_where);
@@ -455,41 +455,41 @@  discard block
 block discarded – undo
455 455
                 $query .= ' '.$query_where;
456 456
             }
457 457
 
458
-            if(isset($query_array['group_by'])){
458
+            if (isset($query_array['group_by'])) {
459 459
                 $query_group_by = '';
460
-                foreach ($query_array['group_by'] as $group_by){
461
-                    $query_group_by .=  ($query_group_by == '' ? 'GROUP BY ' : ', ').$group_by;
460
+                foreach ($query_array['group_by'] as $group_by) {
461
+                    $query_group_by .= ($query_group_by == '' ? 'GROUP BY ' : ', ').$group_by;
462 462
                 }
463 463
                 $query .= ' '.$query_group_by;
464 464
             }
465 465
 
466
-            if(isset($query_array['sort_by'])){
466
+            if (isset($query_array['sort_by'])) {
467 467
                 $query_sort_by = '';
468
-                foreach ($query_array['sort_by'] as $sort_by){
469
-                    $query_sort_by .=  ($query_sort_by == '' ? 'ORDER BY ' : ', ').$sort_by;
468
+                foreach ($query_array['sort_by'] as $sort_by) {
469
+                    $query_sort_by .= ($query_sort_by == '' ? 'ORDER BY ' : ', ').$sort_by;
470 470
                 }
471 471
                 $query .= ' '.$query_sort_by;
472 472
             }
473 473
 
474
-            $query .= ' group by ' . $field_label;
474
+            $query .= ' group by '.$field_label;
475 475
 
476 476
             $result = $this->db->query($query);
477 477
 
478 478
             while ($row = $this->db->fetchByAssoc($result)) {
479
-                if($html != '') $html .= '<br />';
479
+                if ($html != '') $html .= '<br />';
480 480
 
481 481
                $html .= $this->build_report_html($offset, $links, $row[$field_label], '', $extra);
482 482
 
483 483
             }
484 484
         }
485 485
 
486
-        if($html == '') $html = $this->build_report_html($offset, $links);
486
+        if ($html == '') $html = $this->build_report_html($offset, $links);
487 487
         return $html;
488 488
 
489 489
     }
490 490
 
491 491
 
492
-    function build_report_html($offset = -1, $links = true, $group_value = '', $tableIdentifier = '', $extra = array()){
492
+    function build_report_html($offset = -1, $links = true, $group_value = '', $tableIdentifier = '', $extra = array()) {
493 493
 
494 494
         global $beanList, $sugar_config;
495 495
 
@@ -502,22 +502,22 @@  discard block
 block discarded – undo
502 502
         // We have a count query.  Run it and get the results.
503 503
         $result = $this->db->query($count_query);
504 504
         $assoc = $this->db->fetchByAssoc($result);
505
-        if(!empty($assoc['c']))
505
+        if (!empty($assoc['c']))
506 506
         {
507 507
             $total_rows = $assoc['c'];
508 508
         }
509 509
 
510 510
         $html = "<table class='list' id='report_table".$group_value."' width='100%' cellspacing='0' cellpadding='0' border='0' repeat_header='1'>";
511 511
 
512
-        if($offset >= 0){
512
+        if ($offset >= 0) {
513 513
             $start = 0;
514 514
             $end = 0;
515 515
             $previous_offset = 0;
516 516
             $next_offset = 0;
517 517
             $last_offset = 0;
518 518
 
519
-            if($total_rows > 0){
520
-                $start = $offset +1;
519
+            if ($total_rows > 0) {
520
+                $start = $offset + 1;
521 521
                 $end = (($offset + $max_rows) < $total_rows) ? $offset + $max_rows : $total_rows;
522 522
                 $previous_offset = ($offset - $max_rows) < 0 ? 0 : $offset - $max_rows;
523 523
                 $next_offset = $offset + $max_rows;
@@ -529,36 +529,36 @@  discard block
 block discarded – undo
529 529
 
530 530
             $moduleFieldByGroupValue = $this->getModuleFieldByGroupValue($beanList, $group_value);
531 531
 
532
-            $html .="<td colspan='18'>
532
+            $html .= "<td colspan='18'>
533 533
                        <table class='paginationTable' border='0' cellpadding='0' cellspacing='0' width='100%'>
534 534
                         <td style='text-align:left' ><H3><a href=\"javascript:void(0)\" class=\"collapseLink\" onclick=\"groupedReportToggler.toggleList(this);\"><img border=\"0\" id=\"detailpanel_1_img_hide\" src=\"themes/SuiteR/images/basic_search.gif\"></a>$moduleFieldByGroupValue</H3></td>
535 535
                         <td class='paginationChangeButtons' align='right' nowrap='nowrap' width='1%'>";
536 536
 
537
-            if($offset == 0){
538
-                $html .="<button type='button' id='listViewStartButton_top' name='listViewStartButton' title='Start' class='button' disabled='disabled'>
537
+            if ($offset == 0) {
538
+                $html .= "<button type='button' id='listViewStartButton_top' name='listViewStartButton' title='Start' class='button' disabled='disabled'>
539 539
                     <img src='".SugarThemeRegistry::current()->getImageURL('start_off.gif')."' alt='Start' align='absmiddle' border='0'>
540 540
                 </button>
541 541
                 <button type='button' id='listViewPrevButton_top' name='listViewPrevButton' class='button' title='Previous' disabled='disabled'>
542 542
                     <img src='".SugarThemeRegistry::current()->getImageURL('previous_off.gif')."' alt='Previous' align='absmiddle' border='0'>
543 543
                 </button>";
544 544
             } else {
545
-                $html .="<button type='button' id='listViewStartButton_top' name='listViewStartButton' title='Start' class='button' onclick='changeReportPage(\"".$this->id."\",0,\"".$group_value."\",\"".$tableIdentifier."\")'>
545
+                $html .= "<button type='button' id='listViewStartButton_top' name='listViewStartButton' title='Start' class='button' onclick='changeReportPage(\"".$this->id."\",0,\"".$group_value."\",\"".$tableIdentifier."\")'>
546 546
                     <img src='".SugarThemeRegistry::current()->getImageURL('start.gif')."' alt='Start' align='absmiddle' border='0'>
547 547
                 </button>
548 548
                 <button type='button' id='listViewPrevButton_top' name='listViewPrevButton' class='button' title='Previous' onclick='changeReportPage(\"".$this->id."\",".$previous_offset.",\"".$group_value."\",\"".$tableIdentifier."\")'>
549 549
                     <img src='".SugarThemeRegistry::current()->getImageURL('previous.gif')."' alt='Previous' align='absmiddle' border='0'>
550 550
                 </button>";
551 551
             }
552
-            $html .=" <span class='pageNumbers'>(".$start ." - ".$end ." of ". $total_rows .")</span>";
553
-            if($next_offset < $total_rows){
554
-                $html .="<button type='button' id='listViewNextButton_top' name='listViewNextButton' title='Next' class='button' onclick='changeReportPage(\"".$this->id."\",".$next_offset.",\"".$group_value."\",\"".$tableIdentifier."\")'>
552
+            $html .= " <span class='pageNumbers'>(".$start." - ".$end." of ".$total_rows.")</span>";
553
+            if ($next_offset < $total_rows) {
554
+                $html .= "<button type='button' id='listViewNextButton_top' name='listViewNextButton' title='Next' class='button' onclick='changeReportPage(\"".$this->id."\",".$next_offset.",\"".$group_value."\",\"".$tableIdentifier."\")'>
555 555
                         <img src='".SugarThemeRegistry::current()->getImageURL('next.gif')."' alt='Next' align='absmiddle' border='0'>
556 556
                     </button>
557 557
                      <button type='button' id='listViewEndButton_top' name='listViewEndButton' title='End' class='button' onclick='changeReportPage(\"".$this->id."\",".$last_offset.",\"".$group_value."\",\"".$tableIdentifier."\")'>
558 558
                         <img src='".SugarThemeRegistry::current()->getImageURL('end.gif')."' alt='End' align='absmiddle' border='0'>
559 559
                     </button>";
560 560
             } else {
561
-                $html .="<button type='button' id='listViewNextButton_top' name='listViewNextButton' title='Next' class='button'  disabled='disabled'>
561
+                $html .= "<button type='button' id='listViewNextButton_top' name='listViewNextButton' title='Next' class='button'  disabled='disabled'>
562 562
                         <img src='".SugarThemeRegistry::current()->getImageURL('next_off.gif')."' alt='Next' align='absmiddle' border='0'>
563 563
                     </button>
564 564
                      <button type='button' id='listViewEndButton_top' name='listViewEndButton' title='End' class='button'  disabled='disabled'>
@@ -567,12 +567,12 @@  discard block
 block discarded – undo
567 567
 
568 568
             }
569 569
 
570
-            $html .="</td>
570
+            $html .= "</td>
571 571
                        </table>
572 572
                       </td>";
573 573
 
574
-            $html .="</tr></thead>";
575
-        } else{
574
+            $html .= "</tr></thead>";
575
+        } else {
576 576
 
577 577
             $moduleFieldByGroupValue = $this->getModuleFieldByGroupValue($beanList, $group_value);
578 578
 
@@ -598,16 +598,16 @@  discard block
 block discarded – undo
598 598
 
599 599
             $field_module = $this->report_module;
600 600
             $field_alias = $field_bean->table_name;
601
-            if($path[0] != $this->report_module){
602
-                foreach($path as $rel){
603
-                    if(empty($rel)){
601
+            if ($path[0] != $this->report_module) {
602
+                foreach ($path as $rel) {
603
+                    if (empty($rel)) {
604 604
                         continue;
605 605
                     }
606
-                    $field_module = getRelatedModule($field_module,$rel);
607
-                    $field_alias = $field_alias . ':'.$rel;
606
+                    $field_module = getRelatedModule($field_module, $rel);
607
+                    $field_alias = $field_alias.':'.$rel;
608 608
                 }
609 609
             }
610
-            $label = str_replace(' ','_',$field->label).$i;
610
+            $label = str_replace(' ', '_', $field->label).$i;
611 611
             $fields[$label]['field'] = $field->field;
612 612
             $fields[$label]['label'] = $field->label;
613 613
             $fields[$label]['display'] = $field->display;
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
             $fields[$label]['params'] = array("date_format" => $field->format);
621 621
 
622 622
 
623
-            if($fields[$label]['display']){
623
+            if ($fields[$label]['display']) {
624 624
                 $html .= "<th scope='col'>";
625 625
                 $html .= "<div style='white-space: normal;' width='100%' align='left'>";
626 626
                 $html .= $field->label;
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
         $html .= "</thead>";
634 634
         $html .= "<tbody>";
635 635
 
636
-        if($offset >= 0){
636
+        if ($offset >= 0) {
637 637
             $result = $this->db->limitQuery($report_sql, $offset, $max_rows);
638 638
         } else {
639 639
             $result = $this->db->query($report_sql);
@@ -646,39 +646,39 @@  discard block
 block discarded – undo
646 646
         while ($row = $this->db->fetchByAssoc($result)) {
647 647
             $html .= "<tr class='".$row_class."' height='20'>";
648 648
 
649
-            foreach($fields as $name => $att){
650
-                if($att['display']){
649
+            foreach ($fields as $name => $att) {
650
+                if ($att['display']) {
651 651
                     $html .= "<td class='' valign='top' align='left'>";
652
-                    if($att['link'] && $links){
653
-                        $html .= "<a href='" . $sugar_config['site_url'] . "/index.php?module=".$att['module']."&action=DetailView&record=".$row[$att['alias'].'_id']."'>";
652
+                    if ($att['link'] && $links) {
653
+                        $html .= "<a href='".$sugar_config['site_url']."/index.php?module=".$att['module']."&action=DetailView&record=".$row[$att['alias'].'_id']."'>";
654 654
                     }
655 655
 
656 656
                     $currency_id = isset($row[$att['alias'].'_currency_id']) ? $row[$att['alias'].'_currency_id'] : '';
657 657
 
658
-                    switch ($att['function']){
658
+                    switch ($att['function']) {
659 659
                         case 'COUNT':
660 660
                         //case 'SUM':
661 661
                             $html .= $row[$name];
662 662
                             break;
663 663
                         default:
664 664
 
665
-                            $html .= getModuleField($att['module'], $att['field'], $att['field'], 'DetailView',$row[$name],'',$currency_id, $att['params']);
665
+                            $html .= getModuleField($att['module'], $att['field'], $att['field'], 'DetailView', $row[$name], '', $currency_id, $att['params']);
666 666
                             break;
667 667
                     }
668
-                    if($att['total']){
668
+                    if ($att['total']) {
669 669
                         $totals[$name][] = $row[$name];
670 670
                     }
671
-                    if($att['link'] && $links) $html .= "</a>";
671
+                    if ($att['link'] && $links) $html .= "</a>";
672 672
                     $html .= "</td>";
673 673
                 }
674 674
             }
675 675
             $html .= "</tr>";
676 676
 
677
-            $row_class = $row_class == 'oddListRowS1' ?  'evenListRowS1':'oddListRowS1';
677
+            $row_class = $row_class == 'oddListRowS1' ? 'evenListRowS1' : 'oddListRowS1';
678 678
         }
679 679
         $html .= "</tbody>";
680 680
 
681
-        $html .= $this->getTotalHtml($fields,$totals);
681
+        $html .= $this->getTotalHtml($fields, $totals);
682 682
 
683 683
         $html .= "</table>";
684 684
 
@@ -721,13 +721,13 @@  discard block
 block discarded – undo
721 721
 
722 722
             $field_module = $this->report_module;
723 723
             $field_alias = $field_bean->table_name;
724
-            if($path[0] != $this->report_module){
725
-                foreach($path as $rel){
726
-                    if(empty($rel)){
724
+            if ($path[0] != $this->report_module) {
725
+                foreach ($path as $rel) {
726
+                    if (empty($rel)) {
727 727
                         continue;
728 728
                     }
729
-                    $field_module = getRelatedModule($field_module,$rel);
730
-                    $field_alias = $field_alias . ':'.$rel;
729
+                    $field_module = getRelatedModule($field_module, $rel);
730
+                    $field_alias = $field_alias.':'.$rel;
731 731
                 }
732 732
             }
733 733
 
@@ -740,31 +740,31 @@  discard block
 block discarded – undo
740 740
         return $moduleFieldByGroupValue;
741 741
     }
742 742
 
743
-    function getTotalHTML($fields,$totals){
743
+    function getTotalHTML($fields, $totals) {
744 744
         global $app_list_strings;
745 745
         $html = '';
746 746
         $html .= "<tbody>";
747 747
         $html .= "<tr>";
748
-        foreach($fields as $label => $field){
749
-            if(!$field['display']){
748
+        foreach ($fields as $label => $field) {
749
+            if (!$field['display']) {
750 750
                 continue;
751 751
             }
752
-            if($field['total']){
753
-                $totalLabel = $field['label'] ." ".$app_list_strings['aor_total_options'][$field['total']];
752
+            if ($field['total']) {
753
+                $totalLabel = $field['label']." ".$app_list_strings['aor_total_options'][$field['total']];
754 754
                 $html .= "<th>{$totalLabel}</th>";
755
-            }else{
755
+            } else {
756 756
                 $html .= "<th></th>";
757 757
             }
758 758
         }
759 759
         $html .= "</tr>";
760 760
         $html .= "<tr>";
761
-        foreach($fields as $label => $field){
762
-            if(!$field['display']){
761
+        foreach ($fields as $label => $field) {
762
+            if (!$field['display']) {
763 763
                 continue;
764 764
             }
765
-            if($field['total'] && isset($totals[$label])){
766
-                $html .= "<td>".$this->calculateTotal($field['total'],$totals[$label])."</td>";
767
-            }else{
765
+            if ($field['total'] && isset($totals[$label])) {
766
+                $html .= "<td>".$this->calculateTotal($field['total'], $totals[$label])."</td>";
767
+            } else {
768 768
                 $html .= "<td></td>";
769 769
             }
770 770
         }
@@ -773,24 +773,24 @@  discard block
 block discarded – undo
773 773
         return $html;
774 774
     }
775 775
 
776
-    function calculateTotal($type, $totals){
777
-        switch($type){
776
+    function calculateTotal($type, $totals) {
777
+        switch ($type) {
778 778
             case 'SUM':
779 779
                 return array_sum($totals);
780 780
             case 'COUNT':
781 781
                 return count($totals);
782 782
             case 'AVG':
783
-                return array_sum($totals)/count($totals);
783
+                return array_sum($totals) / count($totals);
784 784
             default:
785 785
                 return '';
786 786
         }
787 787
     }
788 788
 
789
-    private function encloseForCSV($field){
789
+    private function encloseForCSV($field) {
790 790
         return '"'.$field.'"';
791 791
     }
792 792
 
793
-    function build_report_csv(){
793
+    function build_report_csv() {
794 794
 
795 795
         ini_set('zlib.output_compression', 'Off');
796 796
 
@@ -814,20 +814,20 @@  discard block
 block discarded – undo
814 814
             $path = unserialize(base64_decode($field->module_path));
815 815
 
816 816
             $field_module = $this->report_module;
817
-            if($path[0] != $this->report_module){
818
-                foreach($path as $rel){
819
-                    $field_module = getRelatedModule($field_module,$rel);
817
+            if ($path[0] != $this->report_module) {
818
+                foreach ($path as $rel) {
819
+                    $field_module = getRelatedModule($field_module, $rel);
820 820
                 }
821 821
             }
822
-            $label = str_replace(' ','_',$field->label).$i;
822
+            $label = str_replace(' ', '_', $field->label).$i;
823 823
             $fields[$label]['field'] = $field->field;
824 824
             $fields[$label]['display'] = $field->display;
825 825
             $fields[$label]['function'] = $field->field_function;
826 826
             $fields[$label]['module'] = $field_module;
827 827
 
828 828
 
829
-            if($field->display){
830
-                $csv.= $this->encloseForCSV($field->label);
829
+            if ($field->display) {
830
+                $csv .= $this->encloseForCSV($field->label);
831 831
                 $csv .= $delimiter;
832 832
             }
833 833
             ++$i;
@@ -838,30 +838,30 @@  discard block
 block discarded – undo
838 838
 
839 839
         while ($row = $this->db->fetchByAssoc($result)) {
840 840
             $csv .= "\r\n";
841
-            foreach($fields as $name => $att){
842
-                if($att['display']){
843
-                    if($att['function'] != '' )
841
+            foreach ($fields as $name => $att) {
842
+                if ($att['display']) {
843
+                    if ($att['function'] != '')
844 844
                         $csv .= $this->encloseForCSV($row[$name]);
845 845
                     else
846
-                        $csv .= $this->encloseForCSV(trim(strip_tags(getModuleField($att['module'], $att['field'], $att['field'], 'DetailView',$row[$name]))));
846
+                        $csv .= $this->encloseForCSV(trim(strip_tags(getModuleField($att['module'], $att['field'], $att['field'], 'DetailView', $row[$name]))));
847 847
                     $csv .= $delimiter;
848 848
                 }
849 849
             }
850 850
         }
851 851
 
852
-        $csv= $GLOBALS['locale']->translateCharset($csv, 'UTF-8', $GLOBALS['locale']->getExportCharset());
852
+        $csv = $GLOBALS['locale']->translateCharset($csv, 'UTF-8', $GLOBALS['locale']->getExportCharset());
853 853
 
854 854
         ob_clean();
855 855
         header("Pragma: cache");
856 856
         header("Content-type: text/comma-separated-values; charset=".$GLOBALS['locale']->getExportCharset());
857 857
         header("Content-Disposition: attachment; filename=\"{$this->name}.csv\"");
858 858
         header("Content-transfer-encoding: binary");
859
-        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
860
-        header("Last-Modified: " . TimeDate::httpTime() );
861
-        header("Cache-Control: post-check=0, pre-check=0", false );
859
+        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
860
+        header("Last-Modified: ".TimeDate::httpTime());
861
+        header("Cache-Control: post-check=0, pre-check=0", false);
862 862
         header("Content-Length: ".mb_strlen($csv, '8bit'));
863 863
         if (!empty($sugar_config['export_excel_compatible'])) {
864
-            $csv==chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
864
+            $csv == chr(255).chr(254).mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');
865 865
         }
866 866
         print $csv;
867 867
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 
871 871
 
872 872
 
873
-    function build_report_query($group_value ='', $extra = array()){
873
+    function build_report_query($group_value = '', $extra = array()) {
874 874
         global $beanList;
875 875
 
876 876
         $module = new $beanList[$this->report_module]();
@@ -879,26 +879,26 @@  discard block
 block discarded – undo
879 879
         $query_array = array();
880 880
 
881 881
         $query_array = $this->build_report_query_select($query_array, $group_value);
882
-        if(isset($extra['where']) && $extra['where']) {
883
-            $query_array['where'][] = implode(' AND ', $extra['where']) . ' AND ';
882
+        if (isset($extra['where']) && $extra['where']) {
883
+            $query_array['where'][] = implode(' AND ', $extra['where']).' AND ';
884 884
         }
885 885
         $query_array = $this->build_report_query_where($query_array);
886 886
 
887
-        foreach ($query_array['select'] as $select){
888
-            $query .=  ($query == '' ? 'SELECT ' : ', ').$select;
887
+        foreach ($query_array['select'] as $select) {
888
+            $query .= ($query == '' ? 'SELECT ' : ', ').$select;
889 889
         }
890 890
 
891 891
         $query .= ' FROM '.$this->db->quoteIdentifier($module->table_name).' ';
892 892
 
893
-        if(isset($query_array['join'])){
894
-            foreach ($query_array['join'] as $join){
893
+        if (isset($query_array['join'])) {
894
+            foreach ($query_array['join'] as $join) {
895 895
                 $query .= $join;
896 896
             }
897 897
         }
898
-        if(isset($query_array['where'])){
898
+        if (isset($query_array['where'])) {
899 899
             $query_where = '';
900
-            foreach ($query_array['where'] as $where){
901
-                $query_where .=  ($query_where == '' ? 'WHERE ' : ' ').$where;
900
+            foreach ($query_array['where'] as $where) {
901
+                $query_where .= ($query_where == '' ? 'WHERE ' : ' ').$where;
902 902
             }
903 903
 
904 904
             $query_where = $this->queryWhereRepair($query_where);
@@ -906,18 +906,18 @@  discard block
 block discarded – undo
906 906
             $query .= ' '.$query_where;
907 907
         }
908 908
 
909
-        if(isset($query_array['group_by'])){
909
+        if (isset($query_array['group_by'])) {
910 910
             $query_group_by = '';
911
-            foreach ($query_array['group_by'] as $group_by){
912
-                $query_group_by .=  ($query_group_by == '' ? 'GROUP BY ' : ', ').$group_by;
911
+            foreach ($query_array['group_by'] as $group_by) {
912
+                $query_group_by .= ($query_group_by == '' ? 'GROUP BY ' : ', ').$group_by;
913 913
             }
914 914
             $query .= ' '.$query_group_by;
915 915
         }
916 916
 
917
-        if(isset($query_array['sort_by'])){
917
+        if (isset($query_array['sort_by'])) {
918 918
             $query_sort_by = '';
919
-            foreach ($query_array['sort_by'] as $sort_by){
920
-                $query_sort_by .=  ($query_sort_by == '' ? 'ORDER BY ' : ', ').$sort_by;
919
+            foreach ($query_array['sort_by'] as $sort_by) {
920
+                $query_sort_by .= ($query_sort_by == '' ? 'ORDER BY ' : ', ').$sort_by;
921 921
             }
922 922
             $query .= ' '.$query_sort_by;
923 923
         }
@@ -931,11 +931,11 @@  discard block
 block discarded – undo
931 931
 
932 932
         $safe = 0;
933 933
         $query_where_clean = '';
934
-        while($query_where_clean != $query_where) {
934
+        while ($query_where_clean != $query_where) {
935 935
             $query_where_clean = $query_where;
936 936
             $query_where = preg_replace('/\b(AND|OR)\s*\(\s*\)|[^\w+\s*]\(\s*\)/i', '', $query_where_clean);
937 937
             $safe++;
938
-            if($safe>100){
938
+            if ($safe > 100) {
939 939
                 $GLOBALS['log']->fatal('Invalid report query conditions');
940 940
                 break;
941 941
             }
@@ -944,10 +944,10 @@  discard block
 block discarded – undo
944 944
         return $query_where;
945 945
     }
946 946
 
947
-    function build_report_query_select($query = array(), $group_value =''){
947
+    function build_report_query_select($query = array(), $group_value = '') {
948 948
         global $beanList;
949 949
 
950
-        if($beanList[$this->report_module]){
950
+        if ($beanList[$this->report_module]) {
951 951
             $module = new $beanList[$this->report_module]();
952 952
 
953 953
             $query['select'][] = $this->db->quoteIdentifier($module->table_name).".id AS '".$module->table_name."_id'";
@@ -960,16 +960,16 @@  discard block
 block discarded – undo
960 960
                 $field = new AOR_Field();
961 961
                 $field->retrieve($row['id']);
962 962
 
963
-                $field->label = str_replace(' ','_',$field->label).$i;
963
+                $field->label = str_replace(' ', '_', $field->label).$i;
964 964
 
965 965
                 $path = unserialize(base64_decode($field->module_path));
966 966
 
967 967
                 $field_module = $module;
968 968
                 $table_alias = $field_module->table_name;
969 969
                 $oldAlias = $table_alias;
970
-                if(!empty($path[0]) && $path[0] != $module->module_dir){
971
-                    foreach($path as $rel){
972
-                        $new_field_module = new $beanList[getRelatedModule($field_module->module_dir,$rel)];
970
+                if (!empty($path[0]) && $path[0] != $module->module_dir) {
971
+                    foreach ($path as $rel) {
972
+                        $new_field_module = new $beanList[getRelatedModule($field_module->module_dir, $rel)];
973 973
                         $oldAlias = $table_alias;
974 974
                         $table_alias = $table_alias.":".$rel;
975 975
                         $query = $this->build_report_query_join($rel, $table_alias, $oldAlias, $field_module, 'relationship', $query, $new_field_module);
@@ -980,54 +980,54 @@  discard block
 block discarded – undo
980 980
 
981 981
                 $data = $field_module->field_defs[$field->field];
982 982
 
983
-                if($data['type'] == 'relate' && isset($data['id_name'])) {
983
+                if ($data['type'] == 'relate' && isset($data['id_name'])) {
984 984
                     $field->field = $data['id_name'];
985 985
                     $data_new = $field_module->field_defs[$field->field];
986
-                    if(isset($data_new['source']) && $data_new['source'] == 'non-db' && $data_new['type'] != 'link' && isset($data['link'])){
986
+                    if (isset($data_new['source']) && $data_new['source'] == 'non-db' && $data_new['type'] != 'link' && isset($data['link'])) {
987 987
                         $data_new['type'] = 'link';
988 988
                         $data_new['relationship'] = $data['link'];
989 989
                     }
990 990
                     $data = $data_new;
991 991
                 }
992 992
 
993
-                if($data['type'] == 'link' && $data['source'] == 'non-db') {
994
-                    $new_field_module = new $beanList[getRelatedModule($field_module->module_dir,$data['relationship'])];
993
+                if ($data['type'] == 'link' && $data['source'] == 'non-db') {
994
+                    $new_field_module = new $beanList[getRelatedModule($field_module->module_dir, $data['relationship'])];
995 995
                     $table_alias = $data['relationship'];
996
-                    $query = $this->build_report_query_join($data['relationship'],$table_alias, $oldAlias, $field_module, 'relationship', $query, $new_field_module);
996
+                    $query = $this->build_report_query_join($data['relationship'], $table_alias, $oldAlias, $field_module, 'relationship', $query, $new_field_module);
997 997
                     $field_module = $new_field_module;
998 998
                     $field->field = 'id';
999 999
                 }
1000 1000
 
1001
-                if($data['type'] == 'currency' && isset($field_module->field_defs['currency_id'])) {
1002
-                    if((isset($field_module->field_defs['currency_id']['source']) && $field_module->field_defs['currency_id']['source'] == 'custom_fields')) {
1001
+                if ($data['type'] == 'currency' && isset($field_module->field_defs['currency_id'])) {
1002
+                    if ((isset($field_module->field_defs['currency_id']['source']) && $field_module->field_defs['currency_id']['source'] == 'custom_fields')) {
1003 1003
                         $query['select'][$table_alias.'_currency_id'] = $this->db->quoteIdentifier($table_alias.'_cstm').".currency_id AS '".$table_alias."_currency_id'";
1004 1004
                     } else {
1005 1005
                         $query['select'][$table_alias.'_currency_id'] = $this->db->quoteIdentifier($table_alias).".currency_id AS '".$table_alias."_currency_id'";
1006 1006
                     }
1007 1007
                 }
1008 1008
 
1009
-                if((isset($data['source']) && $data['source'] == 'custom_fields')) {
1009
+                if ((isset($data['source']) && $data['source'] == 'custom_fields')) {
1010 1010
                     $select_field = $this->db->quoteIdentifier($table_alias.'_cstm').'.'.$field->field;
1011
-                    $query = $this->build_report_query_join($table_alias.'_cstm', $table_alias.'_cstm',$table_alias, $field_module, 'custom', $query);
1011
+                    $query = $this->build_report_query_join($table_alias.'_cstm', $table_alias.'_cstm', $table_alias, $field_module, 'custom', $query);
1012 1012
                 } else {
1013
-                    $select_field= $this->db->quoteIdentifier($table_alias).'.'.$field->field;
1013
+                    $select_field = $this->db->quoteIdentifier($table_alias).'.'.$field->field;
1014 1014
                 }
1015 1015
 
1016
-                if($field->sort_by != ''){
1016
+                if ($field->sort_by != '') {
1017 1017
                     $query['sort_by'][] = $select_field." ".$field->sort_by;
1018 1018
                 }
1019 1019
 
1020
-                if($field->group_by == 1){
1021
-                    $query['group_by'][] = $field->format ? str_replace('(%1)', '(' . $select_field . ')', preg_replace(array('/\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format)))) : $select_field;
1020
+                if ($field->group_by == 1) {
1021
+                    $query['group_by'][] = $field->format ? str_replace('(%1)', '('.$select_field.')', preg_replace(array('/\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format)))) : $select_field;
1022 1022
                 }
1023 1023
 
1024
-                if($field->field_function != null){
1024
+                if ($field->field_function != null) {
1025 1025
                     $select_field = $field->field_function.'('.$select_field.')';
1026 1026
                 }
1027 1027
 
1028
-                $query['select'][] = $select_field ." AS '".$field->label."'";
1028
+                $query['select'][] = $select_field." AS '".$field->label."'";
1029 1029
 
1030
-                if($field->group_display == 1 && $group_value) $query['where'][] = $select_field." = '".$group_value."' AND ";
1030
+                if ($field->group_display == 1 && $group_value) $query['where'][] = $select_field." = '".$group_value."' AND ";
1031 1031
                     ++$i;
1032 1032
             }
1033 1033
         }
@@ -1035,30 +1035,30 @@  discard block
 block discarded – undo
1035 1035
     }
1036 1036
 
1037 1037
 
1038
-    function build_report_query_join($name, $alias, $parentAlias, SugarBean $module, $type, $query = array(),SugarBean $rel_module = null ){
1038
+    function build_report_query_join($name, $alias, $parentAlias, SugarBean $module, $type, $query = array(), SugarBean $rel_module = null) {
1039 1039
 
1040
-        if(!isset($query['join'][$alias])){
1040
+        if (!isset($query['join'][$alias])) {
1041 1041
 
1042
-            switch ($type){
1042
+            switch ($type) {
1043 1043
                 case 'custom':
1044
-                    $query['join'][$alias] = 'LEFT JOIN '.$this->db->quoteIdentifier($module->get_custom_table_name()).' '.$this->db->quoteIdentifier($name).' ON '.$this->db->quoteIdentifier($parentAlias).'.id = '. $this->db->quoteIdentifier($name).'.id_c ';
1044
+                    $query['join'][$alias] = 'LEFT JOIN '.$this->db->quoteIdentifier($module->get_custom_table_name()).' '.$this->db->quoteIdentifier($name).' ON '.$this->db->quoteIdentifier($parentAlias).'.id = '.$this->db->quoteIdentifier($name).'.id_c ';
1045 1045
                     break;
1046 1046
 
1047 1047
                 case 'relationship':
1048
-                    if($module->load_relationship($name)){
1048
+                    if ($module->load_relationship($name)) {
1049 1049
                         $params['join_type'] = 'LEFT JOIN';
1050
-                        if($module->$name->relationship_type != 'one-to-many'){
1051
-                            if($module->$name->getSide() == REL_LHS){
1050
+                        if ($module->$name->relationship_type != 'one-to-many') {
1051
+                            if ($module->$name->getSide() == REL_LHS) {
1052 1052
                                 $params['right_join_table_alias'] = $this->db->quoteIdentifier($alias);
1053 1053
                                 $params['join_table_alias'] = $this->db->quoteIdentifier($alias);
1054 1054
                                 $params['left_join_table_alias'] = $this->db->quoteIdentifier($parentAlias);
1055
-                            }else{
1055
+                            } else {
1056 1056
                                 $params['right_join_table_alias'] = $this->db->quoteIdentifier($parentAlias);
1057 1057
                                 $params['join_table_alias'] = $this->db->quoteIdentifier($alias);
1058 1058
                                 $params['left_join_table_alias'] = $this->db->quoteIdentifier($alias);
1059 1059
                             }
1060 1060
 
1061
-                        }else{
1061
+                        } else {
1062 1062
                             $params['right_join_table_alias'] = $this->db->quoteIdentifier($parentAlias);
1063 1063
                             $params['join_table_alias'] = $this->db->quoteIdentifier($alias);
1064 1064
                             $params['left_join_table_alias'] = $this->db->quoteIdentifier($parentAlias);
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
                         $params['join_table_link_alias'] = $this->db->quoteIdentifier($linkAlias);
1068 1068
                         $join = $module->$name->getJoin($params, true);
1069 1069
                         $query['join'][$alias] = $join['join'];
1070
-                        if($rel_module != null) {
1070
+                        if ($rel_module != null) {
1071 1071
                             $query['join'][$alias] .= $this->build_report_access_query($rel_module, $name);
1072 1072
                         }
1073 1073
                         $query['select'][] = $join['select']." AS '".$alias."_id'";
@@ -1082,11 +1082,11 @@  discard block
 block discarded – undo
1082 1082
         return $query;
1083 1083
     }
1084 1084
 
1085
-    function build_report_access_query(SugarBean $module, $alias){
1085
+    function build_report_access_query(SugarBean $module, $alias) {
1086 1086
 
1087 1087
         $module->table_name = $alias;
1088 1088
         $where = '';
1089
-        if($module->bean_implements('ACL') && ACLController::requireOwner($module->module_dir, 'list') )
1089
+        if ($module->bean_implements('ACL') && ACLController::requireOwner($module->module_dir, 'list'))
1090 1090
         {
1091 1091
             global $current_user;
1092 1092
             $owner_where = $module->getOwnerWhere($current_user->id);
@@ -1094,18 +1094,18 @@  discard block
 block discarded – undo
1094 1094
 
1095 1095
         }
1096 1096
 
1097
-        if(file_exists('modules/SecurityGroups/SecurityGroup.php')){
1097
+        if (file_exists('modules/SecurityGroups/SecurityGroup.php')) {
1098 1098
             /* BEGIN - SECURITY GROUPS */
1099
-            if($module->bean_implements('ACL') && ACLController::requireSecurityGroup($module->module_dir, 'list') )
1099
+            if ($module->bean_implements('ACL') && ACLController::requireSecurityGroup($module->module_dir, 'list'))
1100 1100
             {
1101 1101
                 require_once('modules/SecurityGroups/SecurityGroup.php');
1102 1102
                 global $current_user;
1103 1103
                 $owner_where = $module->getOwnerWhere($current_user->id);
1104
-                $group_where = SecurityGroup::getGroupWhere($alias,$module->module_dir,$current_user->id);
1105
-                if(!empty($owner_where)){
1106
-                    $where .= " AND (".  $owner_where." or ".$group_where.") ";
1104
+                $group_where = SecurityGroup::getGroupWhere($alias, $module->module_dir, $current_user->id);
1105
+                if (!empty($owner_where)) {
1106
+                    $where .= " AND (".$owner_where." or ".$group_where.") ";
1107 1107
                 } else {
1108
-                    $where .= ' AND '.  $group_where;
1108
+                    $where .= ' AND '.$group_where;
1109 1109
                 }
1110 1110
             }
1111 1111
             /* END - SECURITY GROUPS */
@@ -1118,16 +1118,16 @@  discard block
 block discarded – undo
1118 1118
      * @param array $query
1119 1119
      * @return array
1120 1120
      */
1121
-    function build_report_query_where($query = array()){
1121
+    function build_report_query_where($query = array()) {
1122 1122
         global $beanList, $app_list_strings, $sugar_config;
1123 1123
 
1124 1124
         $closure = false;
1125
-        if(!empty($query['where'])) {
1125
+        if (!empty($query['where'])) {
1126 1126
             $query['where'][] = '(';
1127 1127
             $closure = true;
1128 1128
         }
1129 1129
 
1130
-        if($beanList[$this->report_module]){
1130
+        if ($beanList[$this->report_module]) {
1131 1131
             $module = new $beanList[$this->report_module]();
1132 1132
 
1133 1133
             $sql = "SELECT id FROM aor_conditions WHERE aor_report_id = '".$this->id."' AND deleted = 0 ORDER BY condition_order ASC";
@@ -1144,21 +1144,21 @@  discard block
 block discarded – undo
1144 1144
                 $condition_module = $module;
1145 1145
                 $table_alias = $condition_module->table_name;
1146 1146
                 $oldAlias = $table_alias;
1147
-                if(!empty($path[0]) && $path[0] != $module->module_dir){
1148
-                    foreach($path as $rel){
1149
-                        if(empty($rel)){
1147
+                if (!empty($path[0]) && $path[0] != $module->module_dir) {
1148
+                    foreach ($path as $rel) {
1149
+                        if (empty($rel)) {
1150 1150
                             continue;
1151 1151
                         }
1152 1152
                         // Bug: Prevents relationships from loading.
1153 1153
                         //$rel = strtolower($rel);
1154
-                        $new_condition_module = new $beanList[getRelatedModule($condition_module->module_dir,$rel)];
1154
+                        $new_condition_module = new $beanList[getRelatedModule($condition_module->module_dir, $rel)];
1155 1155
                         $oldAlias = $table_alias;
1156 1156
                         $table_alias = $table_alias.":".$rel;
1157 1157
                         $query = $this->build_report_query_join($rel, $table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_condition_module);
1158 1158
                         $condition_module = $new_condition_module;
1159 1159
                     }
1160 1160
                 }
1161
-                if(isset($app_list_strings['aor_sql_operator_list'][$condition->operator])) {
1161
+                if (isset($app_list_strings['aor_sql_operator_list'][$condition->operator])) {
1162 1162
                     $where_set = false;
1163 1163
 
1164 1164
                     $data = $condition_module->field_defs[$condition->field];
@@ -1173,24 +1173,24 @@  discard block
 block discarded – undo
1173 1173
                         $data = $data_new;
1174 1174
                     }
1175 1175
 
1176
-                    if($data['type'] == 'link' && $data['source'] == 'non-db') {
1177
-                        $new_field_module = new $beanList[getRelatedModule($condition_module->module_dir,$data['relationship'])];
1176
+                    if ($data['type'] == 'link' && $data['source'] == 'non-db') {
1177
+                        $new_field_module = new $beanList[getRelatedModule($condition_module->module_dir, $data['relationship'])];
1178 1178
                         $table_alias = $data['relationship'];
1179
-                        $query = $this->build_report_query_join($data['relationship'],$table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_field_module);
1179
+                        $query = $this->build_report_query_join($data['relationship'], $table_alias, $oldAlias, $condition_module, 'relationship', $query, $new_field_module);
1180 1180
                         $condition_module = $new_field_module;
1181 1181
 
1182 1182
                         // Debugging: security groups conditions - It's a hack to just get the query working
1183
-                        if($condition_module->module_dir = 'SecurityGroups' && count($path) > 1) {
1183
+                        if ($condition_module->module_dir = 'SecurityGroups' && count($path) > 1) {
1184 1184
 //                            $table_alias = 'opportunities:assigned_user_link:SecurityGroups' ;
1185
-                            $table_alias = $oldAlias. ':' .$rel;
1185
+                            $table_alias = $oldAlias.':'.$rel;
1186 1186
                         }
1187 1187
                         $condition->field = 'id';
1188 1188
                     }
1189 1189
                     if ((isset($data['source']) && $data['source'] == 'custom_fields')) {
1190
-                        $field = $this->db->quoteIdentifier($table_alias . '_cstm') . '.' . $condition->field;
1191
-                        $query = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm', $oldAlias, $condition_module, 'custom', $query);
1190
+                        $field = $this->db->quoteIdentifier($table_alias.'_cstm').'.'.$condition->field;
1191
+                        $query = $this->build_report_query_join($table_alias.'_cstm', $table_alias.'_cstm', $oldAlias, $condition_module, 'custom', $query);
1192 1192
                     } else {
1193
-                        $field = $this->db->quoteIdentifier($table_alias) . '.' . $condition->field;
1193
+                        $field = $this->db->quoteIdentifier($table_alias).'.'.$condition->field;
1194 1194
                     }
1195 1195
 
1196 1196
                     if (!empty($this->user_parameters[$condition->id]) && $condition->parameter) {
@@ -1222,10 +1222,10 @@  discard block
 block discarded – undo
1222 1222
                                 $condition->field = 'id';
1223 1223
                             }
1224 1224
                             if ((isset($data['source']) && $data['source'] == 'custom_fields')) {
1225
-                                $value = $condition_module->table_name . '_cstm.' . $condition->value;
1226
-                                $query = $this->build_report_query_join($condition_module->table_name . '_cstm', $table_alias . '_cstm', $table_alias, $condition_module, 'custom', $query);
1225
+                                $value = $condition_module->table_name.'_cstm.'.$condition->value;
1226
+                                $query = $this->build_report_query_join($condition_module->table_name.'_cstm', $table_alias.'_cstm', $table_alias, $condition_module, 'custom', $query);
1227 1227
                             } else {
1228
-                                $value = ($table_alias ? "`$table_alias`" : $condition_module->table_name) . '.' . $condition->value;
1228
+                                $value = ($table_alias ? "`$table_alias`" : $condition_module->table_name).'.'.$condition->value;
1229 1229
                             }
1230 1230
                             break;
1231 1231
 
@@ -1237,10 +1237,10 @@  discard block
 block discarded – undo
1237 1237
                                 } else {
1238 1238
                                     $value = 'NOW()';
1239 1239
                                 }
1240
-                            } else if($params[0] == 'today'){
1241
-                                if($sugar_config['dbconfig']['db_type'] == 'mssql'){
1240
+                            } else if ($params[0] == 'today') {
1241
+                                if ($sugar_config['dbconfig']['db_type'] == 'mssql') {
1242 1242
                                     //$field =
1243
-                                    $value  = 'CAST(GETDATE() AS DATE)';
1243
+                                    $value = 'CAST(GETDATE() AS DATE)';
1244 1244
                                 } else {
1245 1245
                                     $field = 'DATE('.$field.')';
1246 1246
                                     $value = 'Curdate()';
@@ -1248,10 +1248,10 @@  discard block
 block discarded – undo
1248 1248
                             } else {
1249 1249
                                 $data = $condition_module->field_defs[$params[0]];
1250 1250
                                 if ((isset($data['source']) && $data['source'] == 'custom_fields')) {
1251
-                                    $value = $condition_module->table_name . '_cstm.' . $params[0];
1252
-                                    $query = $this->build_report_query_join($condition_module->table_name . '_cstm', $table_alias . '_cstm', $table_alias, $condition_module, 'custom', $query);
1251
+                                    $value = $condition_module->table_name.'_cstm.'.$params[0];
1252
+                                    $query = $this->build_report_query_join($condition_module->table_name.'_cstm', $table_alias.'_cstm', $table_alias, $condition_module, 'custom', $query);
1253 1253
                                 } else {
1254
-                                    $value = $condition_module->table_name . '.' . $params[0];
1254
+                                    $value = $condition_module->table_name.'.'.$params[0];
1255 1255
                                 }
1256 1256
                             }
1257 1257
 
@@ -1262,9 +1262,9 @@  discard block
 block discarded – undo
1262 1262
                                         $params[3] = 'hours';
1263 1263
                                     default:
1264 1264
                                         if ($sugar_config['dbconfig']['db_type'] == 'mssql') {
1265
-                                            $value = "DATEADD(" . $params[3] . ",  " . $app_list_strings['aor_date_operator'][$params[1]] . " $params[2], $value)";
1265
+                                            $value = "DATEADD(".$params[3].",  ".$app_list_strings['aor_date_operator'][$params[1]]." $params[2], $value)";
1266 1266
                                         } else {
1267
-                                            $value = "DATE_ADD($value, INTERVAL " . $app_list_strings['aor_date_operator'][$params[1]] . " $params[2] " . $params[3] . ")";
1267
+                                            $value = "DATE_ADD($value, INTERVAL ".$app_list_strings['aor_date_operator'][$params[1]]." $params[2] ".$params[3].")";
1268 1268
                                         }
1269 1269
                                         break;
1270 1270
                                 }
@@ -1279,11 +1279,11 @@  discard block
 block discarded – undo
1279 1279
                                 $value = '(';
1280 1280
                                 foreach ($multi_values as $multi_value) {
1281 1281
                                     if ($value != '(') $value .= $sep;
1282
-                                    $value .= $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . " '" . $multi_value . "'";
1282
+                                    $value .= $field.' '.$app_list_strings['aor_sql_operator_list'][$condition->operator]." '".$multi_value."'";
1283 1283
                                 }
1284 1284
                                 $value .= ')';
1285 1285
                             }
1286
-                            $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ': 'AND ')) . $value;
1286
+                            $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op.' ' : 'AND ')).$value;
1287 1287
                             $where_set = true;
1288 1288
                             break;
1289 1289
                         case "Period":
@@ -1292,20 +1292,20 @@  discard block
 block discarded – undo
1292 1292
                             } else {
1293 1293
                                 $params = base64_decode($condition->value);
1294 1294
                             }
1295
-                            $value = '"' . getPeriodDate($params)->format('Y-m-d H:i:s') . '"';
1295
+                            $value = '"'.getPeriodDate($params)->format('Y-m-d H:i:s').'"';
1296 1296
                             break;
1297 1297
                         case "CurrentUserID":
1298 1298
                             global $current_user;
1299
-                            $value = '"' . $current_user->id . '"';
1299
+                            $value = '"'.$current_user->id.'"';
1300 1300
                             break;
1301 1301
                         case 'Value':
1302 1302
                         default:
1303
-                            $value = "'" . $this->db->quote($condition->value) . "'";
1303
+                            $value = "'".$this->db->quote($condition->value)."'";
1304 1304
                             break;
1305 1305
                     }
1306 1306
 
1307 1307
                     //handle like conditions
1308
-                    Switch($condition->operator) {
1308
+                    Switch ($condition->operator) {
1309 1309
                         case 'Contains':
1310 1310
                             $value = "CONCAT('%', ".$value." ,'%')";
1311 1311
                             break;
@@ -1317,17 +1317,17 @@  discard block
 block discarded – undo
1317 1317
                             break;
1318 1318
                     }
1319 1319
 
1320
-                    if($condition->value_type == 'Value' && !$condition->value && $condition->operator == 'Equal_To') {
1320
+                    if ($condition->value_type == 'Value' && !$condition->value && $condition->operator == 'Equal_To') {
1321 1321
                         $value = "{$value} OR {$field} IS NULL";
1322 1322
                     }
1323 1323
 
1324
-                    if (!$where_set) $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ': 'AND ')) . $field . ' ' . $app_list_strings['aor_sql_operator_list'][$condition->operator] . ' ' . $value;
1324
+                    if (!$where_set) $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op.' ' : 'AND ')).$field.' '.$app_list_strings['aor_sql_operator_list'][$condition->operator].' '.$value;
1325 1325
 
1326 1326
                     $tiltLogicOp = false;
1327 1327
                 }
1328
-                else if($condition->parenthesis) {
1329
-                    if($condition->parenthesis == 'START') {
1330
-                        $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op . ' ' : 'AND ')) .  '(';
1328
+                else if ($condition->parenthesis) {
1329
+                    if ($condition->parenthesis == 'START') {
1330
+                        $query['where'][] = ($tiltLogicOp ? '' : ($condition->logic_op ? $condition->logic_op.' ' : 'AND ')).'(';
1331 1331
                         $tiltLogicOp = true;
1332 1332
                     }
1333 1333
                     else {
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 
1342 1342
             }
1343 1343
 
1344
-            if(isset($query['where']) && $query['where']) {
1344
+            if (isset($query['where']) && $query['where']) {
1345 1345
                 array_unshift($query['where'], '(');
1346 1346
                 $query['where'][] = ') AND ';
1347 1347
             }
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 
1350 1350
         }
1351 1351
 
1352
-        if($closure) {
1352
+        if ($closure) {
1353 1353
             $query['where'][] = ')';
1354 1354
         }
1355 1355
 
Please login to merge, or discard this patch.
modules/AOR_Conditions/AOR_Condition.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -79,40 +79,40 @@
 block discarded – undo
79 79
 
80 80
         require_once('modules/AOW_WorkFlow/aow_utils.php');
81 81
 
82
-        $line_count = count($post_data[$key . 'field']);
82
+        $line_count = count($post_data[$key.'field']);
83 83
         $j = 0;
84 84
         for ($i = 0; $i < $line_count; ++$i) {
85 85
 
86
-            if ($post_data[$key . 'deleted'][$i] == 1) {
87
-                $this->mark_deleted($post_data[$key . 'id'][$i]);
86
+            if ($post_data[$key.'deleted'][$i] == 1) {
87
+                $this->mark_deleted($post_data[$key.'id'][$i]);
88 88
             } else {
89 89
                 $condition = new AOR_Condition();
90 90
                 foreach ($this->field_defs as $field_def) {
91 91
                     $field_name = $field_def['name'];
92
-                    if (isset($post_data[$key . $field_name][$i])) {
93
-                        if (is_array($post_data[$key . $field_name][$i])) {
92
+                    if (isset($post_data[$key.$field_name][$i])) {
93
+                        if (is_array($post_data[$key.$field_name][$i])) {
94 94
 
95 95
                             switch ($condition->value_type) {
96 96
                                 case 'Date':
97
-                                    $post_data[$key . $field_name][$i] = base64_encode(serialize($post_data[$key . $field_name][$i]));
97
+                                    $post_data[$key.$field_name][$i] = base64_encode(serialize($post_data[$key.$field_name][$i]));
98 98
                                     break;
99 99
                                 default:
100
-                                    $post_data[$key . $field_name][$i] = encodeMultienumValue($post_data[$key . $field_name][$i]);
100
+                                    $post_data[$key.$field_name][$i] = encodeMultienumValue($post_data[$key.$field_name][$i]);
101 101
                             }
102
-                        } else if ($field_name == 'value' && $post_data[$key . 'value_type'][$i] === 'Value') {
103
-                            $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key . $field_name][$i]);
102
+                        } else if ($field_name == 'value' && $post_data[$key.'value_type'][$i] === 'Value') {
103
+                            $post_data[$key.$field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $condition->field, $post_data[$key.$field_name][$i]);
104 104
                         } else if ($field_name == 'parameter') {
105
-                            $post_data[$key . $field_name][$i] = isset($post_data[$key . $field_name][$i]);
105
+                            $post_data[$key.$field_name][$i] = isset($post_data[$key.$field_name][$i]);
106 106
                         } else if ($field_name == 'module_path') {
107
-                            $post_data[$key . $field_name][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_name][$i])));
107
+                            $post_data[$key.$field_name][$i] = base64_encode(serialize(explode(":", $post_data[$key.$field_name][$i])));
108 108
                         }
109
-                        if ($field_name == 'parenthesis' && $post_data[$key . $field_name][$i] == 'END') {
109
+                        if ($field_name == 'parenthesis' && $post_data[$key.$field_name][$i] == 'END') {
110 110
                             if (!isset($lastParenthesisStartConditionId)) {
111 111
                                 throw new Exception('a closure parenthesis has no starter pair');
112 112
                             }
113 113
                             $condition->parenthesis = $lastParenthesisStartConditionId;
114 114
                         } else {
115
-                            $condition->$field_name = $post_data[$key . $field_name][$i];
115
+                            $condition->$field_name = $post_data[$key.$field_name][$i];
116 116
                         }
117 117
                     } else if ($field_name == 'parameter') {
118 118
                         $condition->$field_name = 0;
Please login to merge, or discard this patch.