Completed
Push — console-installer ( e2b50d...6ce748 )
by Adam
22:30
created
include/database/DBManager.php 1 patch
Spacing   +314 added lines, -314 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.
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 		}
315 315
 
316 316
 		$dberror = $this->lastDbError();
317
-		if($dberror === false) {
317
+		if ($dberror === false) {
318 318
     		$this->last_error = false;
319 319
 	    	return false;
320 320
 		}
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	protected function registerError($userMessage, $message, $dieOnError = false)
334 334
 	{
335
-		if(!empty($message)) {
336
-			if(!empty($userMessage)) {
335
+		if (!empty($message)) {
336
+			if (!empty($userMessage)) {
337 337
 				$message = "$userMessage: $message";
338 338
 			}
339
-			if(empty($message)) {
339
+			if (empty($message)) {
340 340
 			    $message = "Database error";
341 341
 			}
342 342
 			$this->log->fatal($message);
343 343
 			if ($dieOnError || $this->dieOnError) {
344
-				if(isset($GLOBALS['app_strings']['ERR_DB_FAIL'])) {
344
+				if (isset($GLOBALS['app_strings']['ERR_DB_FAIL'])) {
345 345
 					sugar_die($GLOBALS['app_strings']['ERR_DB_FAIL']);
346 346
 				} else {
347 347
 					sugar_die("Database error. Please check suitecrm.log for details.");
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 		$slow_query_time_msec = isset($sugar_config['slow_query_time_msec'])
380 380
 			? $sugar_config['slow_query_time_msec'] : 5000;
381 381
 
382
-		if($do_the_dump) {
383
-			if($slow_query_time_msec < ($this->query_time * 1000)) {
382
+		if ($do_the_dump) {
383
+			if ($slow_query_time_msec < ($this->query_time * 1000)) {
384 384
 				// Then log both the query and the query time
385 385
 				$this->log->fatal('Slow Query (time:'.$this->query_time."\n".$query);
386 386
 				return true;
@@ -412,20 +412,20 @@  discard block
 block discarded – undo
412 412
 		$indices = $GLOBALS['dictionary'][$object_name]['indices'];
413 413
 
414 414
 	if (empty($indices)) {
415
-		foreach ( $GLOBALS['dictionary'] as $current ) {
416
-			if ($current['table'] == $table){
415
+		foreach ($GLOBALS['dictionary'] as $current) {
416
+			if ($current['table'] == $table) {
417 417
 				$indices = $current['indices'];
418 418
 				break;
419 419
 			}
420 420
 		}
421 421
 	}
422 422
 	if (empty($indices)) {
423
-		$this->log->warn('CHECK QUERY: Could not find index definitions for table ' . $table);
423
+		$this->log->warn('CHECK QUERY: Could not find index definitions for table '.$table);
424 424
 		return false;
425 425
 	}
426 426
 	if (!empty($match[2][0])) {
427 427
 		$orderBys = explode(' ', $match[2][0]);
428
-		foreach ($orderBys as $orderBy){
428
+		foreach ($orderBys as $orderBy) {
429 429
 			$orderBy = trim($orderBy);
430 430
 			if (empty($orderBy))
431 431
 				continue;
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 			if ($orderBy == 'asc' || $orderBy == 'desc')
434 434
 				continue;
435 435
 
436
-			$orderBy = str_replace(array($table . '.', ','), '', $orderBy);
436
+			$orderBy = str_replace(array($table.'.', ','), '', $orderBy);
437 437
 
438 438
 			foreach ($indices as $index)
439 439
 				if (empty($index['db']) || $index['db'] == $this->dbType)
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 						if ($field == $orderBy)
442 442
 							return true;
443 443
 
444
-			$warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy ;
444
+			$warning = 'Missing Index For Order By Table: '.$table.' Order By:'.$orderBy;
445 445
 			if (!empty($GLOBALS['sugar_config']['dump_slow_queries']))
446
-				$this->log->fatal('CHECK QUERY:' .$warning);
446
+				$this->log->fatal('CHECK QUERY:'.$warning);
447 447
 			else
448
-				$this->log->warn('CHECK QUERY:' .$warning);
448
+				$this->log->warn('CHECK QUERY:'.$warning);
449 449
 		}
450 450
 	}
451 451
 	return false;
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 	public function insert(SugarBean $bean)
492 492
 	{
493 493
 		$sql = $this->insertSQL($bean);
494
-		$tablename =  $bean->getTableName();
494
+		$tablename = $bean->getTableName();
495 495
 		$msg = "Error inserting into table: $tablename:";
496
-		return $this->query($sql,true,$msg);
496
+		return $this->query($sql, true, $msg);
497 497
 	}
498 498
 
499 499
 	/**
@@ -512,13 +512,13 @@  discard block
 block discarded – undo
512 512
 		{
513 513
 			if (isset($fieldDef['source']) && $fieldDef['source'] != 'db')  continue;
514 514
 			//custom fields handle there save seperatley
515
-			if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue;
515
+			if (!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue;
516 516
 
517
-			if(isset($data[$field])) {
517
+			if (isset($data[$field])) {
518 518
 				// clean the incoming value..
519 519
 				$val = from_html($data[$field]);
520 520
 			} else {
521
-				if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) {
521
+				if (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) {
522 522
 					$val = $fieldDef['default'];
523 523
 				} else {
524 524
 					$val = null;
@@ -528,26 +528,26 @@  discard block
 block discarded – undo
528 528
 			//handle auto increment values here - we may have to do something like nextval for oracle
529 529
 			if (!empty($fieldDef['auto_increment'])) {
530 530
 				$auto = $this->getAutoIncrementSQL($table, $fieldDef['name']);
531
-				if(!empty($auto)) {
531
+				if (!empty($auto)) {
532 532
 					$values[$field] = $auto;
533 533
 				}
534 534
 			} elseif ($fieldDef['name'] == 'deleted') {
535 535
 				$values['deleted'] = (int)$val;
536 536
 			} else {
537 537
 				// need to do some thing about types of values
538
-				if(!is_null($val) || !empty($fieldDef['required'])) {
538
+				if (!is_null($val) || !empty($fieldDef['required'])) {
539 539
 					$values[$field] = $this->massageValue($val, $fieldDef);
540 540
 				}
541 541
 			}
542 542
 		}
543 543
 
544 544
 		if (empty($values))
545
-			return $execute?true:''; // no columns set
545
+			return $execute ? true : ''; // no columns set
546 546
 
547 547
 		// get the entire sql
548 548
 		$query = "INSERT INTO $table (".implode(",", array_keys($values)).")
549 549
 					VALUES (".implode(",", $values).")";
550
-		return $execute?$this->query($query):$query;
550
+		return $execute ? $this->query($query) : $query;
551 551
 	}
552 552
 
553 553
     /**
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		$sql = $this->updateSQL($bean, $where);
566 566
 		$tablename = $bean->getTableName();
567 567
 		$msg = "Error updating table: $tablename:";
568
-		return $this->query($sql,true,$msg);
568
+		return $this->query($sql, true, $msg);
569 569
 	}
570 570
 
571 571
     /**
@@ -581,8 +581,8 @@  discard block
 block discarded – undo
581 581
 	{
582 582
 		$sql = $this->deleteSQL($bean, $where);
583 583
 		$tableName = $bean->getTableName();
584
-		$msg = "Error deleting from table: ".$tableName. ":";
585
-		return $this->query($sql,true,$msg);
584
+		$msg = "Error deleting from table: ".$tableName.":";
585
+		return $this->query($sql, true, $msg);
586 586
 	}
587 587
 
588 588
 	/**
@@ -599,8 +599,8 @@  discard block
 block discarded – undo
599 599
 	{
600 600
 		$sql = $this->retrieveSQL($bean, $where);
601 601
 		$tableName = $bean->getTableName();
602
-		$msg = "Error retriving values from table:".$tableName. ":";
603
-		return $this->query($sql,true,$msg);
602
+		$msg = "Error retriving values from table:".$tableName.":";
603
+		return $this->query($sql, true, $msg);
604 604
 	}
605 605
 
606 606
 	/**
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 	{
624 624
 		$sql = $this->retrieveViewSQL($beans, $cols, $where);
625 625
 		$msg = "Error retriving values from View Collection:";
626
-		return $this->query($sql,true,$msg);
626
+		return $this->query($sql, true, $msg);
627 627
 	}
628 628
 
629 629
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 		$sql = $this->createTableSQL($bean);
639 639
 		$tablename = $bean->getTableName();
640 640
 		$msg = "Error creating table: $tablename:";
641
-		$this->query($sql,true,$msg);
642
-		if(!$this->supports("inline_keys")) {
641
+		$this->query($sql, true, $msg);
642
+		if (!$this->supports("inline_keys")) {
643 643
 		// handle constraints and indices
644 644
 			$indicesArr = $this->createConstraintSql($bean);
645 645
 			if (count($indicesArr) > 0)
@@ -676,9 +676,9 @@  discard block
 block discarded – undo
676 676
 			$res = true;
677 677
 			if ($sql) {
678 678
 				$msg = "Error creating table: $tablename";
679
-				$res = ($res and $this->query($sql,true,$msg));
679
+				$res = ($res and $this->query($sql, true, $msg));
680 680
 			}
681
-			if(!$this->supports("inline_keys")) {
681
+			if (!$this->supports("inline_keys")) {
682 682
 				// handle constraints and indices
683 683
 				$indicesArr = $this->getConstraintSql($indices, $tablename);
684 684
 				if (count($indicesArr) > 0)
@@ -705,20 +705,20 @@  discard block
 block discarded – undo
705 705
 
706 706
 		//Clean the indexes to prevent duplicate definitions
707 707
 		$new_index = array();
708
-		foreach($indices as $ind_def){
708
+		foreach ($indices as $ind_def) {
709 709
 			$new_index[$ind_def['name']] = $ind_def;
710 710
 		}
711 711
 		//jc: added this for beans that do not actually have a table, namely
712 712
 		//ForecastOpportunities
713
-		if($tablename == 'does_not_exist' || $tablename == '')
713
+		if ($tablename == 'does_not_exist' || $tablename == '')
714 714
 			return '';
715 715
 
716 716
 		global $dictionary;
717
-		$engine=null;
718
-		if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) )
717
+		$engine = null;
718
+		if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']))
719 719
 			$engine = $dictionary[$bean->getObjectName()]['engine'];
720 720
 
721
-		return $this->repairTableParams($tablename, $fielddefs,$new_index,$execute,$engine);
721
+		return $this->repairTableParams($tablename, $fielddefs, $new_index, $execute, $engine);
722 722
 	}
723 723
 
724 724
 	/**
@@ -730,12 +730,12 @@  discard block
 block discarded – undo
730 730
 	protected function isNullable($vardef)
731 731
 	{
732 732
 
733
-		if(isset($vardef['isnull']) && (strtolower($vardef['isnull']) == 'false' || $vardef['isnull'] === false)
733
+		if (isset($vardef['isnull']) && (strtolower($vardef['isnull']) == 'false' || $vardef['isnull'] === false)
734 734
 			&& !empty($vardef['required'])) {
735 735
 				/* required + is_null=false => not null */
736 736
 			return false;
737 737
 		}
738
-		if(empty($vardef['auto_increment']) && (empty($vardef['type']) || $vardef['type'] != 'id')
738
+		if (empty($vardef['auto_increment']) && (empty($vardef['type']) || $vardef['type'] != 'id')
739 739
 					&& (empty($vardef['dbType']) || $vardef['dbType'] != 'id')
740 740
 					&& (empty($vardef['name']) || ($vardef['name'] != 'id' && $vardef['name'] != 'deleted'))
741 741
 		) {
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
      * @todo: refactor engine param to be more generic
757 757
      * @return string
758 758
      */
759
-	public function repairTableParams($tablename, $fielddefs,  $indices, $execute = true, $engine = null)
759
+	public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null)
760 760
 	{
761 761
 		//jc: had a bug when running the repair if the tablename is blank the repair will
762 762
 		//fail when it tries to create a repair table
@@ -766,13 +766,13 @@  discard block
 block discarded – undo
766 766
 		//if the table does not exist create it and we are done
767 767
 		$sql = "/* Table : $tablename */\n";
768 768
 		if (!$this->tableExists($tablename)) {
769
-			$createtablesql = $this->createTableSQLParams($tablename,$fielddefs,$indices,$engine);
770
-			if($execute && $createtablesql){
771
-				$this->createTableParams($tablename,$fielddefs,$indices,$engine);
769
+			$createtablesql = $this->createTableSQLParams($tablename, $fielddefs, $indices, $engine);
770
+			if ($execute && $createtablesql) {
771
+				$this->createTableParams($tablename, $fielddefs, $indices, $engine);
772 772
 			}
773 773
 
774 774
 			$sql .= "/* MISSING TABLE: {$tablename} */\n";
775
-			$sql .= $createtablesql . "\n";
775
+			$sql .= $createtablesql."\n";
776 776
 			return $sql;
777 777
 		}
778 778
 
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 		$take_action = false;
783 783
 
784 784
 		// do column comparisons
785
-		$sql .=	"/*COLUMNS*/\n";
785
+		$sql .= "/*COLUMNS*/\n";
786 786
 		foreach ($fielddefs as $name => $value) {
787 787
 			if (isset($value['source']) && $value['source'] != 'db')
788 788
 				continue;
@@ -801,9 +801,9 @@  discard block
 block discarded – undo
801 801
 
802 802
 			$name = strtolower($value['name']);
803 803
 			// add or fix the field defs per what the DB is expected to give us back
804
-			$this->massageFieldDef($value,$tablename);
804
+			$this->massageFieldDef($value, $tablename);
805 805
 
806
-			$ignorerequired=false;
806
+			$ignorerequired = false;
807 807
 
808 808
 			//Do not track requiredness in the DB, auto_increment, ID,
809 809
 			// and deleted fields are always required in the DB, so don't force those
@@ -819,32 +819,32 @@  discard block
 block discarded – undo
819 819
 				$value['required'] = $compareFieldDefs[$name]['required'];
820 820
 			}
821 821
 
822
-			if ( !isset($compareFieldDefs[$name]) ) {
822
+			if (!isset($compareFieldDefs[$name])) {
823 823
 				// ok we need this field lets create it
824
-				$sql .=	"/*MISSING IN DATABASE - $name -  ROW*/\n";
825
-				$sql .= $this->addColumnSQL($tablename, $value) .  "\n";
824
+				$sql .= "/*MISSING IN DATABASE - $name -  ROW*/\n";
825
+				$sql .= $this->addColumnSQL($tablename, $value)."\n";
826 826
 				if ($execute)
827 827
 					$this->addColumn($tablename, $value);
828 828
 				$take_action = true;
829
-			} elseif ( !$this->compareVarDefs($compareFieldDefs[$name],$value)) {
829
+			} elseif (!$this->compareVarDefs($compareFieldDefs[$name], $value)) {
830 830
 				//fields are different lets alter it
831
-				$sql .=	"/*MISMATCH WITH DATABASE - $name -  ROW ";
832
-				foreach($compareFieldDefs[$name] as $rKey => $rValue) {
833
-					$sql .=	"[$rKey] => '$rValue'  ";
831
+				$sql .= "/*MISMATCH WITH DATABASE - $name -  ROW ";
832
+				foreach ($compareFieldDefs[$name] as $rKey => $rValue) {
833
+					$sql .= "[$rKey] => '$rValue'  ";
834 834
 				}
835
-				$sql .=	"*/\n";
836
-				$sql .=	"/* VARDEF - $name -  ROW";
837
-				foreach($value as $rKey => $rValue) {
838
-					$sql .=	"[$rKey] => '$rValue'  ";
835
+				$sql .= "*/\n";
836
+				$sql .= "/* VARDEF - $name -  ROW";
837
+				foreach ($value as $rKey => $rValue) {
838
+					$sql .= "[$rKey] => '$rValue'  ";
839 839
 				}
840
-				$sql .=	"*/\n";
840
+				$sql .= "*/\n";
841 841
 
842 842
 				//jc: oracle will complain if you try to execute a statement that sets a column to (not) null
843 843
 				//when it is already (not) null
844
-				if ( isset($value['isnull']) && isset($compareFieldDefs[$name]['isnull']) &&
844
+				if (isset($value['isnull']) && isset($compareFieldDefs[$name]['isnull']) &&
845 845
 					$value['isnull'] === $compareFieldDefs[$name]['isnull']) {
846 846
 					unset($value['required']);
847
-					$ignorerequired=true;
847
+					$ignorerequired = true;
848 848
 				}
849 849
 
850 850
 				//dwheeler: Once a column has been defined as null, we cannot try to force it back to !null
@@ -853,12 +853,12 @@  discard block
 block discarded – undo
853 853
 				{
854 854
 					$ignorerequired = true;
855 855
 				}
856
-				$altersql = $this->alterColumnSQL($tablename, $value,$ignorerequired);
857
-				if(is_array($altersql)) {
856
+				$altersql = $this->alterColumnSQL($tablename, $value, $ignorerequired);
857
+				if (is_array($altersql)) {
858 858
 					$altersql = join("\n", $altersql);
859 859
 				}
860
-				$sql .= $altersql .  "\n";
861
-				if($execute){
860
+				$sql .= $altersql."\n";
861
+				if ($execute) {
862 862
 					$this->alterColumn($tablename, $value, $ignorerequired);
863 863
 				}
864 864
 				$take_action = true;
@@ -866,13 +866,13 @@  discard block
 block discarded – undo
866 866
 		}
867 867
 
868 868
 		// do index comparisons
869
-		$sql .=	"/* INDEXES */\n";
869
+		$sql .= "/* INDEXES */\n";
870 870
 		$correctedIndexs = array();
871 871
 
872 872
         $compareIndices_case_insensitive = array();
873 873
 
874 874
 		// do indices comparisons case-insensitive
875
-		foreach($compareIndices as $k => $value){
875
+		foreach ($compareIndices as $k => $value) {
876 876
 			$value['name'] = strtolower($value['name']);
877 877
 			$compareIndices_case_insensitive[strtolower($k)] = $value;
878 878
 		}
@@ -899,59 +899,59 @@  discard block
 block discarded – undo
899 899
 				continue;
900 900
 
901 901
 			//database helpers do not know how to handle full text indices
902
-			if ($value['type']=='fulltext')
902
+			if ($value['type'] == 'fulltext')
903 903
 				continue;
904 904
 
905
-			if ( in_array($value['type'],array('alternate_key','foreign')) )
905
+			if (in_array($value['type'], array('alternate_key', 'foreign')))
906 906
 				$value['type'] = 'index';
907 907
 
908
-			if ( !isset($compareIndices[$name]) ) {
908
+			if (!isset($compareIndices[$name])) {
909 909
 				//First check if an index exists that doesn't match our name, if so, try to rename it
910 910
 				$found = false;
911 911
 				foreach ($compareIndices as $ex_name => $ex_value) {
912
-					if($this->compareVarDefs($ex_value, $value, true)) {
912
+					if ($this->compareVarDefs($ex_value, $value, true)) {
913 913
 						$found = $ex_name;
914 914
 						break;
915 915
 					}
916 916
 				}
917 917
 				if ($found) {
918
-					$sql .=	 "/*MISSNAMED INDEX IN DATABASE - $name - $ex_name */\n";
918
+					$sql .= "/*MISSNAMED INDEX IN DATABASE - $name - $ex_name */\n";
919 919
 					$rename = $this->renameIndexDefs($ex_value, $value, $tablename);
920
-					if($execute) {
920
+					if ($execute) {
921 921
 						$this->query($rename, true, "Cannot rename index");
922 922
 					}
923
-					$sql .= is_array($rename)?join("\n", $rename). "\n":$rename."\n";
923
+					$sql .= is_array($rename) ? join("\n", $rename)."\n" : $rename."\n";
924 924
 
925 925
 				} else {
926 926
 					// ok we need this field lets create it
927
-					$sql .=	 "/*MISSING INDEX IN DATABASE - $name -{$value['type']}  ROW */\n";
928
-					$sql .= $this->addIndexes($tablename,array($value), $execute) .  "\n";
927
+					$sql .= "/*MISSING INDEX IN DATABASE - $name -{$value['type']}  ROW */\n";
928
+					$sql .= $this->addIndexes($tablename, array($value), $execute)."\n";
929 929
 				}
930 930
 				$take_action = true;
931 931
 				$correctedIndexs[$name] = true;
932
-			} elseif ( !$this->compareVarDefs($compareIndices[$name],$value) ) {
932
+			} elseif (!$this->compareVarDefs($compareIndices[$name], $value)) {
933 933
 				// fields are different lets alter it
934
-				$sql .=	"/*INDEX MISMATCH WITH DATABASE - $name -  ROW ";
934
+				$sql .= "/*INDEX MISMATCH WITH DATABASE - $name -  ROW ";
935 935
 				foreach ($compareIndices[$name] as $n1 => $t1) {
936
-					$sql .=	 "<$n1>";
937
-					if ( $n1 == 'fields' )
938
-						foreach($t1 as $rKey => $rValue)
936
+					$sql .= "<$n1>";
937
+					if ($n1 == 'fields')
938
+						foreach ($t1 as $rKey => $rValue)
939 939
 							$sql .= "[$rKey] => '$rValue'  ";
940 940
 					else
941 941
 						$sql .= " $t1 ";
942 942
 				}
943
-				$sql .=	"*/\n";
944
-				$sql .=	"/* VARDEF - $name -  ROW";
943
+				$sql .= "*/\n";
944
+				$sql .= "/* VARDEF - $name -  ROW";
945 945
 				foreach ($value as $n1 => $t1) {
946
-					$sql .=	"<$n1>";
947
-					if ( $n1 == 'fields' )
946
+					$sql .= "<$n1>";
947
+					if ($n1 == 'fields')
948 948
 						foreach ($t1 as $rKey => $rValue)
949
-							$sql .=	"[$rKey] => '$rValue'  ";
949
+							$sql .= "[$rKey] => '$rValue'  ";
950 950
 					else
951 951
 						$sql .= " $t1 ";
952 952
 				}
953
-				$sql .=	"*/\n";
954
-				$sql .= $this->modifyIndexes($tablename,array($value), $execute) .  "\n";
953
+				$sql .= "*/\n";
954
+				$sql .= $this->modifyIndexes($tablename, array($value), $execute)."\n";
955 955
 				$take_action = true;
956 956
 				$correctedIndexs[$name] = true;
957 957
 			}
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
      */
971 971
 	public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false)
972 972
 	{
973
-		foreach ( $fielddef1 as $key => $value ) {
973
+		foreach ($fielddef1 as $key => $value) {
974 974
 			if ($key == 'name' && $ignoreName)
975 975
 				continue;
976 976
             if (isset($fielddef2[$key]))
@@ -984,7 +984,7 @@  discard block
 block discarded – undo
984 984
                 }
985 985
                 else
986 986
                 {
987
-                    if (array_map('strtolower', $fielddef1[$key]) == array_map('strtolower',$fielddef2[$key]))
987
+                    if (array_map('strtolower', $fielddef1[$key]) == array_map('strtolower', $fielddef2[$key]))
988 988
                     {
989 989
                         continue;
990 990
                     }
@@ -1033,9 +1033,9 @@  discard block
 block discarded – undo
1033 1033
 				}
1034 1034
 				else {
1035 1035
 					$returnArray['msg'] = 'match';
1036
-					foreach($row1 as $key => $value){
1036
+					foreach ($row1 as $key => $value) {
1037 1037
 						//ignore keys when checking we will check them when we do the index check
1038
-						if( !isset($ignore_filter[$key]) && (!isset($row2[$key]) || $row1[$key] !== $row2[$key])){
1038
+						if (!isset($ignore_filter[$key]) && (!isset($row2[$key]) || $row1[$key] !== $row2[$key])) {
1039 1039
 							$returnArray['msg'] = 'no_match';
1040 1040
 						}
1041 1041
 					}
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
 		$sql = $this->createIndexSQL($bean, $fieldDefs, $name, $unique);
1112 1112
 		$tablename = $bean->getTableName();
1113 1113
 		$msg = "Error creating index $name on table: $tablename:";
1114
-		return $this->query($sql,true,$msg);
1114
+		return $this->query($sql, true, $msg);
1115 1115
 	}
1116 1116
 
1117 1117
 	/**
@@ -1128,14 +1128,14 @@  discard block
 block discarded – undo
1128 1128
 		$columns = array();
1129 1129
 
1130 1130
 		foreach ($indices as $index) {
1131
-			if(!empty($index['db']) && $index['db'] != $this->dbType)
1131
+			if (!empty($index['db']) && $index['db'] != $this->dbType)
1132 1132
 				continue;
1133 1133
 			if (isset($index['source']) && $index['source'] != 'db')
1134 1134
 			continue;
1135 1135
 
1136 1136
 			$sql = $this->add_drop_constraint($table, $index);
1137 1137
 
1138
-			if(!empty($sql)) {
1138
+			if (!empty($sql)) {
1139 1139
 				$columns[] = $sql;
1140 1140
 			}
1141 1141
 		}
@@ -1155,11 +1155,11 @@  discard block
 block discarded – undo
1155 1155
 	{
1156 1156
 		$alters = $this->getConstraintSql($indexes, $tablename);
1157 1157
 		if ($execute) {
1158
-			foreach($alters as $sql) {
1158
+			foreach ($alters as $sql) {
1159 1159
 				$this->query($sql, true, "Error adding index: ");
1160 1160
 			}
1161 1161
 		}
1162
-		if(!empty($alters)) {
1162
+		if (!empty($alters)) {
1163 1163
 			$sql = join(";\n", $alters).";\n";
1164 1164
 		} else {
1165 1165
 			$sql = '';
@@ -1179,17 +1179,17 @@  discard block
 block discarded – undo
1179 1179
 	{
1180 1180
 		$sqls = array();
1181 1181
 		foreach ($indexes as $index) {
1182
-			$name =$index['name'];
1183
-			$sqls[$name] = $this->add_drop_constraint($tablename,$index,true);
1182
+			$name = $index['name'];
1183
+			$sqls[$name] = $this->add_drop_constraint($tablename, $index, true);
1184 1184
 		}
1185 1185
 		if (!empty($sqls) && $execute) {
1186
-			foreach($sqls as $name => $sql) {
1186
+			foreach ($sqls as $name => $sql) {
1187 1187
 				unset(self::$index_descriptions[$tablename][$name]);
1188 1188
 				$this->query($sql);
1189 1189
 			}
1190 1190
 		}
1191
-		if(!empty($sqls)) {
1192
-			return join(";\n",$sqls).";";
1191
+		if (!empty($sqls)) {
1192
+			return join(";\n", $sqls).";";
1193 1193
 		} else {
1194 1194
 			return '';
1195 1195
 		}
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 	public function addColumn($tablename, $fieldDefs)
1220 1220
 	{
1221 1221
 		$sql = $this->addColumnSQL($tablename, $fieldDefs);
1222
-		if ($this->isFieldArray($fieldDefs)){
1222
+		if ($this->isFieldArray($fieldDefs)) {
1223 1223
 			$columns = array();
1224 1224
 			foreach ($fieldDefs as $fieldDef)
1225 1225
 				$columns[] = $fieldDef['name'];
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 			$columns = $fieldDefs['name'];
1230 1230
 		}
1231 1231
 		$msg = "Error adding column(s) $columns on table: $tablename:";
1232
-		return $this->query($sql,true,$msg);
1232
+		return $this->query($sql, true, $msg);
1233 1233
 	}
1234 1234
 
1235 1235
 	/**
@@ -1242,8 +1242,8 @@  discard block
 block discarded – undo
1242 1242
      */
1243 1243
 	public function alterColumn($tablename, $newFieldDef, $ignoreRequired = false)
1244 1244
 	{
1245
-		$sql = $this->alterColumnSQL($tablename, $newFieldDef,$ignoreRequired);
1246
-		if ($this->isFieldArray($newFieldDef)){
1245
+		$sql = $this->alterColumnSQL($tablename, $newFieldDef, $ignoreRequired);
1246
+		if ($this->isFieldArray($newFieldDef)) {
1247 1247
 			$columns = array();
1248 1248
 			foreach ($newFieldDef as $fieldDef) {
1249 1249
 				$columns[] = $fieldDef['name'];
@@ -1255,8 +1255,8 @@  discard block
 block discarded – undo
1255 1255
 		}
1256 1256
 
1257 1257
 		$msg = "Error altering column(s) $columns on table: $tablename:";
1258
-		$res = $this->query($sql,true,$msg);
1259
-		if($res) {
1258
+		$res = $this->query($sql, true, $msg);
1259
+		if ($res) {
1260 1260
 			$this->getTableDescription($tablename, true); // reload table description after altering
1261 1261
 		}
1262 1262
 		return $res;
@@ -1282,7 +1282,7 @@  discard block
 block discarded – undo
1282 1282
 	public function dropTableName($name)
1283 1283
 	{
1284 1284
 		$sql = $this->dropTableNameSQL($name);
1285
-		return $this->query($sql,true,"Error dropping table $name:");
1285
+		return $this->query($sql, true, "Error dropping table $name:");
1286 1286
 	}
1287 1287
 
1288 1288
     /**
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 		$tablename = $bean->getTableName();
1298 1298
 		$sql = $this->dropColumnSQL($tablename, $fieldDefs);
1299 1299
 		$msg = "Error deleting column(s) on table: $tablename:";
1300
-		return $this->query($sql,true,$msg);
1300
+		return $this->query($sql, true, $msg);
1301 1301
 	}
1302 1302
 
1303 1303
     /**
@@ -1320,18 +1320,18 @@  discard block
 block discarded – undo
1320 1320
 
1321 1321
 		$rows_found = 0;
1322 1322
 		$count_query = $bean->create_list_count_query($select_query);
1323
-		if(!empty($count_query))
1323
+		if (!empty($count_query))
1324 1324
 		{
1325 1325
 			// We have a count query.  Run it and get the results.
1326 1326
 			$result = $this->query($count_query, true, "Error running count query for $this->object_name List: ");
1327 1327
 			$assoc = $this->fetchByAssoc($result);
1328
-			if(!empty($assoc['c']))
1328
+			if (!empty($assoc['c']))
1329 1329
 			{
1330 1330
 				$rows_found = $assoc['c'];
1331 1331
 			}
1332 1332
 		}
1333
-		if($count == -1){
1334
-			$count 	= $sugar_config['list_max_entries_per_page'];
1333
+		if ($count == -1) {
1334
+			$count = $sugar_config['list_max_entries_per_page'];
1335 1335
 		}
1336 1336
 		$next_offset = $start + $count;
1337 1337
 
@@ -1344,13 +1344,13 @@  discard block
 block discarded – undo
1344 1344
 		$fields = $bean->getFieldDefinitions();
1345 1345
 		$custom_fields = array();
1346 1346
 
1347
-		if($bean->hasCustomFields()){
1348
-			foreach ($fields as $fieldDef){
1349
-				if($fieldDef['source'] == 'custom_fields'){
1347
+		if ($bean->hasCustomFields()) {
1348
+			foreach ($fields as $fieldDef) {
1349
+				if ($fieldDef['source'] == 'custom_fields') {
1350 1350
 					$custom_fields[$fieldDef['name']] = $fieldDef['name'];
1351 1351
 				}
1352 1352
 			}
1353
-			if(!empty($custom_fields)){
1353
+			if (!empty($custom_fields)) {
1354 1354
 				$custom_fields['id_c'] = 'id_c';
1355 1355
 				$id_field = array('name' => 'id_c', 'custom_type' => 'id',);
1356 1356
 				$fields[] = $id_field;
@@ -1363,50 +1363,50 @@  discard block
 block discarded – undo
1363 1363
 		$cstm_row_array = array();
1364 1364
 		$cstm_columns = array();
1365 1365
 		$built_columns = false;
1366
-		while(($row = $this->fetchByAssoc($result)) != null)
1366
+		while (($row = $this->fetchByAssoc($result)) != null)
1367 1367
 		{
1368 1368
 			$values = array();
1369 1369
 			$cstm_values = array();
1370
-			if(!$is_related_query){
1370
+			if (!$is_related_query) {
1371 1371
 				foreach ($fields as $fieldDef)
1372 1372
 				{
1373
-					if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue;
1373
+					if (isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue;
1374 1374
 					$val = $row[$fieldDef['name']];
1375 1375
 
1376 1376
 					//handle auto increment values here only need to do this on insert not create
1377
-					if ($fieldDef['name'] == 'deleted'){
1377
+					if ($fieldDef['name'] == 'deleted') {
1378 1378
 							$values['deleted'] = $val;
1379
-							if(!$built_columns){
1379
+							if (!$built_columns) {
1380 1380
 							$columns[] = 'deleted';
1381 1381
 						}
1382 1382
 					}
1383 1383
 					else
1384 1384
 					{
1385 1385
 						$type = $fieldDef['type'];
1386
-						if(!empty($fieldDef['custom_type'])){
1386
+						if (!empty($fieldDef['custom_type'])) {
1387 1387
 							$type = $fieldDef['custom_type'];
1388 1388
 						}
1389 1389
 						// need to do some thing about types of values
1390
-						if($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' ||  $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')){
1391
-							if(!empty($custom_fields[$fieldDef['name']]))
1390
+						if ($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')) {
1391
+							if (!empty($custom_fields[$fieldDef['name']]))
1392 1392
 								$cstm_values[$fieldDef['name']] = 'null';
1393 1393
 							else
1394 1394
 								$values[$fieldDef['name']] = 'null';
1395
-						}else{
1396
-							if(isset($type) && $type=='int') {
1397
-								if(!empty($custom_fields[$fieldDef['name']]))
1395
+						} else {
1396
+							if (isset($type) && $type == 'int') {
1397
+								if (!empty($custom_fields[$fieldDef['name']]))
1398 1398
 									$cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val));
1399 1399
 								else
1400 1400
 									$values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val));
1401 1401
 							} else {
1402
-								if(!empty($custom_fields[$fieldDef['name']]))
1402
+								if (!empty($custom_fields[$fieldDef['name']]))
1403 1403
 									$cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'";
1404 1404
 								else
1405 1405
 									$values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'";
1406 1406
 							}
1407 1407
 						}
1408
-						if(!$built_columns){
1409
-							if(!empty($custom_fields[$fieldDef['name']]))
1408
+						if (!$built_columns) {
1409
+							if (!empty($custom_fields[$fieldDef['name']]))
1410 1410
 								$cstm_columns[] = $fieldDef['name'];
1411 1411
 							else
1412 1412
 								$columns[] = $fieldDef['name'];
@@ -1417,19 +1417,19 @@  discard block
 block discarded – undo
1417 1417
 			} else {
1418 1418
 			foreach ($row as $key=>$val)
1419 1419
 			{
1420
-					if($key != 'orc_row'){
1420
+					if ($key != 'orc_row') {
1421 1421
 						$values[$key] = "'$val'";
1422
-						if(!$built_columns){
1422
+						if (!$built_columns) {
1423 1423
 							$columns[] = $key;
1424 1424
 						}
1425 1425
 					}
1426 1426
 			}
1427 1427
 			}
1428 1428
 			$built_columns = true;
1429
-			if(!empty($values)){
1429
+			if (!empty($values)) {
1430 1430
 				$row_array[] = $values;
1431 1431
 			}
1432
-			if(!empty($cstm_values) && !empty($cstm_values['id_c']) && (strlen($cstm_values['id_c']) > 7)){
1432
+			if (!empty($cstm_values) && !empty($cstm_values['id_c']) && (strlen($cstm_values['id_c']) > 7)) {
1433 1433
 				$cstm_row_array[] = $cstm_values;
1434 1434
 			}
1435 1435
 		}
@@ -1439,9 +1439,9 @@  discard block
 block discarded – undo
1439 1439
 		// get the entire sql
1440 1440
 		$sql .= "(".implode(",", $columns).") ";
1441 1441
 		$sql .= "VALUES";
1442
-		for($i = 0; $i < count($row_array); $i++){
1442
+		for ($i = 0; $i < count($row_array); $i++) {
1443 1443
 			$sql .= " (".implode(",", $row_array[$i]).")";
1444
-			if($i < (count($row_array) - 1)){
1444
+			if ($i < (count($row_array) - 1)) {
1445 1445
 				$sql .= ", ";
1446 1446
 			}
1447 1447
 		}
@@ -1450,9 +1450,9 @@  discard block
 block discarded – undo
1450 1450
 		$custom_sql .= "(".implode(",", $cstm_columns).") ";
1451 1451
 		$custom_sql .= "VALUES";
1452 1452
 
1453
-		for($i = 0; $i < count($cstm_row_array); $i++){
1453
+		for ($i = 0; $i < count($cstm_row_array); $i++) {
1454 1454
 			$custom_sql .= " (".implode(",", $cstm_row_array[$i]).")";
1455
-			if($i < (count($cstm_row_array) - 1)){
1455
+			if ($i < (count($cstm_row_array) - 1)) {
1456 1456
 				$custom_sql .= ", ";
1457 1457
 			}
1458 1458
 		}
@@ -1545,17 +1545,17 @@  discard block
 block discarded – undo
1545 1545
      */
1546 1546
     public function quoteType($type, $value)
1547 1547
 	{
1548
-	    if($type == 'date') {
1548
+	    if ($type == 'date') {
1549 1549
 	        return $this->convert($this->quoted($value), "date");
1550 1550
 	    }
1551
-	    if($type == 'time') {
1551
+	    if ($type == 'time') {
1552 1552
 	        return $this->convert($this->quoted($value), "time");
1553 1553
 	    }
1554
-        if(isset($this->type_class[$type]) &&  $this->type_class[$type] == "date") {
1554
+        if (isset($this->type_class[$type]) && $this->type_class[$type] == "date") {
1555 1555
             return $this->convert($this->quoted($value), "datetime");
1556 1556
         }
1557
-        if($this->isNumericType($type)) {
1558
-            return 0+$value; // ensure it's numeric
1557
+        if ($this->isNumericType($type)) {
1558
+            return 0 + $value; // ensure it's numeric
1559 1559
         }
1560 1560
 
1561 1561
         return $this->quoted($value);
@@ -1571,7 +1571,7 @@  discard block
 block discarded – undo
1571 1571
      */
1572 1572
 	public function arrayQuote(array &$array)
1573 1573
 	{
1574
-		foreach($array as &$val) {
1574
+		foreach ($array as &$val) {
1575 1575
 			$val = $this->quote($val);
1576 1576
 		}
1577 1577
 		return $array;
@@ -1584,10 +1584,10 @@  discard block
 block discarded – undo
1584 1584
      */
1585 1585
 	protected function freeResult($result = false)
1586 1586
 	{
1587
-		if($result) {
1587
+		if ($result) {
1588 1588
 			$this->freeDbResult($result);
1589 1589
 		}
1590
-		if($this->lastResult) {
1590
+		if ($this->lastResult) {
1591 1591
 			$this->freeDbResult($this->lastResult);
1592 1592
 			$this->lastResult = null;
1593 1593
 		}
@@ -1616,17 +1616,17 @@  discard block
 block discarded – undo
1616 1616
 	public function getOne($sql, $dieOnError = false, $msg = '')
1617 1617
 	{
1618 1618
 		$this->log->info("Get One: |$sql|");
1619
-		if(!$this->hasLimit($sql)) {
1619
+		if (!$this->hasLimit($sql)) {
1620 1620
 		    $queryresult = $this->limitQuery($sql, 0, 1, $dieOnError, $msg);
1621 1621
 		} else {
1622 1622
 		    // support old code that passes LIMIT to sql
1623 1623
 		    // works only for mysql, so do not rely on this
1624 1624
 		    $queryresult = $this->query($sql, $dieOnError, $msg);
1625 1625
 		}
1626
-		$this->checkError($msg.' Get One Failed:' . $sql, $dieOnError);
1626
+		$this->checkError($msg.' Get One Failed:'.$sql, $dieOnError);
1627 1627
 		if (!$queryresult) return false;
1628 1628
 		$row = $this->fetchByAssoc($queryresult);
1629
-		if(!empty($row)) {
1629
+		if (!empty($row)) {
1630 1630
 			return array_shift($row);
1631 1631
 		}
1632 1632
 		return false;
@@ -1646,12 +1646,12 @@  discard block
 block discarded – undo
1646 1646
 		$this->log->info("Fetch One: |$sql|");
1647 1647
 		$this->checkConnection();
1648 1648
 		$queryresult = $this->query($sql, $dieOnError, $msg);
1649
-		$this->checkError($msg.' Fetch One Failed:' . $sql, $dieOnError);
1649
+		$this->checkError($msg.' Fetch One Failed:'.$sql, $dieOnError);
1650 1650
 
1651 1651
 		if (!$queryresult) return false;
1652 1652
 
1653 1653
 		$row = $this->fetchByAssoc($queryresult);
1654
-		if ( !$row ) return false;
1654
+		if (!$row) return false;
1655 1655
 
1656 1656
 		$this->freeResult($queryresult);
1657 1657
 		return $row;
@@ -1692,7 +1692,7 @@  discard block
 block discarded – undo
1692 1692
      */
1693 1693
 	public function getTableDescription($tablename, $reload = false)
1694 1694
 	{
1695
-		if($reload || empty(self::$table_descriptions[$tablename])) {
1695
+		if ($reload || empty(self::$table_descriptions[$tablename])) {
1696 1696
 			self::$table_descriptions[$tablename] = $this->get_columns($tablename);
1697 1697
 		}
1698 1698
 		return self::$table_descriptions[$tablename];
@@ -1708,12 +1708,12 @@  discard block
 block discarded – undo
1708 1708
 	protected function describeField($name, $tablename)
1709 1709
 	{
1710 1710
 		$table = $this->getTableDescription($tablename);
1711
-		if(!empty($table) && isset($table[$name]))
1711
+		if (!empty($table) && isset($table[$name]))
1712 1712
 			return 	$table[$name];
1713 1713
 
1714 1714
 		$table = $this->getTableDescription($tablename, true);
1715 1715
 
1716
-		if(isset($table[$name]))
1716
+		if (isset($table[$name]))
1717 1717
 		return $table[$name];
1718 1718
 
1719 1719
 		return array();
@@ -1728,13 +1728,13 @@  discard block
 block discarded – undo
1728 1728
 	 */
1729 1729
 	protected function describeIndex($name, $tablename)
1730 1730
 	{
1731
-		if(isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename][$name])){
1731
+		if (isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename][$name])) {
1732 1732
 			return 	self::$index_descriptions[$tablename][$name];
1733 1733
 		}
1734 1734
 
1735 1735
 		self::$index_descriptions[$tablename] = $this->get_indices($tablename);
1736 1736
 
1737
-		if(isset(self::$index_descriptions[$tablename][$name])){
1737
+		if (isset(self::$index_descriptions[$tablename][$name])) {
1738 1738
 			return 	self::$index_descriptions[$tablename][$name];
1739 1739
 		}
1740 1740
 
@@ -1751,9 +1751,9 @@  discard block
 block discarded – undo
1751 1751
      */
1752 1752
 	public function truncate($string, $len)
1753 1753
 	{
1754
-		if ( is_numeric($len) && $len > 0)
1754
+		if (is_numeric($len) && $len > 0)
1755 1755
 		{
1756
-			$string = mb_substr($string,0,(int) $len, "UTF-8");
1756
+			$string = mb_substr($string, 0, (int)$len, "UTF-8");
1757 1757
 		}
1758 1758
 		return $string;
1759 1759
 	}
@@ -1768,11 +1768,11 @@  discard block
 block discarded – undo
1768 1768
      */
1769 1769
 	public function concat($table, array $fields, $space = ' ')
1770 1770
 	{
1771
-		if(empty($fields)) return '';
1771
+		if (empty($fields)) return '';
1772 1772
 		$elems = array();
1773 1773
 		$space = $this->quoted($space);
1774
-		foreach ( $fields as $field ) {
1775
-			if(!empty($elems)) $elems[] = $space;
1774
+		foreach ($fields as $field) {
1775
+			if (!empty($elems)) $elems[] = $space;
1776 1776
 			$elems[] = $this->convert("$table.$field", 'IFNULL', array("''"));
1777 1777
 		}
1778 1778
 		$first = array_shift($elems);
@@ -1829,8 +1829,8 @@  discard block
 block discarded – undo
1829 1829
 	 */
1830 1830
 	public function executePreparedQuery($stmt, $data = array())
1831 1831
 	{
1832
-		if(!empty($this->preparedTokens[$stmt])){
1833
-			if(!is_array($data)){
1832
+		if (!empty($this->preparedTokens[$stmt])) {
1833
+			if (!is_array($data)) {
1834 1834
 				$data = array($data);
1835 1835
 			}
1836 1836
 
@@ -1838,7 +1838,7 @@  discard block
 block discarded – undo
1838 1838
 
1839 1839
 			//ensure that the number of data elements matches the number of replacement tokens
1840 1840
 			//we found in prepare().
1841
-			if(count($data) != $pTokens['tokenCount']){
1841
+			if (count($data) != $pTokens['tokenCount']) {
1842 1842
 				//error the data count did not match the token count
1843 1843
 				return false;
1844 1844
 			}
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
 				}//switch
1865 1865
 			}//foreach
1866 1866
 			return $this->query($query);
1867
-		}else{
1867
+		} else {
1868 1868
 			return false;
1869 1869
 		}
1870 1870
 	}
@@ -1908,7 +1908,7 @@  discard block
 block discarded – undo
1908 1908
 	{
1909 1909
 		// get column names and values
1910 1910
 		$sql = $this->insertParams($bean->getTableName(), $bean->getFieldDefinitions(), get_object_vars($bean),
1911
-		        isset($bean->field_name_map)?$bean->field_name_map:null, false);
1911
+		        isset($bean->field_name_map) ? $bean->field_name_map : null, false);
1912 1912
 		return $sql;
1913 1913
 	}
1914 1914
 
@@ -1936,48 +1936,48 @@  discard block
 block discarded – undo
1936 1936
     		if (!empty($bean->field_name_map[$field]['auto_increment'])) continue;
1937 1937
 
1938 1938
     		//custom fields handle their save separately
1939
-    		if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type']))  continue;
1939
+    		if (isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type']))  continue;
1940 1940
 
1941 1941
     		// no need to clear deleted since we only update not deleted records anyway
1942
-    		if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue;
1942
+    		if ($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue;
1943 1943
 
1944
-    		if(isset($bean->$field)) {
1944
+    		if (isset($bean->$field)) {
1945 1945
     			$val = from_html($bean->$field);
1946 1946
     		} else {
1947 1947
     			continue;
1948 1948
     		}
1949 1949
 
1950
-    		if(!empty($fieldDef['type']) && $fieldDef['type'] == 'bool'){
1950
+    		if (!empty($fieldDef['type']) && $fieldDef['type'] == 'bool') {
1951 1951
     			$val = $bean->getFieldValue($field);
1952 1952
     		}
1953 1953
 
1954
-    		if(strlen($val) == 0) {
1955
-    			if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) {
1954
+    		if (strlen($val) == 0) {
1955
+    			if (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) {
1956 1956
     				$val = $fieldDef['default'];
1957 1957
     			} else {
1958 1958
     				$val = null;
1959 1959
     			}
1960 1960
     		}
1961 1961
 
1962
-    		if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) {
1962
+    		if (!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) {
1963 1963
 			    $val = $this->truncate($val, $fieldDef['len']);
1964 1964
 			}
1965 1965
 		$columnName = $this->quoteIdentifier($fieldDef['name']);
1966
-    		if(!is_null($val) || !empty($fieldDef['required'])) {
1966
+    		if (!is_null($val) || !empty($fieldDef['required'])) {
1967 1967
     			$columns[] = "{$columnName}=".$this->massageValue($val, $fieldDef);
1968
-    		} elseif($this->isNullable($fieldDef)) {
1968
+    		} elseif ($this->isNullable($fieldDef)) {
1969 1969
     			$columns[] = "{$columnName}=NULL";
1970 1970
     		} else {
1971 1971
     		    $columns[] = "{$columnName}=".$this->emptyValue($fieldDef['type']);
1972 1972
     		}
1973 1973
 		}
1974 1974
 
1975
-		if ( sizeof($columns) == 0 )
1975
+		if (sizeof($columns) == 0)
1976 1976
 			return ""; // no columns set
1977 1977
 
1978 1978
 		// build where clause
1979 1979
 		$where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where));
1980
-		if(isset($fields['deleted'])) {
1980
+		if (isset($fields['deleted'])) {
1981 1981
 		    $where .= " AND deleted=0";
1982 1982
 		}
1983 1983
 
@@ -2001,7 +2001,7 @@  discard block
 block discarded – undo
2001 2001
 			$primaryColumn = $fieldDef['name'];
2002 2002
 
2003 2003
 			$val = $bean->getFieldValue($fieldDef['name']);
2004
-			if ($val != FALSE){
2004
+			if ($val != FALSE) {
2005 2005
 				$where[$primaryColumn] = $val;
2006 2006
 			}
2007 2007
 		}
@@ -2027,7 +2027,7 @@  discard block
 block discarded – undo
2027 2027
 			if (is_array($val)) {
2028 2028
 				$op = "IN";
2029 2029
 				$temp = array();
2030
-				foreach ($val as $tval){
2030
+				foreach ($val as $tval) {
2031 2031
 					$temp[] = $this->quoted($tval);
2032 2032
 				}
2033 2033
 				$val = implode(",", $temp);
@@ -2053,9 +2053,9 @@  discard block
 block discarded – undo
2053 2053
 	 * @param  array  $whereArray Optional, where conditions in an array
2054 2054
 	 * @return string
2055 2055
 	 */
2056
-	protected function getWhereClause(SugarBean $bean, array $whereArray=array())
2056
+	protected function getWhereClause(SugarBean $bean, array $whereArray = array())
2057 2057
 	{
2058
-	    return " WHERE " . $this->getColumnWhereClause($bean->getTableName(), $whereArray);
2058
+	    return " WHERE ".$this->getColumnWhereClause($bean->getTableName(), $whereArray);
2059 2059
 	}
2060 2060
 
2061 2061
 	/**
@@ -2069,13 +2069,13 @@  discard block
 block discarded – undo
2069 2069
 	{
2070 2070
 		$type = $this->getFieldType($fieldDef);
2071 2071
 
2072
-		if(isset($this->type_class[$type])) {
2072
+		if (isset($this->type_class[$type])) {
2073 2073
 			// handle some known types
2074
-			switch($this->type_class[$type]) {
2074
+			switch ($this->type_class[$type]) {
2075 2075
 				case 'bool':
2076 2076
 				case 'int':
2077
-					if (!empty($fieldDef['required']) && $val == ''){
2078
-						if (isset($fieldDef['default'])){
2077
+					if (!empty($fieldDef['required']) && $val == '') {
2078
+						if (isset($fieldDef['default'])) {
2079 2079
 							return $fieldDef['default'];
2080 2080
 						}
2081 2081
 						return 0;
@@ -2083,16 +2083,16 @@  discard block
 block discarded – undo
2083 2083
 					return intval($val);
2084 2084
                 case 'bigint' :
2085 2085
                     $val = (float)$val;
2086
-					if (!empty($fieldDef['required']) && $val == false){
2087
-						if (isset($fieldDef['default'])){
2086
+					if (!empty($fieldDef['required']) && $val == false) {
2087
+						if (isset($fieldDef['default'])) {
2088 2088
 							return $fieldDef['default'];
2089 2089
 						}
2090 2090
 						return 0;
2091 2091
 					}
2092 2092
                     return $val;
2093 2093
 				case 'float':
2094
-					if (!empty($fieldDef['required'])  && $val == ''){
2095
-						if (isset($fieldDef['default'])){
2094
+					if (!empty($fieldDef['required']) && $val == '') {
2095
+						if (isset($fieldDef['default'])) {
2096 2096
 							return $fieldDef['default'];
2097 2097
 						}
2098 2098
 						return 0;
@@ -2101,7 +2101,7 @@  discard block
 block discarded – undo
2101 2101
 				case 'time':
2102 2102
 				case 'date':
2103 2103
 					// empty date can't be '', so convert it to either NULL or empty date value
2104
-					if($val == '') {
2104
+					if ($val == '') {
2105 2105
 						if (!empty($fieldDef['required'])) {
2106 2106
 							if (isset($fieldDef['default'])) {
2107 2107
 								return $fieldDef['default'];
@@ -2113,14 +2113,14 @@  discard block
 block discarded – undo
2113 2113
 					break;
2114 2114
 			}
2115 2115
 		} else {
2116
-		    if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) {
2116
+		    if (!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) {
2117 2117
 			    $val = $this->truncate($val, $fieldDef['len']);
2118 2118
 			}
2119 2119
 		}
2120 2120
 
2121
-		if ( is_null($val) ) {
2122
-			if(!empty($fieldDef['required'])) {
2123
-				if (isset($fieldDef['default'])  && $fieldDef['default'] != ''){
2121
+		if (is_null($val)) {
2122
+			if (!empty($fieldDef['required'])) {
2123
+				if (isset($fieldDef['default']) && $fieldDef['default'] != '') {
2124 2124
 					return $fieldDef['default'];
2125 2125
 				}
2126 2126
 				return $this->emptyValue($type);
@@ -2128,7 +2128,7 @@  discard block
 block discarded – undo
2128 2128
 				return "NULL";
2129 2129
 			}
2130 2130
 		}
2131
-        if($type == "datetimecombo") {
2131
+        if ($type == "datetimecombo") {
2132 2132
             $type = "datetime";
2133 2133
         }
2134 2134
 		return $this->convert($this->quoted($val), $type);
@@ -2143,23 +2143,23 @@  discard block
 block discarded – undo
2143 2143
 	 */
2144 2144
 	public function massageFieldDef(&$fieldDef, $tablename)
2145 2145
 	{
2146
-		if ( !isset($fieldDef['dbType']) ) {
2147
-			if ( isset($fieldDef['dbtype']) )
2146
+		if (!isset($fieldDef['dbType'])) {
2147
+			if (isset($fieldDef['dbtype']))
2148 2148
 				$fieldDef['dbType'] = $fieldDef['dbtype'];
2149 2149
 			else
2150 2150
 				$fieldDef['dbType'] = $fieldDef['type'];
2151 2151
 		}
2152
-		$type = $this->getColumnType($fieldDef['dbType'],$fieldDef['name'],$tablename);
2152
+		$type = $this->getColumnType($fieldDef['dbType'], $fieldDef['name'], $tablename);
2153 2153
 		$matches = array();
2154 2154
         // len can be a number or a string like 'max', for example, nvarchar(max)
2155 2155
         preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*|\w+)\)|)/i', $type, $matches);
2156
-		if ( isset($matches[1][0]) )
2156
+		if (isset($matches[1][0]))
2157 2157
 			$fieldDef['type'] = $matches[1][0];
2158
-		if ( isset($matches[2][0]) && empty($fieldDef['len']) )
2158
+		if (isset($matches[2][0]) && empty($fieldDef['len']))
2159 2159
 			$fieldDef['len'] = $matches[2][0];
2160
-		if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') )
2160
+		if (!empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'], ','))
2161 2161
 			$fieldDef['len'] .= ",{$fieldDef['precision']}";
2162
-		if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required'])) ) {
2162
+		if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required']))) {
2163 2163
 			$fieldDef['required'] = 'true';
2164 2164
 		}
2165 2165
 	}
@@ -2180,7 +2180,7 @@  discard block
 block discarded – undo
2180 2180
 		$level = 0;
2181 2181
 		$selectField = "";
2182 2182
 		$strLen = strlen($selectStatement);
2183
-		for($i = 0; $i < $strLen; $i++)
2183
+		for ($i = 0; $i < $strLen; $i++)
2184 2184
 		{
2185 2185
 			$char = $selectStatement[$i];
2186 2186
 
@@ -2190,16 +2190,16 @@  discard block
 block discarded – undo
2190 2190
 				$fields[$field] = $selectField;
2191 2191
 				$selectField = "";
2192 2192
 			}
2193
-			else if ($char == "("){
2193
+			else if ($char == "(") {
2194 2194
 				$level++;
2195 2195
 				$selectField .= $char;
2196 2196
 			}
2197
-			else if($char == ")"){
2197
+			else if ($char == ")") {
2198 2198
 				$level--;
2199 2199
 				$selectField .= $char;
2200 2200
 
2201 2201
 
2202
-			}else{
2202
+			} else {
2203 2203
 				$selectField .= $char;
2204 2204
 			}
2205 2205
 
@@ -2215,7 +2215,7 @@  discard block
 block discarded – undo
2215 2215
      */
2216 2216
 	protected function getFieldNameFromSelect($string)
2217 2217
 	{
2218
-		if(strncasecmp($string, "DISTINCT ", 9) == 0) {
2218
+		if (strncasecmp($string, "DISTINCT ", 9) == 0) {
2219 2219
 			$string = substr($string, 9);
2220 2220
 		}
2221 2221
 		if (stripos($string, " as ") !== false)
@@ -2293,14 +2293,14 @@  discard block
 block discarded – undo
2293 2293
 				foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name'];
2294 2294
 
2295 2295
 			// build part of where clause
2296
-			if (is_array($whereClause[$beanID])){
2296
+			if (is_array($whereClause[$beanID])) {
2297 2297
 				$where[] = $this->getColumnWhereClause($table, $whereClause[$beanID]);
2298 2298
 			}
2299 2299
 			// initialize so that it can be used properly in form clause generation
2300 2300
 			$table_used_in_from[$table] = false;
2301 2301
 
2302 2302
 			$indices = $bean->getIndices();
2303
-			foreach ($indices as $index){
2303
+			foreach ($indices as $index) {
2304 2304
 				if ($index['type'] == 'foreign') {
2305 2305
 					$relationship[$table][] = array('foreignTable'=> $index['foreignTable']
2306 2306
 												,'foreignColumn'=>$index['foreignField']
@@ -2321,12 +2321,12 @@  discard block
 block discarded – undo
2321 2321
 		// table2 is assumed to joining through primary key called id
2322 2322
 		$separator = "";
2323 2323
 		$from = ''; $table_used_in_from = array();
2324
-		foreach ($relations as $table1 => $rightsidearray){
2324
+		foreach ($relations as $table1 => $rightsidearray) {
2325 2325
 			if ($table_used_in_from[$table1]) continue; // table has been joined
2326 2326
 
2327 2327
 			$from .= $separator." ".$table1;
2328 2328
 			$table_used_in_from[$table1] = true;
2329
-			foreach ($rightsidearray as $tablearray){
2329
+			foreach ($rightsidearray as $tablearray) {
2330 2330
 				$table2 = $tablearray['foreignTable']; // get foreign table
2331 2331
 				$tableAlias = $aliases[$table2]; // get a list of aliases for this table
2332 2332
 				foreach ($tableAlias as $table2) {
@@ -2386,9 +2386,9 @@  discard block
 block discarded – undo
2386 2386
 		// we do not have change a lot of existing code
2387 2387
 		// and add dbtype where type is being used for some special
2388 2388
 		// purposes like referring to foreign table etc.
2389
-		if(!empty($fieldDef['dbType']))
2389
+		if (!empty($fieldDef['dbType']))
2390 2390
 			return  $fieldDef['dbType'];
2391
-		if(!empty($fieldDef['dbtype']))
2391
+		if (!empty($fieldDef['dbtype']))
2392 2392
 			return  $fieldDef['dbtype'];
2393 2393
 		if (!empty($fieldDef['type']))
2394 2394
 			return  $fieldDef['type'];
@@ -2408,17 +2408,17 @@  discard block
 block discarded – undo
2408 2408
      */
2409 2409
     public function getTypeParts($type)
2410 2410
     {
2411
-        if(preg_match("#(?P<type>\w+)\s*(?P<arg>\((?P<len>\w+)\s*(,\s*(?P<scale>\d+))*\))*#", $type, $matches))
2411
+        if (preg_match("#(?P<type>\w+)\s*(?P<arg>\((?P<len>\w+)\s*(,\s*(?P<scale>\d+))*\))*#", $type, $matches))
2412 2412
         {
2413
-            $return = array();  // Not returning matches array as such as we don't want to expose the regex make up on the interface
2413
+            $return = array(); // Not returning matches array as such as we don't want to expose the regex make up on the interface
2414 2414
             $return['baseType'] = $matches['type'];
2415
-            if( isset($matches['arg'])) {
2415
+            if (isset($matches['arg'])) {
2416 2416
                 $return['arg'] = $matches['arg'];
2417 2417
             }
2418
-            if( isset($matches['len'])) {
2418
+            if (isset($matches['len'])) {
2419 2419
                 $return['len'] = $matches['len'];
2420 2420
             }
2421
-            if( isset($matches['scale'])) {
2421
+            if (isset($matches['scale'])) {
2422 2422
                 $return['scale'] = $matches['scale'];
2423 2423
             }
2424 2424
             return $return;
@@ -2442,28 +2442,28 @@  discard block
 block discarded – undo
2442 2442
 		$type = $this->getFieldType($fieldDef);
2443 2443
         $colType = $this->getColumnType($type);
2444 2444
 
2445
-        if($parts = $this->getTypeParts($colType))
2445
+        if ($parts = $this->getTypeParts($colType))
2446 2446
         {
2447 2447
             $colBaseType = $parts['baseType'];
2448
-            $defLen =  isset($parts['len']) ? $parts['len'] : '255'; // Use the mappings length (precision) as default if it exists
2448
+            $defLen = isset($parts['len']) ? $parts['len'] : '255'; // Use the mappings length (precision) as default if it exists
2449 2449
         }
2450 2450
 
2451
-        if(!empty($fieldDef['len'])) {
2452
-            if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char',
2451
+        if (!empty($fieldDef['len'])) {
2452
+            if (in_array($colBaseType, array('nvarchar', 'nchar', 'varchar', 'varchar2', 'char',
2453 2453
                                           'clob', 'blob', 'text'))) {
2454 2454
           	    $colType = "$colBaseType(${fieldDef['len']})";
2455
-            } elseif(($colBaseType == 'decimal' || $colBaseType == 'float')){
2456
-                  if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision']))
2457
-                      if(strpos($fieldDef['len'],',') === false){
2458
-                          $colType = $colBaseType . "(".$fieldDef['len'].",".$fieldDef['precision'].")";
2459
-                      }else{
2460
-                          $colType = $colBaseType . "(".$fieldDef['len'].")";
2455
+            } elseif (($colBaseType == 'decimal' || $colBaseType == 'float')) {
2456
+                  if (!empty($fieldDef['precision']) && is_numeric($fieldDef['precision']))
2457
+                      if (strpos($fieldDef['len'], ',') === false) {
2458
+                          $colType = $colBaseType."(".$fieldDef['len'].",".$fieldDef['precision'].")";
2459
+                      } else {
2460
+                          $colType = $colBaseType."(".$fieldDef['len'].")";
2461 2461
                       }
2462 2462
                   else
2463
-                          $colType = $colBaseType . "(".$fieldDef['len'].")";
2463
+                          $colType = $colBaseType."(".$fieldDef['len'].")";
2464 2464
               }
2465 2465
         } else {
2466
-            if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) {
2466
+            if (in_array($colBaseType, array('nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) {
2467 2467
                 $colType = "$colBaseType($defLen)";
2468 2468
             }
2469 2469
         }
@@ -2485,29 +2485,29 @@  discard block
 block discarded – undo
2485 2485
         }
2486 2486
 
2487 2487
 		$auto_increment = '';
2488
-		if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment'])
2489
-			$auto_increment = $this->setAutoIncrement($table , $fieldDef['name']);
2488
+		if (!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment'])
2489
+			$auto_increment = $this->setAutoIncrement($table, $fieldDef['name']);
2490 2490
 
2491
-		$required = 'NULL';  // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify
2491
+		$required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify
2492 2492
 		//Starting in 6.0, only ID and auto_increment fields will be NOT NULL in the DB.
2493 2493
 		if ((empty($fieldDef['isnull']) || strtolower($fieldDef['isnull']) == 'false') &&
2494 2494
 			(!empty($auto_increment) || $name == 'id' || ($fieldDef['type'] == 'id' && !empty($fieldDef['required'])))) {
2495
-			$required =  "NOT NULL";
2495
+			$required = "NOT NULL";
2496 2496
 		}
2497 2497
 		// If the field is marked both required & isnull=>false - alwqys make it not null
2498 2498
 		// Use this to ensure primary key fields never defined as null
2499
-		if(isset($fieldDef['isnull']) && (strtolower($fieldDef['isnull']) == 'false' || $fieldDef['isnull'] === false)
2499
+		if (isset($fieldDef['isnull']) && (strtolower($fieldDef['isnull']) == 'false' || $fieldDef['isnull'] === false)
2500 2500
 			&& !empty($fieldDef['required'])) {
2501
-			$required =  "NOT NULL";
2501
+			$required = "NOT NULL";
2502 2502
 		}
2503 2503
 		if ($ignoreRequired)
2504 2504
 			$required = "";
2505 2505
 
2506
-		if ( $return_as_array ) {
2506
+		if ($return_as_array) {
2507 2507
 			return array(
2508 2508
 				'name' => $name,
2509 2509
 				'colType' => $colType,
2510
-                'colBaseType' => $colBaseType,  // Adding base type for easier processing in derived classes
2510
+                'colBaseType' => $colBaseType, // Adding base type for easier processing in derived classes
2511 2511
 				'default' => $default,
2512 2512
 				'required' => $required,
2513 2513
 				'auto_increment' => $auto_increment,
@@ -2532,14 +2532,14 @@  discard block
 block discarded – undo
2532 2532
 
2533 2533
 		if ($this->isFieldArray($fieldDefs)) {
2534 2534
 			foreach ($fieldDefs as $fieldDef) {
2535
-				if(!isset($fieldDef['source']) || $fieldDef['source'] == 'db') {
2536
-					$columns[] = $this->oneColumnSQLRep($fieldDef,false, $tablename);
2535
+				if (!isset($fieldDef['source']) || $fieldDef['source'] == 'db') {
2536
+					$columns[] = $this->oneColumnSQLRep($fieldDef, false, $tablename);
2537 2537
 				}
2538 2538
 			}
2539 2539
 			$columns = implode(",", $columns);
2540 2540
 		}
2541 2541
 		else {
2542
-			$columns = $this->oneColumnSQLRep($fieldDefs,$ignoreRequired, $tablename);
2542
+			$columns = $this->oneColumnSQLRep($fieldDefs, $ignoreRequired, $tablename);
2543 2543
 		}
2544 2544
 
2545 2545
 		return $columns;
@@ -2701,40 +2701,40 @@  discard block
 block discarded – undo
2701 2701
      */
2702 2702
 	public function getValidDBName($name, $ensureUnique = false, $type = 'column', $force = false)
2703 2703
 	{
2704
-		if(is_array($name)) {
2704
+		if (is_array($name)) {
2705 2705
 			$result = array();
2706
-			foreach($name as $field) {
2706
+			foreach ($name as $field) {
2707 2707
 				$result[] = $this->getValidDBName($field, $ensureUnique, $type);
2708 2708
 			}
2709 2709
 			return $result;
2710 2710
 		} else {
2711
-		    if(strchr($name, ".")) {
2711
+		    if (strchr($name, ".")) {
2712 2712
 		        // this is a compound name with dots, handle separately
2713 2713
 		        $parts = explode(".", $name);
2714
-		        if(count($parts) > 2) {
2714
+		        if (count($parts) > 2) {
2715 2715
 		            // some weird name, cut to table.name
2716
-		            array_splice($parts, 0, count($parts)-2);
2716
+		            array_splice($parts, 0, count($parts) - 2);
2717 2717
 		        }
2718 2718
 		        $parts = $this->getValidDBName($parts, $ensureUnique, $type, $force);
2719 2719
                 return join(".", $parts);
2720 2720
 		    }
2721 2721
 			// first strip any invalid characters - all but word chars (which is alphanumeric and _)
2722
-			$name = preg_replace( '/[^\w]+/i', '', $name ) ;
2723
-			$len = strlen( $name ) ;
2722
+			$name = preg_replace('/[^\w]+/i', '', $name);
2723
+			$len = strlen($name);
2724 2724
 			$maxLen = empty($this->maxNameLengths[$type]) ? $this->maxNameLengths[$type]['column'] : $this->maxNameLengths[$type];
2725 2725
 			if ($len <= $maxLen && !$force) {
2726 2726
 				return strtolower($name);
2727 2727
 			}
2728 2728
 			if ($ensureUnique) {
2729 2729
 				$md5str = md5($name);
2730
-				$tail = substr ( $name, -11) ;
2731
-				$temp = substr($md5str , strlen($md5str)-4 );
2732
-				$result = substr( $name, 0, 10) . $temp . $tail ;
2730
+				$tail = substr($name, -11);
2731
+				$temp = substr($md5str, strlen($md5str) - 4);
2732
+				$result = substr($name, 0, 10).$temp.$tail;
2733 2733
 			} else {
2734
-				$result = substr( $name, 0, 11) . substr( $name, 11 - $maxLen);
2734
+				$result = substr($name, 0, 11).substr($name, 11 - $maxLen);
2735 2735
 			}
2736 2736
 
2737
-			return strtolower( $result ) ;
2737
+			return strtolower($result);
2738 2738
 		}
2739 2739
 	}
2740 2740
 
@@ -2746,7 +2746,7 @@  discard block
 block discarded – undo
2746 2746
 	 */
2747 2747
 	public function getColumnType($type)
2748 2748
 	{
2749
-		return isset($this->type_map[$type])?$this->type_map[$type]:$type;
2749
+		return isset($this->type_map[$type]) ? $this->type_map[$type] : $type;
2750 2750
 	}
2751 2751
 
2752 2752
 	/**
@@ -2760,10 +2760,10 @@  discard block
 block discarded – undo
2760 2760
 	 */
2761 2761
 	public function isFieldArray($defArray)
2762 2762
 	{
2763
-		if ( !is_array($defArray) )
2763
+		if (!is_array($defArray))
2764 2764
 			return false;
2765 2765
 
2766
-		if ( isset($defArray['type']) ){
2766
+		if (isset($defArray['type'])) {
2767 2767
 			// type key exists. May be an array of defs or a simple definition
2768 2768
 			return is_array($defArray['type']); // type is not an array => definition else array
2769 2769
 		}
@@ -2798,19 +2798,19 @@  discard block
 block discarded – undo
2798 2798
 		require('metadata/audit_templateMetaData.php');
2799 2799
 		$fieldDefs = $dictionary['audit']['fields'];
2800 2800
 
2801
-		$values=array();
2801
+		$values = array();
2802 2802
 		$values['id'] = $this->massageValue(create_guid(), $fieldDefs['id']);
2803
-		$values['parent_id']= $this->massageValue($bean->id, $fieldDefs['parent_id']);
2804
-		$values['field_name']= $this->massageValue($changes['field_name'], $fieldDefs['field_name']);
2803
+		$values['parent_id'] = $this->massageValue($bean->id, $fieldDefs['parent_id']);
2804
+		$values['field_name'] = $this->massageValue($changes['field_name'], $fieldDefs['field_name']);
2805 2805
 		$values['data_type'] = $this->massageValue($changes['data_type'], $fieldDefs['data_type']);
2806
-		if ($changes['data_type']=='text') {
2806
+		if ($changes['data_type'] == 'text') {
2807 2807
 			$values['before_value_text'] = $this->massageValue($changes['before'], $fieldDefs['before_value_text']);
2808 2808
 			$values['after_value_text'] = $this->massageValue($changes['after'], $fieldDefs['after_value_text']);
2809 2809
 		} else {
2810 2810
 			$values['before_value_string'] = $this->massageValue($changes['before'], $fieldDefs['before_value_string']);
2811 2811
 			$values['after_value_string'] = $this->massageValue($changes['after'], $fieldDefs['after_value_string']);
2812 2812
 		}
2813
-		$values['date_created'] = $this->massageValue(TimeDate::getInstance()->nowDb(), $fieldDefs['date_created'] );
2813
+		$values['date_created'] = $this->massageValue(TimeDate::getInstance()->nowDb(), $fieldDefs['date_created']);
2814 2814
 		$values['created_by'] = $this->massageValue($current_user->id, $fieldDefs['created_by']);
2815 2815
 
2816 2816
 		$sql .= "(".implode(",", array_keys($values)).") ";
@@ -2840,9 +2840,9 @@  discard block
 block discarded – undo
2840 2840
      * @param array|null $field_filter Array of filter names to be inspected (NULL means all fields)
2841 2841
      * @return array
2842 2842
      */
2843
-    public function getDataChanges(SugarBean &$bean, array $field_filter = null)
2843
+    public function getDataChanges(SugarBean & $bean, array $field_filter = null)
2844 2844
 	{
2845
-        $changed_values=array();
2845
+        $changed_values = array();
2846 2846
 
2847 2847
         $fetched_row = array();
2848 2848
         if (is_array($bean->fetched_row))
@@ -2862,40 +2862,40 @@  discard block
 block discarded – undo
2862 2862
             $field_defs = array_intersect_key($field_defs, $fetched_row);
2863 2863
 
2864 2864
             // remove fields which do not exist as bean property
2865
-            $field_defs = array_intersect_key($field_defs, (array) $bean);
2865
+            $field_defs = array_intersect_key($field_defs, (array)$bean);
2866 2866
 
2867 2867
             foreach ($field_defs as $field => $properties) {
2868 2868
                 $before_value = $fetched_row[$field];
2869
-                $after_value=$bean->$field;
2869
+                $after_value = $bean->$field;
2870 2870
                 if (isset($properties['type'])) {
2871
-                    $field_type=$properties['type'];
2871
+                    $field_type = $properties['type'];
2872 2872
                 } else {
2873 2873
                     if (isset($properties['dbType'])) {
2874
-                        $field_type=$properties['dbType'];
2874
+                        $field_type = $properties['dbType'];
2875 2875
                     }
2876
-                    else if(isset($properties['data_type'])) {
2877
-                        $field_type=$properties['data_type'];
2876
+                    else if (isset($properties['data_type'])) {
2877
+                        $field_type = $properties['data_type'];
2878 2878
                     }
2879 2879
                     else {
2880
-                        $field_type=$properties['dbtype'];
2880
+                        $field_type = $properties['dbtype'];
2881 2881
                     }
2882 2882
                 }
2883 2883
 
2884 2884
                 //Because of bug #25078(sqlserver haven't 'date' type, trim extra "00:00:00" when insert into *_cstm table).
2885 2885
                 // so when we read the audit datetime field from sqlserver, we have to replace the extra "00:00:00" again.
2886
-                if(!empty($field_type) && $field_type == 'date'){
2887
-                    $before_value = $this->fromConvert($before_value , $field_type);
2886
+                if (!empty($field_type) && $field_type == 'date') {
2887
+                    $before_value = $this->fromConvert($before_value, $field_type);
2888 2888
                 }
2889 2889
                 //if the type and values match, do nothing.
2890
-                if (!($this->_emptyValue($before_value,$field_type) && $this->_emptyValue($after_value,$field_type))) {
2890
+                if (!($this->_emptyValue($before_value, $field_type) && $this->_emptyValue($after_value, $field_type))) {
2891 2891
                     $change = false;
2892 2892
                     if (trim($before_value) !== trim($after_value)) {
2893 2893
                         // Bug #42475: Don't directly compare numeric values, instead do the subtract and see if the comparison comes out to be "close enough", it is necessary for floating point numbers.
2894 2894
                         // Manual merge of fix 95727f2eed44852f1b6bce9a9eccbe065fe6249f from DBHelper
2895 2895
                         // This fix also fixes Bug #44624 in a more generic way and therefore eliminates the need for fix 0a55125b281c4bee87eb347709af462715f33d2d in DBHelper
2896 2896
                         if ($this->isNumericType($field_type)) {
2897
-                            $numerator = abs(2*((trim($before_value)+0)-(trim($after_value)+0)));
2898
-                            $denominator = abs(((trim($before_value)+0)+(trim($after_value)+0)));
2897
+                            $numerator = abs(2 * ((trim($before_value) + 0) - (trim($after_value) + 0)));
2898
+                            $denominator = abs(((trim($before_value) + 0) + (trim($after_value) + 0)));
2899 2899
                             // detect whether to use absolute or relative error. use absolute if denominator is zero to avoid division by zero
2900 2900
                             $error = ($denominator == 0) ? $numerator : $numerator / $denominator;
2901 2901
                             if ($error >= 0.0000000001) {    // Smaller than 10E-10
@@ -2911,7 +2911,7 @@  discard block
 block discarded – undo
2911 2911
                             $change = true;
2912 2912
                         }
2913 2913
                         if ($change) {
2914
-                            $changed_values[$field]=array('field_name'=>$field,
2914
+                            $changed_values[$field] = array('field_name'=>$field,
2915 2915
                                 'data_type'=>$field_type,
2916 2916
                                 'before'=>$before_value,
2917 2917
                                 'after'=>$after_value);
@@ -2982,8 +2982,8 @@  discard block
 block discarded – undo
2982 2982
      */
2983 2983
 	public function renameIndexDefs($old_definition, $new_definition, $table_name)
2984 2984
 	{
2985
-		return array($this->add_drop_constraint($table_name,$old_definition,true),
2986
-				$this->add_drop_constraint($table_name,$new_definition), false);
2985
+		return array($this->add_drop_constraint($table_name, $old_definition, true),
2986
+				$this->add_drop_constraint($table_name, $new_definition), false);
2987 2987
 	}
2988 2988
 
2989 2989
 	/**
@@ -3005,7 +3005,7 @@  discard block
 block discarded – undo
3005 3005
 	protected function _getBooleanValue($val)
3006 3006
 	{
3007 3007
 		//need to put the === sign here otherwise true == 'non empty string'
3008
-		if (empty($val) or $val==='off')
3008
+		if (empty($val) or $val === 'off')
3009 3009
 			return false;
3010 3010
 
3011 3011
 		return true;
@@ -3018,7 +3018,7 @@  discard block
 block discarded – undo
3018 3018
 	 */
3019 3019
 	public function isNumericType($type)
3020 3020
 	{
3021
-	    if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) {
3021
+	    if (isset($this->type_class[$type]) && ($this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) {
3022 3022
 	        return true;
3023 3023
 	    }
3024 3024
 		return false;
@@ -3035,7 +3035,7 @@  discard block
 block discarded – undo
3035 3035
 		if (empty($val))
3036 3036
 			return true;
3037 3037
 
3038
-		if($this->emptyValue($type) == $val) {
3038
+		if ($this->emptyValue($type) == $val) {
3039 3039
 			return true;
3040 3040
 		}
3041 3041
 		switch ($type) {
@@ -3094,7 +3094,7 @@  discard block
 block discarded – undo
3094 3094
 		$i = 0;
3095 3095
 		$order_by_arr = array();
3096 3096
 		foreach ($values as $key => $value) {
3097
-			if($key == '') {
3097
+			if ($key == '') {
3098 3098
 				$order_by_arr[] = "WHEN ($order_by='' OR $order_by IS NULL) THEN $i";
3099 3099
 			} else {
3100 3100
 				$order_by_arr[] = "WHEN $order_by=".$this->quoted($key)." THEN $i";
@@ -3112,7 +3112,7 @@  discard block
 block discarded – undo
3112 3112
      */
3113 3113
 	public function emptyValue($type)
3114 3114
 	{
3115
-		if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'bool' || $this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) {
3115
+		if (isset($this->type_class[$type]) && ($this->type_class[$type] == 'bool' || $this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) {
3116 3116
 			return 0;
3117 3117
 		}
3118 3118
 
@@ -3161,9 +3161,9 @@  discard block
 block discarded – undo
3161 3161
      * @return resource|bool query result
3162 3162
      * @see DBManager::limitQuery()
3163 3163
 	 */
3164
-	public function limitQuerySql($sql, $start, $count, $dieOnError=false, $msg='')
3164
+	public function limitQuerySql($sql, $start, $count, $dieOnError = false, $msg = '')
3165 3165
 	{
3166
-		return $this->limitQuery($sql,$start,$count,$dieOnError,$msg,false);
3166
+		return $this->limitQuery($sql, $start, $count, $dieOnError, $msg, false);
3167 3167
 	}
3168 3168
 
3169 3169
 	/**
@@ -3182,7 +3182,7 @@  discard block
 block discarded – undo
3182 3182
      */
3183 3183
 	public function checkPrivilege($privilege)
3184 3184
 	{
3185
-		switch($privilege) {
3185
+		switch ($privilege) {
3186 3186
 			case "CREATE TABLE":
3187 3187
 				$this->query("CREATE TABLE temp (id varchar(36))");
3188 3188
 				break;
@@ -3203,23 +3203,23 @@  discard block
 block discarded – undo
3203 3203
 				break;
3204 3204
 			case "ADD COLUMN":
3205 3205
 				$test = array("test" => array("name" => "test", "type" => "varchar", "len" => 50));
3206
-				$sql = 	$this->changeColumnSQL("temp", $test, "add");
3206
+				$sql = $this->changeColumnSQL("temp", $test, "add");
3207 3207
 				$this->query($sql);
3208 3208
 				break;
3209 3209
 			case "CHANGE COLUMN":
3210 3210
 				$test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100));
3211
-				$sql = 	$this->changeColumnSQL("temp", $test, "modify");
3211
+				$sql = $this->changeColumnSQL("temp", $test, "modify");
3212 3212
 				$this->query($sql);
3213 3213
 				break;
3214 3214
 			case "DROP COLUMN":
3215 3215
 				$test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100));
3216
-				$sql = 	$this->changeColumnSQL("temp", $test, "drop");
3216
+				$sql = $this->changeColumnSQL("temp", $test, "drop");
3217 3217
 				$this->query($sql);
3218 3218
 				break;
3219 3219
 			default:
3220 3220
 				return false;
3221 3221
 		}
3222
-		if($this->checkError("Checking privileges")) {
3222
+		if ($this->checkError("Checking privileges")) {
3223 3223
 			return false;
3224 3224
 		}
3225 3225
 		return true;
@@ -3236,7 +3236,7 @@  discard block
 block discarded – undo
3236 3236
 		$select_check = strpos(strtolower($query), strtolower("SELECT"));
3237 3237
 		//Checks to see if there is union select which is valid
3238 3238
 		$select_check2 = strpos(strtolower($query), strtolower("(SELECT"));
3239
-		if($select_check==0 || $select_check2==0){
3239
+		if ($select_check == 0 || $select_check2 == 0) {
3240 3240
 			//Returning false means query is ok!
3241 3241
 			return true;
3242 3242
 		}
@@ -3255,10 +3255,10 @@  discard block
 block discarded – undo
3255 3255
 	public function parseFulltextQuery($query)
3256 3256
 	{
3257 3257
 		/* split on space or comma, double quotes with \ for escape */
3258
-		if(strpbrk($query, " ,")) {
3258
+		if (strpbrk($query, " ,")) {
3259 3259
 			// ("([^"]*?)"|[^" ,]+)((, )+)?
3260 3260
 			// '/([^" ,]+|".*?[^\\\\]")(,|\s)\s*/'
3261
-			if(!preg_match_all('/("([^"]*?)"|[^"\s,]+)((,\s)+)?/', $query, $m)) {
3261
+			if (!preg_match_all('/("([^"]*?)"|[^"\s,]+)((,\s)+)?/', $query, $m)) {
3262 3262
 				return false;
3263 3263
 			}
3264 3264
 			$qterms = $m[1];
@@ -3266,17 +3266,17 @@  discard block
 block discarded – undo
3266 3266
 			$qterms = array($query);
3267 3267
 		}
3268 3268
 		$terms = $must_terms = $not_terms = array();
3269
-		foreach($qterms as $item) {
3270
-			if($item[0] == '"') {
3269
+		foreach ($qterms as $item) {
3270
+			if ($item[0] == '"') {
3271 3271
 				$item = trim($item, '"');
3272 3272
 			}
3273
-			if($item[0] == '+') {
3273
+			if ($item[0] == '+') {
3274 3274
                 if (strlen($item) > 1) {
3275 3275
                     $must_terms[] = substr($item, 1);
3276 3276
                 }
3277 3277
                 continue;
3278 3278
 			}
3279
-			if($item[0] == '-') {
3279
+			if ($item[0] == '-') {
3280 3280
                 if (strlen($item) > 1) {
3281 3281
 				    $not_terms[] = substr($item, 1);
3282 3282
                 }
@@ -3325,11 +3325,11 @@  discard block
 block discarded – undo
3325 3325
 	public function verifySQLStatement($query, $skipTables)
3326 3326
 	{
3327 3327
 		$query = trim($query);
3328
-		foreach($this->standardQueries as $qstart => $check) {
3329
-			if(strncasecmp($qstart, $query, strlen($qstart)) == 0) {
3330
-				if(is_callable(array($this, $check))) {
3328
+		foreach ($this->standardQueries as $qstart => $check) {
3329
+			if (strncasecmp($qstart, $query, strlen($qstart)) == 0) {
3330
+				if (is_callable(array($this, $check))) {
3331 3331
 					$table = $this->extractTableName($query);
3332
-					if(!in_array($table, $skipTables)) {
3332
+					if (!in_array($table, $skipTables)) {
3333 3333
 						return call_user_func(array($this, $check), $table, $query);
3334 3334
 					} else {
3335 3335
 						$this->log->debug("Skipping table $table as blacklisted");
@@ -3358,20 +3358,20 @@  discard block
 block discarded – undo
3358 3358
 		$tempname = $table."__uw_temp";
3359 3359
 		$tempTableQuery = str_replace("CREATE TABLE {$table}", "CREATE TABLE $tempname", $query);
3360 3360
 
3361
-		if(strpos($tempTableQuery, '__uw_temp') === false) {
3361
+		if (strpos($tempTableQuery, '__uw_temp') === false) {
3362 3362
 			return 'Could not use a temp table to test query!';
3363 3363
 		}
3364 3364
 
3365 3365
 		$this->query($tempTableQuery, false, "Preflight Failed for: {$query}");
3366 3366
 
3367 3367
 		$error = $this->lastError(); // empty on no-errors
3368
-		if(!empty($error)) {
3368
+		if (!empty($error)) {
3369 3369
 			return $error;
3370 3370
 		}
3371 3371
 
3372 3372
 		// check if table exists
3373 3373
 		$this->log->debug('testing for table: '.$table);
3374
-		if(!$this->tableExists($tempname)) {
3374
+		if (!$this->tableExists($tempname)) {
3375 3375
 			return "Failed to create temp table!";
3376 3376
 		}
3377 3377
 
@@ -3390,8 +3390,8 @@  discard block
 block discarded – undo
3390 3390
 	public function queryArray(array $sqls, $dieOnError = false, $msg = '', $suppress = false)
3391 3391
 	{
3392 3392
 		$last = true;
3393
-		foreach($sqls as $sql) {
3394
-			if(!($last = $this->query($sql, $dieOnError, $msg, $suppress))) {
3393
+		foreach ($sqls as $sql) {
3394
+			if (!($last = $this->query($sql, $dieOnError, $msg, $suppress))) {
3395 3395
 				break;
3396 3396
 			}
3397 3397
 		}
@@ -3409,7 +3409,7 @@  discard block
 block discarded – undo
3409 3409
 	{
3410 3410
 	    if (empty($result))	return false;
3411 3411
 
3412
-	    if(is_int($encode) && func_num_args() == 3) {
3412
+	    if (is_int($encode) && func_num_args() == 3) {
3413 3413
 	        // old API: $result, $rowNum, $encode
3414 3414
 	        $GLOBALS['log']->deprecated("Using row number in fetchByAssoc is not portable and no longer supported. Please fix your code.");
3415 3415
 	        $encode = func_get_arg(2);
@@ -3460,7 +3460,7 @@  discard block
 block discarded – undo
3460 3460
 	 */
3461 3461
 	public function getOption($option)
3462 3462
 	{
3463
-	    if(isset($this->options[$option])) {
3463
+	    if (isset($this->options[$option])) {
3464 3464
 	        return $this->options[$option];
3465 3465
 	    }
3466 3466
 	    return null;
@@ -3500,7 +3500,7 @@  discard block
 block discarded – undo
3500 3500
 	public function isDatabaseNameValid($name)
3501 3501
 	{
3502 3502
 		// Generic case - no slashes, no dots
3503
-		return preg_match('#[/.\\\\]#', $name)==0;
3503
+		return preg_match('#[/.\\\\]#', $name) == 0;
3504 3504
 	}
3505 3505
 
3506 3506
 	/**
Please login to merge, or discard this patch.
install.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
- if(!defined('sugarEntry'))define('sugarEntry', true);
2
+ if (!defined('sugarEntry'))define('sugarEntry', true);
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.
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  ********************************************************************************/
40 40
  
41 41
 @session_start();
42
-if(isset($_REQUEST['clear_session']) || !empty($_SESSION['loginAttempts'])) {
42
+if (isset($_REQUEST['clear_session']) || !empty($_SESSION['loginAttempts'])) {
43 43
 	session_destroy();
44 44
 	header('Location: install.php');
45 45
 	echo 'session clean, page refresh...';
@@ -47,17 +47,17 @@  discard block
 block discarded – undo
47 47
 }
48 48
  
49 49
 //  recover smtp settings
50
-if(isset($_POST['smtp_tab_selected'])) {
50
+if (isset($_POST['smtp_tab_selected'])) {
51 51
     $_POST = array_merge($_POST, $_POST[$_POST['smtp_tab_selected']]);
52 52
 }
53 53
 
54 54
 //session_destroy();
55
-if (version_compare(phpversion(),'5.2.0') < 0) {
56
-	$msg = 'Minimum PHP version required is 5.2.0.  You are using PHP version  '. phpversion();
55
+if (version_compare(phpversion(), '5.2.0') < 0) {
56
+	$msg = 'Minimum PHP version required is 5.2.0.  You are using PHP version  '.phpversion();
57 57
     die($msg);
58 58
 }
59 59
 $session_id = session_id();
60
-if(empty($session_id)){
60
+if (empty($session_id)) {
61 61
 	@session_start();
62 62
 }
63 63
 $GLOBALS['installing'] = true;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 //check to see if the script files need to be rebuilt, add needed variables to request array
79 79
 $_REQUEST['root_directory'] = getcwd();
80 80
 $_REQUEST['js_rebuild_concat'] = 'rebuild';
81
-if(isset($_REQUEST['goto']) && $_REQUEST['goto'] != 'SilentInstall') {
81
+if (isset($_REQUEST['goto']) && $_REQUEST['goto'] != 'SilentInstall') {
82 82
     require_once('jssource/minify.php');
83 83
 }
84 84
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 setPhpIniSettings();
88 88
 $locale = new Localization();
89 89
 
90
-if(get_magic_quotes_gpc() == 1) {
90
+if (get_magic_quotes_gpc() == 1) {
91 91
    $_REQUEST = array_map("stripslashes_checkstrings", $_REQUEST);
92 92
    $_POST = array_map("stripslashes_checkstrings", $_POST);
93 93
    $_GET = array_map("stripslashes_checkstrings", $_GET);
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 
109 109
 ///////////////////////////////////////////////////////////////////////////////
110 110
 ////	INSTALLER LANGUAGE
111
-function getSupportedInstallLanguages(){
111
+function getSupportedInstallLanguages() {
112 112
 	$supportedLanguages = array(
113 113
 	'en_us'	=> 'English (US)',
114 114
 	);
115
-	if(file_exists('install/lang.config.php')){
115
+	if (file_exists('install/lang.config.php')) {
116 116
 		include('install/lang.config.php');
117
-		if(!empty($config['languages'])){
117
+		if (!empty($config['languages'])) {
118 118
 
119
-			foreach($config['languages'] as $k=>$v){
120
-				if(file_exists('install/language/' . $k . '.lang.php')){
119
+			foreach ($config['languages'] as $k=>$v) {
120
+				if (file_exists('install/language/'.$k.'.lang.php')) {
121 121
 					$supportedLanguages[$k] = $v;
122 122
 				}
123 123
 			}
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
 
130 130
 // after install language is selected, use that pack
131 131
 $default_lang = 'en_us';
132
-if(!isset($_POST['language']) && (!isset($_SESSION['language']) && empty($_SESSION['language']))) {
133
-	if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
132
+if (!isset($_POST['language']) && (!isset($_SESSION['language']) && empty($_SESSION['language']))) {
133
+	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
134 134
 		$lang = parseAcceptLanguage();
135
-		if(isset($supportedLanguages[$lang])) {
135
+		if (isset($supportedLanguages[$lang])) {
136 136
 			$_POST['language'] = $lang;
137 137
 		} else {
138 138
 			$_POST['language'] = $default_lang;
@@ -140,19 +140,19 @@  discard block
 block discarded – undo
140 140
 	}
141 141
 }
142 142
 
143
-if(isset($_POST['language'])) {
144
-	$_SESSION['language'] = str_replace('-','_',$_POST['language']);
143
+if (isset($_POST['language'])) {
144
+	$_SESSION['language'] = str_replace('-', '_', $_POST['language']);
145 145
 }
146 146
 
147 147
 $current_language = isset($_SESSION['language']) ? $_SESSION['language'] : $default_lang;
148 148
 
149
-if(file_exists("install/language/{$current_language}.lang.php")) {
149
+if (file_exists("install/language/{$current_language}.lang.php")) {
150 150
 	require_once("install/language/{$current_language}.lang.php");
151 151
 } else {
152 152
 	require_once("install/language/{$default_lang}.lang.php");
153 153
 }
154 154
 
155
-if($current_language != 'en_us') {
155
+if ($current_language != 'en_us') {
156 156
 	$my_mod_strings = $mod_strings;
157 157
 	include('install/language/en_us.lang.php');
158 158
 	$mod_strings = sugarLangArrayMerge($mod_strings, $my_mod_strings);
@@ -166,40 +166,40 @@  discard block
 block discarded – undo
166 166
 $help_url = get_help_button_url();
167 167
 
168 168
 //if this license print, then redirect and exit,
169
-if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'licensePrint')
169
+if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'licensePrint')
170 170
 {
171 171
     include('install/licensePrint.php');
172 172
     exit ();
173 173
 }
174 174
 
175
-if(isset($_REQUEST['sugar_body_only']) && $_REQUEST['sugar_body_only'] == "1") {
175
+if (isset($_REQUEST['sugar_body_only']) && $_REQUEST['sugar_body_only'] == "1") {
176 176
     //if this is a system check, then just run the check and return,
177 177
     //this is an ajax call and there is no need for further processing
178 178
 
179
-    if(isset($_REQUEST['uploadLogoFrame']) && ($_REQUEST['uploadLogoFrame'])){
179
+    if (isset($_REQUEST['uploadLogoFrame']) && ($_REQUEST['uploadLogoFrame'])) {
180 180
         echo 'I\'m an uploader iframe!';
181 181
         return;
182 182
     }
183 183
 
184 184
         // upload company logo
185
-    if(isset($_REQUEST['uploadLogo']) && ($_REQUEST['uploadLogo'])){
185
+    if (isset($_REQUEST['uploadLogo']) && ($_REQUEST['uploadLogo'])) {
186 186
         $filepath = '';
187 187
         $errors = array();
188 188
 
189
-        switch($_FILES['company_logo']['error']) {
189
+        switch ($_FILES['company_logo']['error']) {
190 190
 
191 191
             case UPLOAD_ERR_OK:
192 192
                 $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG/*, IMAGETYPE_GIF */);
193 193
                 $detectedType = exif_imagetype($_FILES['company_logo']['tmp_name']);
194
-                if(!in_array($detectedType, $allowedTypes)) {
194
+                if (!in_array($detectedType, $allowedTypes)) {
195 195
                     $errors[] = $mod_strings['ERR_UPLOAD_FILETYPE'];
196 196
                 }
197 197
                 else {
198 198
                     // uploaded image stored in the /custom path instead of put into the original theme directory..
199 199
 
200
-                    mkdir_recursive('custom/' . SugarThemeRegistry::current()->getDefaultImagePath(), true);
200
+                    mkdir_recursive('custom/'.SugarThemeRegistry::current()->getDefaultImagePath(), true);
201 201
                     $tmpvar = explode('?', SugarThemeRegistry::current()->getImageURL('company_logo.png'));
202
-                    $destFile = 'custom/' . $tmpvar[0];
202
+                    $destFile = 'custom/'.$tmpvar[0];
203 203
                     if (!move_uploaded_file($_FILES['company_logo']['tmp_name'], $destFile)) {
204 204
                         $errors[] = $mod_strings['ERR_LANG_UPLOAD_1'];
205 205
                     }
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
 
248 248
         // TODO--low: validate file size & image width/height and save, show status result to client js
249 249
 
250
-        echo "<script>window.top.window.{$_REQUEST['callback']}(" . json_encode($result) . ");</script>";
250
+        echo "<script>window.top.window.{$_REQUEST['callback']}(".json_encode($result).");</script>";
251 251
         return;
252 252
     }
253 253
 
254
-    if(isset($_REQUEST['storeConfig']) && ($_REQUEST['storeConfig'])){
254
+    if (isset($_REQUEST['storeConfig']) && ($_REQUEST['storeConfig'])) {
255 255
         // store configuration by form to session
256
-        if(!isset($_SESSION)) session_start();
256
+        if (!isset($_SESSION)) session_start();
257 257
         $_SESSION = array_merge($_SESSION, $_POST);
258 258
 
259 259
         // TODO--low: don't forget the custom type install settings! validate here..
@@ -267,22 +267,22 @@  discard block
 block discarded – undo
267 267
 //            $si_errors = true;
268 268
 //        }
269 269
 
270
-        if(!empty($sugar_config['dbconfig'])) {
270
+        if (!empty($sugar_config['dbconfig'])) {
271 271
             try {
272 272
                 $db = DBManagerFactory::getInstance();
273 273
                 $db->disconnect();
274
-            } catch (\Exception $e) {
275
-                $validation_errors[] = $mod_strings['LBL_DB_CONN_ERR'] . ': ' . $e->getMessage();
274
+            }catch (\Exception $e) {
275
+                $validation_errors[] = $mod_strings['LBL_DB_CONN_ERR'].': '.$e->getMessage();
276 276
             }
277 277
         }
278 278
 
279 279
         $errors = '';
280
-        if( isset($validation_errors) && is_array($validation_errors)){
281
-            if( count($validation_errors) > 0 ){
280
+        if (isset($validation_errors) && is_array($validation_errors)) {
281
+            if (count($validation_errors) > 0) {
282 282
                // $errors  = '<div id="errorMsgs">';
283 283
                 $errors .= '<p>'.$mod_strings['LBL_SITECFG_FIX_ERRORS'].'</p><ul>';
284
-                foreach( $validation_errors as $error ){
285
-                    $errors .= '<li class="error">' . $error . '</li>';
284
+                foreach ($validation_errors as $error) {
285
+                    $errors .= '<li class="error">'.$error.'</li>';
286 286
                 }
287 287
                 $errors .= '</ul>'; //</div>';
288 288
             }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
         return;
293 293
     }
294 294
 
295
-    if(isset($_REQUEST['checkInstallSystem']) && ($_REQUEST['checkInstallSystem'])){
295
+    if (isset($_REQUEST['checkInstallSystem']) && ($_REQUEST['checkInstallSystem'])) {
296 296
         require_once('install/installSystemCheck.php');
297 297
         echo runCheck($install_script, $mod_strings);
298 298
         return;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 
301 301
     //if this is a DB Settings check, then just run the check and return,
302 302
     //this is an ajax call and there is no need for further processing
303
-    if(isset($_REQUEST['checkDBSettings']) && ($_REQUEST['checkDBSettings'])){
303
+    if (isset($_REQUEST['checkDBSettings']) && ($_REQUEST['checkDBSettings'])) {
304 304
         require_once('install/checkDBSettings.php');
305 305
         echo checkDBSettings();
306 306
         return;
@@ -308,13 +308,13 @@  discard block
 block discarded – undo
308 308
 }
309 309
 
310 310
 //maintaining the install_type if earlier set to custom
311
-if(isset($_REQUEST['install_type']) && $_REQUEST['install_type'] == 'custom'){
311
+if (isset($_REQUEST['install_type']) && $_REQUEST['install_type'] == 'custom') {
312 312
 	$_SESSION['install_type'] = $_REQUEST['install_type'];
313 313
 }
314 314
 
315 315
 //set the default settings into session
316
-foreach($installer_defaults as $key =>$val){
317
-    if(!isset($_SESSION[$key])){
316
+foreach ($installer_defaults as $key =>$val) {
317
+    if (!isset($_SESSION[$key])) {
318 318
         $_SESSION[$key] = $val;
319 319
     }
320 320
 }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 $next_step = 0;
327 327
 
328 328
 // use a simple array to map out the steps of the installer page flow
329
-$workflow = array(  'welcome.php',
329
+$workflow = array('welcome.php',
330 330
                     'ready.php',
331 331
 
332 332
                     // TODO-g: remove these files..
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 //$workflow[] = 'dbConfig_b.php';
340 340
 
341 341
 //define web root, which will be used as default for site_url
342
-if($_SERVER['SERVER_PORT']=='80'){
342
+if ($_SERVER['SERVER_PORT'] == '80') {
343 343
     $web_root = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
344
-}else{
344
+} else {
345 345
     $web_root = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['PHP_SELF'];
346 346
 }
347 347
 $web_root = str_replace("/install.php", "", $web_root);
@@ -359,16 +359,16 @@  discard block
 block discarded – undo
359 359
     }
360 360
 }
361 361
 
362
-if(empty($sugar_config['cache_dir']) && !empty($_SESSION['cache_dir'])) {
362
+if (empty($sugar_config['cache_dir']) && !empty($_SESSION['cache_dir'])) {
363 363
     $sugar_config['cache_dir'] = $_SESSION['cache_dir'];
364 364
 }
365 365
 
366 366
 // set the form's php var to the loaded config's var else default to sane settings
367
-if(!isset($_SESSION['setup_site_url'])  || empty($_SESSION['setup_site_url'])) {
368
-    if(isset($sugar_config['site_url']) && !empty($sugar_config['site_url'])) {
369
-        $_SESSION['setup_site_url']= $sugar_config['site_url'];
367
+if (!isset($_SESSION['setup_site_url']) || empty($_SESSION['setup_site_url'])) {
368
+    if (isset($sugar_config['site_url']) && !empty($sugar_config['site_url'])) {
369
+        $_SESSION['setup_site_url'] = $sugar_config['site_url'];
370 370
     } else {
371
-        $_SESSION['setup_site_url']= $web_root;
371
+        $_SESSION['setup_site_url'] = $web_root;
372 372
     }
373 373
 }
374 374
 
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
   //$workflow[] = 'confirmSettings.php';
392 392
 $workflow[] = 'performSetup.php';
393 393
 
394
-  if(!isset($_SESSION['oc_install']) ||  $_SESSION['oc_install'] == false){
395
-    if(isset($_SESSION['install_type'])  && !empty($_SESSION['install_type'])  && $_SESSION['install_type']=='custom'){
394
+  if (!isset($_SESSION['oc_install']) || $_SESSION['oc_install'] == false) {
395
+    if (isset($_SESSION['install_type']) && !empty($_SESSION['install_type']) && $_SESSION['install_type'] == 'custom') {
396 396
         //$workflow[] = 'download_patches.php';
397 397
         $workflow[] = 'download_modules.php';
398 398
     }
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 
404 404
 
405 405
 // increment/decrement the workflow pointer
406
-if(!empty($_REQUEST['goto'])) {
407
-    switch($_REQUEST['goto']) {
406
+if (!empty($_REQUEST['goto'])) {
407
+    switch ($_REQUEST['goto']) {
408 408
         case $mod_strings['LBL_CHECKSYS_RECHECK']:
409 409
             $next_step = $_REQUEST['current_step'];
410 410
             break;
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
     }
427 427
 }
428 428
 // Add check here to see if a silent install config file exists; if so then launch silent installer
429
-elseif ( is_file('config_si.php') && empty($sugar_config['installer_locked'])) {
429
+elseif (is_file('config_si.php') && empty($sugar_config['installer_locked'])) {
430 430
 
431 431
 $langHeader = get_language_header();
432 432
 
@@ -471,13 +471,13 @@  discard block
 block discarded – undo
471 471
 
472 472
 
473 473
 
474
-    $exclude_files = array('complete_install.php','register.php','download_modules.php');
474
+    $exclude_files = array('complete_install.php', 'register.php', 'download_modules.php');
475 475
 
476
-if(isset($next_step) && isset($workflow[$next_step]) && !in_array($workflow[$next_step],$exclude_files) && isset($sugar_config['installer_locked']) && $sugar_config['installer_locked'] == true) {
476
+if (isset($next_step) && isset($workflow[$next_step]) && !in_array($workflow[$next_step], $exclude_files) && isset($sugar_config['installer_locked']) && $sugar_config['installer_locked'] == true) {
477 477
     $the_file = 'installDisabled.php';
478 478
 	$disabled_title = $mod_strings['LBL_DISABLED_DESCRIPTION'];
479 479
 	$disabled_title_2 = $mod_strings['LBL_DISABLED_TITLE_2'];
480
-	$disabled_text =<<<EOQ
480
+	$disabled_text = <<<EOQ
481 481
 		<p>{$mod_strings['LBL_DISABLED_DESCRIPTION']}</p>
482 482
 		<pre>
483 483
 			'installer_locked' => false,
@@ -487,12 +487,12 @@  discard block
 block discarded – undo
487 487
 		<p>{$mod_strings['LBL_DISABLED_HELP_1']} <a href="{$mod_strings['LBL_DISABLED_HELP_LNK']}" target="_blank">{$mod_strings['LBL_DISABLED_HELP_2']}</a>.</p>
488 488
 EOQ;
489 489
 }
490
-else{
490
+else {
491 491
 $validation_errors = array();
492 492
 // process the data posted
493
-if($next_clicked) {
493
+if ($next_clicked) {
494 494
 	// store the submitted data because the 'Next' button was clicked
495
-    switch($workflow[trim($_REQUEST['current_step'])]) {
495
+    switch ($workflow[trim($_REQUEST['current_step'])]) {
496 496
         case 'welcome.php':
497 497
         	$_SESSION['language'] = $_REQUEST['language'];
498 498
    			$_SESSION['setup_site_admin_user_name'] = 'admin';
@@ -503,25 +503,25 @@  discard block
 block discarded – undo
503 503
 
504 504
 
505 505
            // eventually default all vars here, with overrides from config.php
506
-            if(is_readable('config.php')) {
506
+            if (is_readable('config.php')) {
507 507
             	global $sugar_config;
508 508
                 include_once('config.php');
509 509
             }
510 510
 
511 511
             $default_db_type = 'mysql';
512 512
 
513
-            if(!isset($_SESSION['setup_db_type'])) {
513
+            if (!isset($_SESSION['setup_db_type'])) {
514 514
                 $_SESSION['setup_db_type'] = empty($sugar_config['dbconfig']['db_type']) ? $default_db_type : $sugar_config['dbconfig']['db_type'];
515 515
             }
516 516
 
517 517
             break;
518 518
         //TODO--low: add this functionality to installConfig.php
519 519
         case 'installType.php':
520
-            $_SESSION['install_type']   = $_REQUEST['install_type'];
521
-            if(isset($_REQUEST['setup_license_key']) && !empty($_REQUEST['setup_license_key'])){
522
-                $_SESSION['setup_license_key']  = $_REQUEST['setup_license_key'];
520
+            $_SESSION['install_type'] = $_REQUEST['install_type'];
521
+            if (isset($_REQUEST['setup_license_key']) && !empty($_REQUEST['setup_license_key'])) {
522
+                $_SESSION['setup_license_key'] = $_REQUEST['setup_license_key'];
523 523
             }
524
-            $_SESSION['licenseKey_submitted']      = true;
524
+            $_SESSION['licenseKey_submitted'] = true;
525 525
 
526 526
 
527 527
 
@@ -530,39 +530,39 @@  discard block
 block discarded – undo
530 530
         case 'installConfig.php':
531 531
 
532 532
         //case 'systemOptions.php':
533
-            if(isset($_REQUEST['setup_db_type'])) {
533
+            if (isset($_REQUEST['setup_db_type'])) {
534 534
               $_SESSION['setup_db_type'] = $_REQUEST['setup_db_type'];
535 535
             }
536 536
             $validation_errors = validate_systemOptions();
537
-            if(count($validation_errors) > 0) {
537
+            if (count($validation_errors) > 0) {
538 538
                 $next_step--;
539 539
             }
540 540
             //break;
541 541
 
542 542
         //case 'dbConfig_a.php':
543 543
             //validation is now done through ajax call to checkDBSettings.php
544
-            if(isset($_REQUEST['setup_db_drop_tables'])){
544
+            if (isset($_REQUEST['setup_db_drop_tables'])) {
545 545
                 $_SESSION['setup_db_drop_tables'] = $_REQUEST['setup_db_drop_tables'];
546
-                if($_SESSION['setup_db_drop_tables']=== true || $_SESSION['setup_db_drop_tables'] == 'true'){
546
+                if ($_SESSION['setup_db_drop_tables'] === true || $_SESSION['setup_db_drop_tables'] == 'true') {
547 547
                     $_SESSION['setup_db_create_database'] = false;
548 548
                 }
549 549
             }
550 550
             //break;
551 551
 
552 552
         //case 'siteConfig_a.php':
553
-            if(isset($_REQUEST['setup_site_url'])){$_SESSION['setup_site_url']          = $_REQUEST['setup_site_url'];}
554
-            if(isset($_REQUEST['setup_system_name'])){$_SESSION['setup_system_name']    = $_REQUEST['setup_system_name'];}
555
-            if(isset($_REQUEST['setup_db_collation'])) {
553
+            if (isset($_REQUEST['setup_site_url'])) {$_SESSION['setup_site_url']          = $_REQUEST['setup_site_url']; }
554
+            if (isset($_REQUEST['setup_system_name'])) {$_SESSION['setup_system_name']    = $_REQUEST['setup_system_name']; }
555
+            if (isset($_REQUEST['setup_db_collation'])) {
556 556
                 $_SESSION['setup_db_options']['collation'] = $_REQUEST['setup_db_collation'];
557 557
             }
558 558
             $_SESSION['setup_site_admin_user_name']             = $_REQUEST['setup_site_admin_user_name'];
559 559
             $_SESSION['setup_site_admin_password']              = $_REQUEST['setup_site_admin_password'];
560 560
             $_SESSION['setup_site_admin_password_retype']       = $_REQUEST['setup_site_admin_password_retype'];
561
-            $_SESSION['siteConfig_submitted']               = true;
561
+            $_SESSION['siteConfig_submitted'] = true;
562 562
 
563 563
             $validation_errors = array();
564 564
             $validation_errors = validate_siteConfig('a');
565
-            if(count($validation_errors) > 0 || $_REQUEST['goto'] == 'resend') {
565
+            if (count($validation_errors) > 0 || $_REQUEST['goto'] == 'resend') {
566 566
                 $next_step--;
567 567
             }
568 568
             //break;
@@ -570,56 +570,56 @@  discard block
 block discarded – undo
570 570
         //case 'siteConfig_b.php':
571 571
             $_SESSION['setup_site_sugarbeet_automatic_checks'] = get_boolean_from_request('setup_site_sugarbeet_automatic_checks');
572 572
 
573
-            $_SESSION['setup_site_custom_session_path']     = get_boolean_from_request('setup_site_custom_session_path');
574
-            if($_SESSION['setup_site_custom_session_path']){
575
-                $_SESSION['setup_site_session_path']            = $_REQUEST['setup_site_session_path'];
576
-            }else{
573
+            $_SESSION['setup_site_custom_session_path'] = get_boolean_from_request('setup_site_custom_session_path');
574
+            if ($_SESSION['setup_site_custom_session_path']) {
575
+                $_SESSION['setup_site_session_path'] = $_REQUEST['setup_site_session_path'];
576
+            } else {
577 577
                 $_SESSION['setup_site_session_path'] = '';
578 578
             }
579 579
 
580
-            $_SESSION['setup_site_custom_log_dir']          = get_boolean_from_request('setup_site_custom_log_dir');
581
-            if($_SESSION['setup_site_custom_log_dir']){
582
-                $_SESSION['setup_site_log_dir']                 = $_REQUEST['setup_site_log_dir'];
583
-            }else{
580
+            $_SESSION['setup_site_custom_log_dir'] = get_boolean_from_request('setup_site_custom_log_dir');
581
+            if ($_SESSION['setup_site_custom_log_dir']) {
582
+                $_SESSION['setup_site_log_dir'] = $_REQUEST['setup_site_log_dir'];
583
+            } else {
584 584
                 $_SESSION['setup_site_log_dir'] = '.';
585 585
             }
586 586
 
587
-            $_SESSION['setup_site_specify_guid']            = get_boolean_from_request('setup_site_specify_guid');
588
-            if($_SESSION['setup_site_specify_guid']){
589
-                $_SESSION['setup_site_guid']                    = $_REQUEST['setup_site_guid'];
590
-            }else{
587
+            $_SESSION['setup_site_specify_guid'] = get_boolean_from_request('setup_site_specify_guid');
588
+            if ($_SESSION['setup_site_specify_guid']) {
589
+                $_SESSION['setup_site_guid'] = $_REQUEST['setup_site_guid'];
590
+            } else {
591 591
                 $_SESSION['setup_site_guid'] = '';
592 592
             }
593
-            $_SESSION['siteConfig_submitted']               = true;
594
-            if(isset($_REQUEST['setup_site_sugarbeet_anonymous_stats'])){
593
+            $_SESSION['siteConfig_submitted'] = true;
594
+            if (isset($_REQUEST['setup_site_sugarbeet_anonymous_stats'])) {
595 595
                 $_SESSION['setup_site_sugarbeet_anonymous_stats'] = get_boolean_from_request('setup_site_sugarbeet_anonymous_stats');
596
-            }else{
596
+            } else {
597 597
                 $_SESSION['setup_site_sugarbeet_anonymous_stats'] = 0;
598 598
             }
599 599
 
600 600
             $validation_errors = array();
601 601
             $validation_errors = validate_siteConfig('b');
602
-            if(count($validation_errors) > 0) {
602
+            if (count($validation_errors) > 0) {
603 603
                 $next_step--;
604 604
             }
605 605
             break;
606 606
 }
607 607
     }
608 608
 
609
-if($next_step == 9999) {
609
+if ($next_step == 9999) {
610 610
     $the_file = 'SilentInstall';
611
-}else if($next_step == 9191) {
612
-	$_SESSION['oc_server_url']	= $_REQUEST['oc_server_url'];
611
+} else if ($next_step == 9191) {
612
+	$_SESSION['oc_server_url'] = $_REQUEST['oc_server_url'];
613 613
     $_SESSION['oc_username']    = $_REQUEST['oc_username'];
614 614
     $_SESSION['oc_password']   	= $_REQUEST['oc_password'];
615 615
     $the_file = 'oc_convert.php';
616 616
 }
617
-else{
617
+else {
618 618
         $the_file = $workflow[$next_step];
619 619
 
620 620
 }
621 621
 
622
-switch($the_file) {
622
+switch ($the_file) {
623 623
     case 'welcome.php':
624 624
     case 'license.php':
625 625
 			//
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 			unset($_SESSION['test_session']);
631 631
         @session_start();
632 632
 
633
-			if(!isset($_SESSION['test_session']))
633
+			if (!isset($_SESSION['test_session']))
634 634
 			{
635 635
                 $the_file = 'installDisabled.php';
636 636
 				// PHP.ini location -
@@ -641,14 +641,14 @@  discard block
 block discarded – undo
641 641
             break;
642 642
 			}
643 643
         // check to see if installer has been disabled
644
-        if(is_readable('config.php') && (filesize('config.php') > 0)) {
644
+        if (is_readable('config.php') && (filesize('config.php') > 0)) {
645 645
             include_once('config.php');
646 646
 
647
-            if(!isset($sugar_config['installer_locked']) || $sugar_config['installer_locked'] == true) {
647
+            if (!isset($sugar_config['installer_locked']) || $sugar_config['installer_locked'] == true) {
648 648
                 $the_file = 'installDisabled.php';
649 649
 				$disabled_title = $mod_strings['LBL_DISABLED_DESCRIPTION'];
650 650
 				$disabled_title_2 = $mod_strings['LBL_DISABLED_TITLE_2'];
651
-				$disabled_text =<<<EOQ
651
+				$disabled_text = <<<EOQ
652 652
 					<p>{$mod_strings['LBL_DISABLED_DESCRIPTION']}</p>
653 653
 					<pre>
654 654
 						'installer_locked' => false,
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 EOQ;
660 660
 		             //if this is an offline client installation but the conversion did not succeed,
661 661
 		            //then try to convert again
662
-					if(isset($sugar_config['disc_client']) && $sugar_config['disc_client'] == true && isset($sugar_config['oc_converted']) && $sugar_config['oc_converted'] == false) {
662
+					if (isset($sugar_config['disc_client']) && $sugar_config['disc_client'] == true && isset($sugar_config['oc_converted']) && $sugar_config['oc_converted'] == false) {
663 663
 			          header('Location: index.php?entryPoint=oc_convert&first_time=true');
664 664
 						exit ();
665 665
 		            }
@@ -689,22 +689,22 @@  discard block
 block discarded – undo
689 689
         }
690 690
 
691 691
         $validation_errors = validate_dbConfig('a');
692
-        if(count($validation_errors) > 0) {
692
+        if (count($validation_errors) > 0) {
693 693
             $the_file = 'dbConfig_a.php';
694 694
             $si_errors = true;
695 695
         }
696 696
         $validation_errors = validate_siteConfig('a');
697
-        if(count($validation_errors) > 0) {
697
+        if (count($validation_errors) > 0) {
698 698
             $the_file = 'siteConfig_a.php';
699 699
             $si_errors = true;
700 700
         }
701 701
         $validation_errors = validate_siteConfig('b');
702
-        if(count($validation_errors) > 0) {
702
+        if (count($validation_errors) > 0) {
703 703
             $the_file = 'siteConfig_b.php';
704 704
             $si_errors = true;
705 705
         }
706 706
 
707
-        if(!$si_errors){
707
+        if (!$si_errors) {
708 708
             $the_file = 'performSetup.php';
709 709
         }
710 710
         require_once('jssource/minify.php');
@@ -734,13 +734,13 @@  discard block
 block discarded – undo
734 734
         // check whether we're getting this request from a command line tool
735 735
         // we want to output brief messages if we're outputting to a command line tool
736 736
         $cli_mode = false;
737
-        if(isset($_REQUEST['cli']) && ($_REQUEST['cli'] == 'true')) {
737
+        if (isset($_REQUEST['cli']) && ($_REQUEST['cli'] == 'true')) {
738 738
             $_SESSION['cli'] = true;
739 739
             // if we have errors, just shoot them back now
740
-            if(count($validation_errors) > 0) {
741
-                foreach($validation_errors as $error) {
740
+            if (count($validation_errors) > 0) {
741
+                foreach ($validation_errors as $error) {
742 742
                     print($mod_strings['ERR_ERROR_GENERAL']."\n");
743
-                    print("    " . $error . "\n");
743
+                    print("    ".$error."\n");
744 744
                     print("Exit 1\n");
745 745
                     exit(1);
746 746
                 }
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 
758 758
 // change to require to get a good file load error message if the file is not available.
759 759
 
760
-require('install/' . $the_file);
760
+require('install/'.$the_file);
761 761
 
762 762
 installerHook('post_installFileRequire', array('the_file' => $the_file));
763 763
 
Please login to merge, or discard this patch.
modules/AOR_Reports/aor_utils.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     $fieldDisplay = $currentBean->field_name_map[$field]['vname'];
63 63
     $fieldDisplay = translate($fieldDisplay, $currentBean->module_dir);
64 64
     $fieldDisplay = trim($fieldDisplay, ':');
65
-    foreach($modulePathDisplay as &$module) {
65
+    foreach ($modulePathDisplay as &$module) {
66 66
         $module = isset($app_list_strings['aor_moduleList'][$module]) ? $app_list_strings['aor_moduleList'][$module] : (
67 67
             isset($app_list_strings['moduleList'][$module]) ? $app_list_strings['moduleList'][$module] : $module
68 68
         );
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 function requestToUserParameters()
74 74
 {
75 75
     $params = array();
76
-    if(isset($_REQUEST['parameter_id']) && $_REQUEST['parameter_id']) {
76
+    if (isset($_REQUEST['parameter_id']) && $_REQUEST['parameter_id']) {
77 77
         foreach ($_REQUEST['parameter_id'] as $key => $parameterId) {
78 78
             if ($_REQUEST['parameter_type'][$key] === 'Multi') {
79 79
                 $_REQUEST['parameter_value'][$key] = encodeMultienumValue(explode(',', $_REQUEST['parameter_value'][$key]));
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
             if ($_REQUEST['parameter_type'][$key] === 'Date') {
89 89
                 $values = array();
90 90
                 $values[] = $_REQUEST['parameter_value'][0];
91
-                $values[] = $_REQUEST['parameter_value'][1];;
92
-                $values[] = $_REQUEST['parameter_value'][2];;
93
-                $values[] = $_REQUEST['parameter_value'][3];;
91
+                $values[] = $_REQUEST['parameter_value'][1]; ;
92
+                $values[] = $_REQUEST['parameter_value'][2]; ;
93
+                $values[] = $_REQUEST['parameter_value'][3]; ;
94 94
 
95 95
                 $params[$parameterId] = array(
96 96
                     'id' => $parameterId,
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
  */
228 228
 function getPeriodEndDate($dateTimePeriodListSelected)
229 229
 {
230
-    switch($dateTimePeriodListSelected) {
230
+    switch ($dateTimePeriodListSelected) {
231 231
         case 'today':
232 232
         case 'yesterday':
233 233
             $datetimePeriod = new DateTime();
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     $offsetMonths -= 1;
328 328
     // Offset months
329 329
     if ($offsetMonths > 0) {
330
-        $q1start->add(new DateInterval('P' . $offsetMonths . 'M'));
330
+        $q1start->add(new DateInterval('P'.$offsetMonths.'M'));
331 331
     }
332 332
     $q1end = DateTime::createFromFormat(DATE_ISO8601, $q1start->format(DATE_ISO8601));
333 333
     $q1end->add(new DateInterval('P2M'));
Please login to merge, or discard this patch.
modules/AM_ProjectTemplates/controller.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
  * @author Andrew Mclaughlan <[email protected]>
20 20
  */
21 21
 
22
-if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
22
+if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
23 23
 
24 24
 class AM_ProjectTemplatesController extends SugarController {
25 25
 
26
-    function action_create_project(){
26
+    function action_create_project() {
27 27
 
28 28
         global $current_user, $db;
29 29
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         $template_id = $_POST['template_id'];
32 32
         $project_start = $_POST['start_date'];
33 33
         //Get project start date
34
-		if($project_start!='')
34
+		if ($project_start != '')
35 35
 		{
36 36
 			$dateformat = $current_user->getPreference('datef');
37 37
 			$startdate = DateTime::createFromFormat($dateformat, $project_start);
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
                         ORDER BY am_tasktemplates.order_number ASC";
74 74
         $tasks = $db->query($get_tasks);
75 75
         //Create new project tasks from the template tasks
76
-        $count=1;
77
-        while($row = $db->fetchByAssoc($tasks))
76
+        $count = 1;
77
+        while ($row = $db->fetchByAssoc($tasks))
78 78
         {
79 79
             $project_task = new ProjectTask();
80 80
             $project_task->name = $row['name'];
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
             //Flag to prevent after save logichook running when project_tasks are created (see custom/modules/ProjectTask/updateProject.php)
96 96
             $project_task->set_project_end_date = 0;
97 97
 
98
-            if($count == '1'){
98
+            if ($count == '1') {
99 99
                 $project_task->date_start = $start;
100 100
                 $enddate = $startdate->modify('+'.$row['duration'].' '.$duration_unit);
101 101
                 $end = $enddate->format('Y-m-d');
102 102
                 $project_task->date_finish = $end;
103 103
                 $enddate_array[$count] = $end;
104
-                $GLOBALS['log']->fatal("DATE:". $end);
104
+                $GLOBALS['log']->fatal("DATE:".$end);
105 105
             }
106 106
             else {
107 107
                 $start_date = $count - 1;
108 108
                 $startdate = DateTime::createFromFormat('Y-m-d', $enddate_array[$start_date]);
109
-                $GLOBALS['log']->fatal("DATE:". $enddate_array[$start_date]);
109
+                $GLOBALS['log']->fatal("DATE:".$enddate_array[$start_date]);
110 110
                 $start = $startdate->format('Y-m-d');
111 111
                 $project_task->date_start = $start;
112 112
                 $enddate = $startdate->modify('+'.$row['duration'].' '.$duration_unit);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             'action'=>'DetailView',
137 137
             'record' => $project->id,
138 138
         );
139
-        SugarApplication::redirect('index.php?' . http_build_query($params));
139
+        SugarApplication::redirect('index.php?'.http_build_query($params));
140 140
     }
141 141
 
142 142
 }
Please login to merge, or discard this patch.
modules/EmailTemplates/PopupDocumentsCampaignTemplate.php 1 patch
Spacing   +5 added lines, -5 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.
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
 	public function _get_where_clause() {
57 57
 		$where = '';
58
-		if(isset($_REQUEST['query']))
58
+		if (isset($_REQUEST['query']))
59 59
 		{
60 60
 			$where_clauses = array();
61 61
 			append_where_clause($where_clauses, "document_name", "documents.document_name");
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 
99 99
 
100 100
 $hide_clear_button = empty($_REQUEST['hide_clear_button']) ? false : true;
101
-$button  = "<form action='index.php' method='post' name='form' id='form'>\n";
102
-if(!$hide_clear_button)
101
+$button = "<form action='index.php' method='post' name='form' id='form'>\n";
102
+if (!$hide_clear_button)
103 103
 {
104 104
 	$button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='"
105 105
 		.$app_strings['LBL_CLEAR_BUTTON_TITLE']."' value='  "
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 $form->assign('MODULE_NAME', $currentModule);
120 120
 $form->assign('NAME', $name);
121 121
 $form->assign('DOCUMENT_NAME', $document_name);
122
-if(isset($_REQUEST['target'])) $form->assign('DOCUMENT_TARGET', $_REQUEST['target']);
122
+if (isset($_REQUEST['target'])) $form->assign('DOCUMENT_TARGET', $_REQUEST['target']);
123 123
 else $form->assign('DOCUMENT_TARGET', '');
124 124
 
125 125
 $form->assign('DOCUMENT_REVISION_ID', $document_revision_id);
Please login to merge, or discard this patch.
data/SugarBean.php 1 patch
Spacing   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -311,17 +311,17 @@  discard block
 block discarded – undo
311 311
                     $this->optimistic_lock = true;
312 312
                 }
313 313
             }
314
-            $loaded_defs[$this->object_name]['column_fields'] =& $this->column_fields;
315
-            $loaded_defs[$this->object_name]['list_fields'] =& $this->list_fields;
316
-            $loaded_defs[$this->object_name]['required_fields'] =& $this->required_fields;
317
-            $loaded_defs[$this->object_name]['field_name_map'] =& $this->field_name_map;
318
-            $loaded_defs[$this->object_name]['field_defs'] =& $this->field_defs;
314
+            $loaded_defs[$this->object_name]['column_fields'] = & $this->column_fields;
315
+            $loaded_defs[$this->object_name]['list_fields'] = & $this->list_fields;
316
+            $loaded_defs[$this->object_name]['required_fields'] = & $this->required_fields;
317
+            $loaded_defs[$this->object_name]['field_name_map'] = & $this->field_name_map;
318
+            $loaded_defs[$this->object_name]['field_defs'] = & $this->field_defs;
319 319
         } else {
320
-            $this->column_fields =& $loaded_defs[$this->object_name]['column_fields'];
321
-            $this->list_fields =& $loaded_defs[$this->object_name]['list_fields'];
322
-            $this->required_fields =& $loaded_defs[$this->object_name]['required_fields'];
323
-            $this->field_name_map =& $loaded_defs[$this->object_name]['field_name_map'];
324
-            $this->field_defs =& $loaded_defs[$this->object_name]['field_defs'];
320
+            $this->column_fields = & $loaded_defs[$this->object_name]['column_fields'];
321
+            $this->list_fields = & $loaded_defs[$this->object_name]['list_fields'];
322
+            $this->required_fields = & $loaded_defs[$this->object_name]['required_fields'];
323
+            $this->field_name_map = & $loaded_defs[$this->object_name]['field_name_map'];
324
+            $this->field_defs = & $loaded_defs[$this->object_name]['field_defs'];
325 325
             $this->added_custom_field_defs = true;
326 326
 
327 327
             if (!isset($this->custom_fields) &&
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
     /**
344 344
      * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
345 345
      */
346
-    public function SugarBean(){
346
+    public function SugarBean() {
347 347
         $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
348
-        if(isset($GLOBALS['log'])) {
348
+        if (isset($GLOBALS['log'])) {
349 349
             $GLOBALS['log']->deprecated($deprecatedMessage);
350 350
         }
351 351
         else {
@@ -457,14 +457,14 @@  discard block
 block discarded – undo
457 457
     {
458 458
         //load the module dictionary if not supplied.
459 459
         if ((!isset($dictionary) or empty($dictionary)) && !empty($module_dir)) {
460
-            $filename = 'modules/' . $module_dir . '/vardefs.php';
460
+            $filename = 'modules/'.$module_dir.'/vardefs.php';
461 461
             if (file_exists($filename)) {
462 462
                 include($filename);
463 463
             }
464 464
         }
465 465
         if (!is_array($dictionary) or !array_key_exists($key, $dictionary)) {
466
-            $GLOBALS['log']->fatal("removeRelationshipMeta: Metadata for table " . $tablename . " does not exist");
467
-            display_notice("meta data absent for table " . $tablename . " keyed to $key ");
466
+            $GLOBALS['log']->fatal("removeRelationshipMeta: Metadata for table ".$tablename." does not exist");
467
+            display_notice("meta data absent for table ".$tablename." keyed to $key ");
468 468
         } else {
469 469
             if (isset($dictionary[$key]['relationships'])) {
470 470
                 $RelationshipDefs = $dictionary[$key]['relationships'];
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
         //load the module dictionary if not supplied.
496 496
         if (empty($dictionary) && !empty($module_dir)) {
497 497
             if ($is_custom) {
498
-                $filename = 'custom/modules/' . $module_dir . '/Ext/Vardefs/vardefs.ext.php';
498
+                $filename = 'custom/modules/'.$module_dir.'/Ext/Vardefs/vardefs.ext.php';
499 499
             } else {
500 500
                 if ($key == 'User') {
501 501
                     // a very special case for the Employees module
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
                     // Users/vardefs.php
504 504
                     $filename = 'modules/Users/vardefs.php';
505 505
                 } else {
506
-                    $filename = 'modules/' . $module_dir . '/vardefs.php';
506
+                    $filename = 'modules/'.$module_dir.'/vardefs.php';
507 507
                 }
508 508
             }
509 509
 
@@ -514,14 +514,14 @@  discard block
 block discarded – undo
514 514
                     $dictionary = $GLOBALS['dictionary'];
515 515
                 }
516 516
             } else {
517
-                $GLOBALS['log']->debug("createRelationshipMeta: no metadata file found" . $filename);
517
+                $GLOBALS['log']->debug("createRelationshipMeta: no metadata file found".$filename);
518 518
                 return;
519 519
             }
520 520
         }
521 521
 
522 522
         if (!is_array($dictionary) or !array_key_exists($key, $dictionary)) {
523
-            $GLOBALS['log']->fatal("createRelationshipMeta: Metadata for table " . $tablename . " does not exist");
524
-            display_notice("meta data absent for table " . $tablename . " keyed to $key ");
523
+            $GLOBALS['log']->fatal("createRelationshipMeta: Metadata for table ".$tablename." does not exist");
524
+            display_notice("meta data absent for table ".$tablename." keyed to $key ");
525 525
         } else {
526 526
             if (isset($dictionary[$key]['relationships'])) {
527 527
                 $RelationshipDefs = $dictionary[$key]['relationships'];
@@ -530,18 +530,18 @@  discard block
 block discarded – undo
530 530
                 $beanList_ucase = array_change_key_case($beanList, CASE_UPPER);
531 531
                 foreach ($RelationshipDefs as $rel_name => $rel_def) {
532 532
                     if (isset($rel_def['lhs_module']) and !isset($beanList_ucase[strtoupper($rel_def['lhs_module'])])) {
533
-                        $GLOBALS['log']->debug('skipping orphaned relationship record ' . $rel_name . ' lhs module is missing ' . $rel_def['lhs_module']);
533
+                        $GLOBALS['log']->debug('skipping orphaned relationship record '.$rel_name.' lhs module is missing '.$rel_def['lhs_module']);
534 534
                         continue;
535 535
                     }
536 536
                     if (isset($rel_def['rhs_module']) and !isset($beanList_ucase[strtoupper($rel_def['rhs_module'])])) {
537
-                        $GLOBALS['log']->debug('skipping orphaned relationship record ' . $rel_name . ' rhs module is missing ' . $rel_def['rhs_module']);
537
+                        $GLOBALS['log']->debug('skipping orphaned relationship record '.$rel_name.' rhs module is missing '.$rel_def['rhs_module']);
538 538
                         continue;
539 539
                     }
540 540
 
541 541
 
542 542
                     //check whether relationship exists or not first.
543 543
                     if (Relationship::exists($rel_name, $db)) {
544
-                        $GLOBALS['log']->debug('Skipping, relationship already exists ' . $rel_name);
544
+                        $GLOBALS['log']->debug('Skipping, relationship already exists '.$rel_name);
545 545
                     } else {
546 546
                         $seed = BeanFactory::getBean("Relationships");
547 547
                         $keys = array_keys($seed->field_defs);
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
 
560 560
 
561 561
                         $column_list = implode(",", array_keys($toInsert));
562
-                        $value_list = "'" . implode("','", array_values($toInsert)) . "'";
562
+                        $value_list = "'".implode("','", array_values($toInsert))."'";
563 563
 
564 564
                         //create the record. todo add error check.
565
-                        $insert_string = "INSERT into relationships (" . $column_list . ") values (" . $value_list . ")";
565
+                        $insert_string = "INSERT into relationships (".$column_list.") values (".$value_list.")";
566 566
                         $db->query($insert_string, true);
567 567
                     }
568 568
                 }
@@ -638,11 +638,11 @@  discard block
 block discarded – undo
638 638
                     $tmp_final_query = $parentbean->$shortcut_function_name();
639 639
                 }
640 640
                 if (!$first) {
641
-                    $final_query_rows .= ' UNION ALL ( ' . $parentbean->create_list_count_query($tmp_final_query, $parameters) . ' )';
642
-                    $final_query .= ' UNION ALL ( ' . $tmp_final_query . ' )';
641
+                    $final_query_rows .= ' UNION ALL ( '.$parentbean->create_list_count_query($tmp_final_query, $parameters).' )';
642
+                    $final_query .= ' UNION ALL ( '.$tmp_final_query.' )';
643 643
                 } else {
644
-                    $final_query_rows = '(' . $parentbean->create_list_count_query($tmp_final_query, $parameters) . ')';
645
-                    $final_query = '(' . $tmp_final_query . ')';
644
+                    $final_query_rows = '('.$parentbean->create_list_count_query($tmp_final_query, $parameters).')';
645
+                    $final_query = '('.$tmp_final_query.')';
646 646
                     $first = false;
647 647
                 }
648 648
             }
@@ -673,32 +673,32 @@  discard block
 block discarded – undo
673 673
                 }
674 674
                 $subquery['select'] = substr($subquery['select'], 0, strlen($subquery['select']) - 1);
675 675
                 //Put the query into the final_query
676
-                $query = $subquery['select'] . " " . $subquery['from'] . " " . $subquery['where'];
676
+                $query = $subquery['select']." ".$subquery['from']." ".$subquery['where'];
677 677
                 if (!$first) {
678
-                    $query = ' UNION ALL ( ' . $query . ' )';
678
+                    $query = ' UNION ALL ( '.$query.' )';
679 679
                     $final_query_rows .= " UNION ALL ";
680 680
                 } else {
681
-                    $query = '(' . $query . ')';
681
+                    $query = '('.$query.')';
682 682
                     $first = false;
683 683
                 }
684 684
                 $query_array = $subquery['query_array'];
685 685
                 $select_position = strpos($query_array['select'], "SELECT");
686 686
                 $distinct_position = strpos($query_array['select'], "DISTINCT");
687 687
                 if (!empty($subquery['params']['distinct']) && !empty($subpanel_def->table_name)) {
688
-                    $query_rows = "( SELECT count(DISTINCT " . $subpanel_def->table_name . ".id)" . $subquery['from_min'] . $query_array['join'] . $subquery['where'] . ' )';
688
+                    $query_rows = "( SELECT count(DISTINCT ".$subpanel_def->table_name.".id)".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
689 689
                 } elseif ($select_position !== false && $distinct_position != false) {
690
-                    $query_rows = "( " . substr_replace($query_array['select'], "SELECT count(", $select_position, 6) . ")" . $subquery['from_min'] . $query_array['join'] . $subquery['where'] . ' )';
690
+                    $query_rows = "( ".substr_replace($query_array['select'], "SELECT count(", $select_position, 6).")".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
691 691
                 } else {
692 692
                     //resort to default behavior.
693
-                    $query_rows = "( SELECT count(*)" . $subquery['from_min'] . $query_array['join'] . $subquery['where'] . ' )';
693
+                    $query_rows = "( SELECT count(*)".$subquery['from_min'].$query_array['join'].$subquery['where'].' )';
694 694
                 }
695 695
                 if (!empty($subquery['secondary_select'])) {
696
-                    $subquerystring = $subquery['secondary_select'] . $subquery['secondary_from'] . $query_array['join'] . $subquery['where'];
696
+                    $subquerystring = $subquery['secondary_select'].$subquery['secondary_from'].$query_array['join'].$subquery['where'];
697 697
                     if (!empty($subquery['secondary_where'])) {
698 698
                         if (empty($subquery['where'])) {
699
-                            $subquerystring .= " WHERE " . $subquery['secondary_where'];
699
+                            $subquerystring .= " WHERE ".$subquery['secondary_where'];
700 700
                         } else {
701
-                            $subquerystring .= " AND " . $subquery['secondary_where'];
701
+                            $subquerystring .= " AND ".$subquery['secondary_where'];
702 702
                         }
703 703
                     }
704 704
                     $secondary_queries[] = $subquerystring;
@@ -721,12 +721,12 @@  discard block
 block discarded – undo
721 721
             }
722 722
 
723 723
             if (!empty($sort_order)) {
724
-                $order_by .= ' ' . $sort_order;
724
+                $order_by .= ' '.$sort_order;
725 725
             }
726 726
 
727 727
             $order_by = $parentbean->process_order_by($order_by, $submodule, $suppress_table_name);
728 728
             if (!empty($order_by)) {
729
-                $final_query .= ' ORDER BY ' . $order_by;
729
+                $final_query .= ' ORDER BY '.$order_by;
730 730
             }
731 731
         }
732 732
 
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
                     if (empty($where_definition)) {
795 795
                         $where_definition = $table_where;
796 796
                     } else {
797
-                        $where_definition .= ' AND ' . $table_where;
797
+                        $where_definition .= ' AND '.$table_where;
798 798
                     }
799 799
                 }
800 800
 
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 
816 816
 
817 817
                 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')) {
818
-                    $order_by = $submodule->table_name . '.' . $order_by;
818
+                    $order_by = $submodule->table_name.'.'.$order_by;
819 819
                 }
820 820
                 $table_name = $this_subpanel->table_name;
821 821
                 $panel_name = $this_subpanel->name;
@@ -831,8 +831,8 @@  discard block
 block discarded – undo
831 831
 
832 832
                 $subquery = $submodule->create_new_list_query('', $subwhere, $list_fields, $params, 0, '', true, $parentbean, $singleSelect);
833 833
 
834
-                $subquery['select'] = $subquery['select'] . " , '$panel_name' panel_name ";
835
-                $subquery['from'] = $subquery['from'] . $query_array['join'];
834
+                $subquery['select'] = $subquery['select']." , '$panel_name' panel_name ";
835
+                $subquery['from'] = $subquery['from'].$query_array['join'];
836 836
                 $subquery['query_array'] = $query_array;
837 837
                 $subquery['params'] = $params;
838 838
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
         $use_count_query = false;
871 871
         $processing_collection = $subpanel_def->isCollection();
872 872
 
873
-        $GLOBALS['log']->debug("process_union_list_query: " . $query);
873
+        $GLOBALS['log']->debug("process_union_list_query: ".$query);
874 874
         if ($max_per_page == -1) {
875 875
             $max_per_page = $sugar_config['list_max_entries_per_subpanel'];
876 876
         }
@@ -947,9 +947,9 @@  discard block
 block discarded – undo
947 947
                         if (isset($row[$field])) {
948 948
                             $current_bean->$field = $this->convertField($row[$field], $value);
949 949
                             unset($row[$field]);
950
-                        } elseif (isset($row[$this->table_name . '.' . $field])) {
951
-                            $current_bean->$field = $this->convertField($row[$this->table_name . '.' . $field], $value);
952
-                            unset($row[$this->table_name . '.' . $field]);
950
+                        } elseif (isset($row[$this->table_name.'.'.$field])) {
951
+                            $current_bean->$field = $this->convertField($row[$this->table_name.'.'.$field], $value);
952
+                            unset($row[$this->table_name.'.'.$field]);
953 953
                         } else {
954 954
                             $current_bean->$field = "";
955 955
                             unset($row[$field]);
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
                         $class = $beanList[$child_info['parent_type']];
1117 1117
                         // Added to avoid error below; just silently fail and write message to log
1118 1118
                         if (empty($beanFiles[$class])) {
1119
-                            $GLOBALS['log']->error($this->object_name . '::retrieve_parent_fields() - cannot load class "' . $class . '", skip loading.');
1119
+                            $GLOBALS['log']->error($this->object_name.'::retrieve_parent_fields() - cannot load class "'.$class.'", skip loading.');
1120 1120
                             continue;
1121 1121
                         }
1122 1122
                         require_once($beanFiles[$class]);
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
                         $queries[$child_info['parent_type']] = "SELECT id ";
1128 1128
                         $field_def = $templates[$child_info['parent_type']]->field_defs['name'];
1129 1129
                         if (isset($field_def['db_concat_fields'])) {
1130
-                            $queries[$child_info['parent_type']] .= ' , ' . $this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']) . ' parent_name';
1130
+                            $queries[$child_info['parent_type']] .= ' , '.$this->db->concat($templates[$child_info['parent_type']]->table_name, $field_def['db_concat_fields']).' parent_name';
1131 1131
                         } else {
1132 1132
                             $queries[$child_info['parent_type']] .= ' , name parent_name';
1133 1133
                         }
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
                         } elseif (isset($templates[$child_info['parent_type']]->field_defs['created_by'])) {
1138 1138
                             $queries[$child_info['parent_type']] .= ", created_by parent_name_owner, '{$child_info['parent_type']}' parent_name_mod";
1139 1139
                         }
1140
-                        $queries[$child_info['parent_type']] .= " FROM " . $templates[$child_info['parent_type']]->table_name . " WHERE id IN ('{$child_info['parent_id']}'";
1140
+                        $queries[$child_info['parent_type']] .= " FROM ".$templates[$child_info['parent_type']]->table_name." WHERE id IN ('{$child_info['parent_id']}'";
1141 1141
                     } else {
1142 1142
                         if (empty($parent_child_map[$child_info['parent_id']])) {
1143 1143
                             $queries[$child_info['parent_type']] .= " ,'{$child_info['parent_id']}'";
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
         }
1150 1150
         $results = array();
1151 1151
         foreach ($queries as $query) {
1152
-            $result = $this->db->query($query . ')');
1152
+            $result = $this->db->query($query.')');
1153 1153
             while ($row = $this->db->fetchByAssoc($result)) {
1154 1154
                 $results[$row['id']] = $row;
1155 1155
             }
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
      */
1235 1235
     public function get_custom_table_name()
1236 1236
     {
1237
-        return $this->getTableName() . '_cstm';
1237
+        return $this->getTableName().'_cstm';
1238 1238
     }
1239 1239
 
1240 1240
     /**
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
      */
1475 1475
     public function load_relationship($rel_name)
1476 1476
     {
1477
-        $GLOBALS['log']->debug("SugarBean[{$this->object_name}].load_relationships, Loading relationship (" . $rel_name . ").");
1477
+        $GLOBALS['log']->debug("SugarBean[{$this->object_name}].load_relationships, Loading relationship (".$rel_name.").");
1478 1478
 
1479 1479
         if (empty($rel_name)) {
1480 1480
             $GLOBALS['log']->error("SugarBean.load_relationships, Null relationship name passed.");
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
                 return true;
1510 1510
             }
1511 1511
         }
1512
-        $GLOBALS['log']->debug("SugarBean.load_relationships, Error Loading relationship (" . $rel_name . ")");
1512
+        $GLOBALS['log']->debug("SugarBean.load_relationships, Error Loading relationship (".$rel_name.")");
1513 1513
         return false;
1514 1514
     }
1515 1515
 
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
                         $idField = $value_array['id_name'];
1617 1617
                         if (isset($fieldDefs[$idField]) && isset($fieldDefs[$idField]['type']) && $fieldDefs[$idField]['type'] == 'link') {
1618 1618
                             $tmpFieldDefs = $fieldDefs[$idField];
1619
-                            $tmpFieldDefs['vname'] = translate($value_array['vname'], $this->module_dir) . " " . $GLOBALS['app_strings']['LBL_ID'];
1619
+                            $tmpFieldDefs['vname'] = translate($value_array['vname'], $this->module_dir)." ".$GLOBALS['app_strings']['LBL_ID'];
1620 1620
                             $importableFields[$idField] = $tmpFieldDefs;
1621 1621
                         }
1622 1622
                     }
@@ -1640,8 +1640,8 @@  discard block
 block discarded – undo
1640 1640
 
1641 1641
         $key = $this->getObjectName();
1642 1642
         if (!array_key_exists($key, $dictionary)) {
1643
-            $GLOBALS['log']->fatal("create_tables: Metadata for table " . $this->table_name . " does not exist");
1644
-            display_notice("meta data absent for table " . $this->table_name . " keyed to $key ");
1643
+            $GLOBALS['log']->fatal("create_tables: Metadata for table ".$this->table_name." does not exist");
1644
+            display_notice("meta data absent for table ".$this->table_name." keyed to $key ");
1645 1645
         } else {
1646 1646
             if (!$this->db->tableExists($this->table_name)) {
1647 1647
                 $this->db->createTable($this);
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
      */
1703 1703
     public function get_audit_table_name()
1704 1704
     {
1705
-        return $this->getTableName() . '_audit';
1705
+        return $this->getTableName().'_audit';
1706 1706
     }
1707 1707
 
1708 1708
     /**
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
         require('metadata/audit_templateMetaData.php');
1721 1721
 
1722 1722
         // Bug: 52583 Need ability to customize template for audit tables
1723
-        $custom = 'custom/metadata/audit_templateMetaData_' . $this->getTableName() . '.php';
1723
+        $custom = 'custom/metadata/audit_templateMetaData_'.$this->getTableName().'.php';
1724 1724
         if (file_exists($custom)) {
1725 1725
             require($custom);
1726 1726
         }
@@ -1730,7 +1730,7 @@  discard block
 block discarded – undo
1730 1730
 
1731 1731
         // Renaming template indexes to fit the particular audit table (removed the brittle hard coding)
1732 1732
         foreach ($indices as $nr => $properties) {
1733
-            $indices[$nr]['name'] = 'idx_' . strtolower($this->getTableName()) . '_' . $properties['name'];
1733
+            $indices[$nr]['name'] = 'idx_'.strtolower($this->getTableName()).'_'.$properties['name'];
1734 1734
         }
1735 1735
 
1736 1736
         $engine = null;
@@ -1754,8 +1754,8 @@  discard block
 block discarded – undo
1754 1754
         global $dictionary;
1755 1755
         $key = $this->getObjectName();
1756 1756
         if (!array_key_exists($key, $dictionary)) {
1757
-            $GLOBALS['log']->fatal("drop_tables: Metadata for table " . $this->table_name . " does not exist");
1758
-            echo "meta data absent for table " . $this->table_name . "<br>\n";
1757
+            $GLOBALS['log']->fatal("drop_tables: Metadata for table ".$this->table_name." does not exist");
1758
+            echo "meta data absent for table ".$this->table_name."<br>\n";
1759 1759
         } else {
1760 1760
             if (empty($this->table_name)) {
1761 1761
                 return;
@@ -1763,8 +1763,8 @@  discard block
 block discarded – undo
1763 1763
             if ($this->db->tableExists($this->table_name)) {
1764 1764
                 $this->db->dropTable($this);
1765 1765
             }
1766
-            if ($this->db->tableExists($this->table_name . '_cstm')) {
1767
-                $this->db->dropTableName($this->table_name . '_cstm');
1766
+            if ($this->db->tableExists($this->table_name.'_cstm')) {
1767
+                $this->db->dropTableName($this->table_name.'_cstm');
1768 1768
                 DynamicField::deleteCache();
1769 1769
             }
1770 1770
             if ($this->db->tableExists($this->get_audit_table_name())) {
@@ -2059,7 +2059,7 @@  discard block
 block discarded – undo
2059 2059
                     break;
2060 2060
             }
2061 2061
             if ($reformatted) {
2062
-                $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');
2062
+                $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');
2063 2063
             }
2064 2064
         }
2065 2065
     }
@@ -2101,7 +2101,7 @@  discard block
 block discarded – undo
2101 2101
                     $_SESSION['o_lock_object'] = $this->toArray();
2102 2102
                     $saveform = "<form name='save' id='save' method='POST'>";
2103 2103
                     foreach ($_POST as $key => $arg) {
2104
-                        $saveform .= "<input type='hidden' name='" . addslashes($key) . "' value='" . addslashes($arg) . "'>";
2104
+                        $saveform .= "<input type='hidden' name='".addslashes($key)."' value='".addslashes($arg)."'>";
2105 2105
                     }
2106 2106
                     $saveform .= "</form><script>document.getElementById('save').submit();</script>";
2107 2107
                     $_SESSION['o_lock_save'] = $saveform;
@@ -2281,7 +2281,7 @@  discard block
 block discarded – undo
2281 2281
                     if ($rel_name == $new_rel_link && $this->$id != $new_rel_id) {
2282 2282
                         $new_rel_id = '';
2283 2283
                     }
2284
-                    $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - adding a relationship record: ' . $rel_name . ' = ' . $this->$id);
2284
+                    $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - adding a relationship record: '.$rel_name.' = '.$this->$id);
2285 2285
                     //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
2286 2286
                     $this->load_relationship($rel_name);
2287 2287
                     $rel_add = $this->$rel_name->add($this->$id);
@@ -2292,7 +2292,7 @@  discard block
 block discarded – undo
2292 2292
                 } else {
2293 2293
                     //if before value is not empty then attempt to delete relationship
2294 2294
                     if (!empty($this->rel_fields_before_value[$id])) {
2295
-                        $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - attempting to remove the relationship record, using relationship attribute' . $rel_name);
2295
+                        $GLOBALS['log']->debug('save_relationship_changes(): From relationship_field array - attempting to remove the relationship record, using relationship attribute'.$rel_name);
2296 2296
                         $this->load_relationship($rel_name);
2297 2297
                         $this->$rel_name->delete($this->id, $this->rel_fields_before_value[$id]);
2298 2298
                     }
@@ -2342,7 +2342,7 @@  discard block
 block discarded – undo
2342 2342
                             } else {
2343 2343
                                 $modified_relationships['remove']['failure'][] = $linkField;
2344 2344
                             }
2345
-                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to remove the relationship record returned " . var_export($success, true));
2345
+                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - attempting to remove the relationship record returned ".var_export($success, true));
2346 2346
                         }
2347 2347
 
2348 2348
                         if (!empty($this->$idName) && is_string($this->$idName)) {
@@ -2357,7 +2357,7 @@  discard block
 block discarded – undo
2357 2357
                                 $modified_relationships['add']['failure'][] = $linkField;
2358 2358
                             }
2359 2359
 
2360
-                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - add a relationship record returned " . var_export($success, true));
2360
+                            $GLOBALS['log']->debug("save_relationship_changes(): From field_defs - add a relationship record returned ".var_export($success, true));
2361 2361
                         }
2362 2362
                     } else {
2363 2363
                         $GLOBALS['log']->fatal("Failed to load relationship {$linkField} while saving {$this->module_dir}");
@@ -2741,10 +2741,10 @@  discard block
 block discarded – undo
2741 2741
             $template_name = "Default";
2742 2742
         }
2743 2743
         if (!empty($_SESSION["special_notification"]) && $_SESSION["special_notification"]) {
2744
-            $template_name = $beanList[$this->module_dir] . 'Special';
2744
+            $template_name = $beanList[$this->module_dir].'Special';
2745 2745
         }
2746 2746
         if ($this->special_notification) {
2747
-            $template_name = $beanList[$this->module_dir] . 'Special';
2747
+            $template_name = $beanList[$this->module_dir].'Special';
2748 2748
         }
2749 2749
         $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
2750 2750
         $xtpl->assign("ASSIGNER", $current_user->name);
@@ -2755,17 +2755,17 @@  discard block
 block discarded – undo
2755 2755
             $parsedSiteUrl['port'] = 80;
2756 2756
         }
2757 2757
 
2758
-        $port = ($parsedSiteUrl['port'] != 80) ? ":" . $parsedSiteUrl['port'] : '';
2758
+        $port = ($parsedSiteUrl['port'] != 80) ? ":".$parsedSiteUrl['port'] : '';
2759 2759
         $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : "";
2760 2760
         $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
2761 2761
 
2762
-        $xtpl->assign("URL", $cleanUrl . "/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
2762
+        $xtpl->assign("URL", $cleanUrl."/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
2763 2763
         $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
2764 2764
         $xtpl->parse($template_name);
2765
-        $xtpl->parse($template_name . "_Subject");
2765
+        $xtpl->parse($template_name."_Subject");
2766 2766
 
2767 2767
         $notify_mail->Body = from_html(trim($xtpl->text($template_name)));
2768
-        $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
2768
+        $notify_mail->Subject = from_html($xtpl->text($template_name."_Subject"));
2769 2769
 
2770 2770
         // cn: bug 8568 encode notify email in User's outbound email encoding
2771 2771
         $notify_mail->prepForOutbound();
@@ -2857,7 +2857,7 @@  discard block
 block discarded – undo
2857 2857
                 if (empty($where)) {
2858 2858
                     $where = $owner_where;
2859 2859
                 } else {
2860
-                    $where .= ' AND ' . $owner_where;
2860
+                    $where .= ' AND '.$owner_where;
2861 2861
                 }
2862 2862
             }
2863 2863
         }
@@ -2911,7 +2911,7 @@  discard block
 block discarded – undo
2911 2911
             if (empty($where)) {
2912 2912
                 $where = $owner_where;
2913 2913
             } else {
2914
-                $where .= ' AND ' . $owner_where;
2914
+                $where .= ' AND '.$owner_where;
2915 2915
             }
2916 2916
         }
2917 2917
         /* BEGIN - SECURITY GROUPS */
@@ -2925,9 +2925,9 @@  discard block
 block discarded – undo
2925 2925
             $group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
2926 2926
             //$group_where = "user_name = 'admin'";
2927 2927
             if (empty($where)) {
2928
-                $where = " (" . $group_where . ") ";
2928
+                $where = " (".$group_where.") ";
2929 2929
             } else {
2930
-                $where .= " AND (" . $group_where . ") ";
2930
+                $where .= " AND (".$group_where.") ";
2931 2931
             }
2932 2932
         } elseif ($this->bean_implements('ACL') && ACLController::requireSecurityGroup($this->module_dir, 'list')) {
2933 2933
             require_once('modules/SecurityGroups/SecurityGroup.php');
@@ -2936,12 +2936,12 @@  discard block
 block discarded – undo
2936 2936
             $group_where = SecurityGroup::getGroupWhere($this->table_name, $this->module_dir, $current_user->id);
2937 2937
             if (!empty($owner_where)) {
2938 2938
                 if (empty($where)) {
2939
-                    $where = " (" . $owner_where . " or " . $group_where . ") ";
2939
+                    $where = " (".$owner_where." or ".$group_where.") ";
2940 2940
                 } else {
2941
-                    $where .= " AND (" . $owner_where . " or " . $group_where . ") ";
2941
+                    $where .= " AND (".$owner_where." or ".$group_where.") ";
2942 2942
                 }
2943 2943
             } else {
2944
-                $where .= ' AND ' . $group_where;
2944
+                $where .= ' AND '.$group_where;
2945 2945
             }
2946 2946
         }
2947 2947
         /* END - SECURITY GROUPS */
@@ -2960,7 +2960,7 @@  discard block
 block discarded – undo
2960 2960
         $ret_array['order_by'] = '';
2961 2961
         //secondary selects are selects that need to be run after the primary query to retrieve additional info on main
2962 2962
         if ($singleSelect) {
2963
-            $ret_array['secondary_select'] =& $ret_array['select'];
2963
+            $ret_array['secondary_select'] = & $ret_array['select'];
2964 2964
             $ret_array['secondary_from'] = &$ret_array['from'];
2965 2965
         } else {
2966 2966
             $ret_array['secondary_select'] = '';
@@ -3034,7 +3034,7 @@  discard block
 block discarded – undo
3034 3034
             //alias is used to alias field names
3035 3035
             $alias = '';
3036 3036
             if (isset($value['alias'])) {
3037
-                $alias = ' as ' . $value['alias'] . ' ';
3037
+                $alias = ' as '.$value['alias'].' ';
3038 3038
             }
3039 3039
 
3040 3040
             if (empty($this->field_defs[$field]) || !empty($value['force_blank'])) {
@@ -3073,29 +3073,29 @@  discard block
 block discarded – undo
3073 3073
                 $selectedFields["$this->table_name.$field"] = true;
3074 3074
             } elseif ((!isset($data['source']) || $data['source'] == 'custom_fields') && (!empty($alias) || !empty($filter))) {
3075 3075
                 //add this column only if it has NOT already been added to select statement string
3076
-                $colPos = strpos($ret_array['select'], "$this->table_name" . "_cstm" . ".$field");
3076
+                $colPos = strpos($ret_array['select'], "$this->table_name"."_cstm".".$field");
3077 3077
                 if (!$colPos || $colPos < 0) {
3078
-                    $ret_array['select'] .= ", $this->table_name" . "_cstm" . ".$field $alias";
3078
+                    $ret_array['select'] .= ", $this->table_name"."_cstm".".$field $alias";
3079 3079
                 }
3080 3080
 
3081 3081
                 $selectedFields["$this->table_name.$field"] = true;
3082 3082
             }
3083 3083
 
3084 3084
             if ($data['type'] != 'relate' && isset($data['db_concat_fields'])) {
3085
-                $ret_array['select'] .= ", " . $this->db->concat($this->table_name, $data['db_concat_fields']) . " as $field";
3085
+                $ret_array['select'] .= ", ".$this->db->concat($this->table_name, $data['db_concat_fields'])." as $field";
3086 3086
                 $selectedFields[$this->db->concat($this->table_name, $data['db_concat_fields'])] = true;
3087 3087
             }
3088 3088
             //Custom relate field or relate fields built in module builder which have no link field associated.
3089 3089
             if ($data['type'] == 'relate' && (isset($data['custom_module']) || isset($data['ext2']))) {
3090
-                $joinTableAlias = 'jt' . $jtcount;
3090
+                $joinTableAlias = 'jt'.$jtcount;
3091 3091
                 $relateJoinInfo = $this->custom_fields->getRelateJoin($data, $joinTableAlias, false);
3092 3092
                 $ret_array['select'] .= $relateJoinInfo['select'];
3093 3093
                 $ret_array['from'] .= $relateJoinInfo['from'];
3094 3094
                 //Replace any references to the relationship in the where clause with the new alias
3095 3095
                 //If the link isn't set, assume that search used the local table for the field
3096 3096
                 $searchTable = isset($data['link']) ? $relateJoinInfo['rel_table'] : $this->table_name;
3097
-                $field_name = $relateJoinInfo['rel_table'] . '.' . !empty($data['name']) ? $data['name'] : 'name';
3098
-                $where = preg_replace('/(^|[\s(])' . $field_name . '/', '${1}' . $relateJoinInfo['name_field'], $where);
3097
+                $field_name = $relateJoinInfo['rel_table'].'.'.!empty($data['name']) ? $data['name'] : 'name';
3098
+                $where = preg_replace('/(^|[\s(])'.$field_name.'/', '${1}'.$relateJoinInfo['name_field'], $where);
3099 3099
                 $jtcount++;
3100 3100
             }
3101 3101
             //Parent Field
@@ -3103,7 +3103,7 @@  discard block
 block discarded – undo
3103 3103
                 //See if we need to join anything by inspecting the where clause
3104 3104
                 $match = preg_match('/(^|[\s(])parent_([a-zA-Z]+_?[a-zA-Z]+)_([a-zA-Z]+_?[a-zA-Z]+)\.name/', $where, $matches);
3105 3105
                 if ($match) {
3106
-                    $joinTableAlias = 'jt' . $jtcount;
3106
+                    $joinTableAlias = 'jt'.$jtcount;
3107 3107
                     $joinModule = $matches[2];
3108 3108
                     $joinTable = $matches[3];
3109 3109
                     $localTable = $this->table_name;
@@ -3124,7 +3124,7 @@  discard block
 block discarded – undo
3124 3124
                     $ret_array['from'] .= " LEFT JOIN $joinTable $joinTableAlias
3125 3125
                         ON $localTable.{$data['id_name']} = $joinTableAlias.id";
3126 3126
                     //Replace any references to the relationship in the where clause with the new alias
3127
-                    $where = preg_replace('/(^|[\s(])parent_' . $joinModule . '_' . $joinTable . '\.name/', '${1}' . $nameField, $where);
3127
+                    $where = preg_replace('/(^|[\s(])parent_'.$joinModule.'_'.$joinTable.'\.name/', '${1}'.$nameField, $where);
3128 3128
                     $jtcount++;
3129 3129
                 }
3130 3130
             }
@@ -3133,7 +3133,7 @@  discard block
 block discarded – undo
3133 3133
             {
3134 3134
                 $linkField = $data['link'];
3135 3135
                 $this->load_relationship($linkField);
3136
-                if(!empty($this->$linkField))
3136
+                if (!empty($this->$linkField))
3137 3137
                 {
3138 3138
                     $params = array();
3139 3139
                     if (empty($join_type)) {
@@ -3144,12 +3144,12 @@  discard block
 block discarded – undo
3144 3144
                     if (isset($data['join_name'])) {
3145 3145
                         $params['join_table_alias'] = $data['join_name'];
3146 3146
                     } else {
3147
-                        $params['join_table_alias'] = 'jt' . $jtcount;
3147
+                        $params['join_table_alias'] = 'jt'.$jtcount;
3148 3148
                     }
3149 3149
                     if (isset($data['join_link_name'])) {
3150 3150
                         $params['join_table_link_alias'] = $data['join_link_name'];
3151 3151
                     } else {
3152
-                        $params['join_table_link_alias'] = 'jtl' . $jtcount;
3152
+                        $params['join_table_link_alias'] = 'jtl'.$jtcount;
3153 3153
                     }
3154 3154
                     $join_primary = !isset($data['join_primary']) || $data['join_primary'];
3155 3155
 
@@ -3182,20 +3182,20 @@  discard block
 block discarded – undo
3182 3182
                                 require_once($beanFiles[$beanList[$rel_module]]);
3183 3183
                                 $rel_mod = new $beanList[$rel_module]();
3184 3184
                                 if (isset($rel_mod->field_defs['assigned_user_id'])) {
3185
-                                    $ret_array['secondary_select'] .= " , " . $params['join_table_alias'] . ".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3185
+                                    $ret_array['secondary_select'] .= " , ".$params['join_table_alias'].".assigned_user_id {$field}_owner, '$rel_module' {$field}_mod";
3186 3186
                                 } else {
3187 3187
                                     if (isset($rel_mod->field_defs['created_by'])) {
3188
-                                        $ret_array['secondary_select'] .= " , " . $params['join_table_alias'] . ".created_by {$field}_owner , '$rel_module' {$field}_mod";
3188
+                                        $ret_array['secondary_select'] .= " , ".$params['join_table_alias'].".created_by {$field}_owner , '$rel_module' {$field}_mod";
3189 3189
                                     }
3190 3190
                                 }
3191 3191
                             }
3192 3192
                         }
3193 3193
 
3194 3194
                         if (isset($data['db_concat_fields'])) {
3195
-                            $ret_array['secondary_select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3195
+                            $ret_array['secondary_select'] .= ' , '.$this->db->concat($params['join_table_alias'], $data['db_concat_fields']).' '.$field;
3196 3196
                         } else {
3197 3197
                             if (!isset($data['relationship_fields'])) {
3198
-                                $ret_array['secondary_select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3198
+                                $ret_array['secondary_select'] .= ' , '.$params['join_table_alias'].'.'.$data['rname'].' '.$field;
3199 3199
                             }
3200 3200
                         }
3201 3201
                         if (!$singleSelect) {
@@ -3211,54 +3211,54 @@  discard block
 block discarded – undo
3211 3211
                             //27416, the $ret_array['secondary_select'] should always generate, regardless the dbtype
3212 3212
                             // add rel_key only if it was not already added
3213 3213
                             if (!$singleSelect) {
3214
-                                $ret_array['select'] .= ", '                                    '  " . $join['rel_key'] . ' ';
3214
+                                $ret_array['select'] .= ", '                                    '  ".$join['rel_key'].' ';
3215 3215
                             }
3216
-                            $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'] . '.' . $join['rel_key'] . ' ' . $join['rel_key'];
3216
+                            $ret_array['secondary_select'] .= ', '.$params['join_table_link_alias'].'.'.$join['rel_key'].' '.$join['rel_key'];
3217 3217
                         }
3218 3218
                         if (isset($data['relationship_fields'])) {
3219 3219
                             foreach ($data['relationship_fields'] as $r_name => $alias_name) {
3220 3220
                                 if (!empty($secondarySelectedFields[$alias_name])) {
3221 3221
                                     continue;
3222 3222
                                 }
3223
-                                $ret_array['secondary_select'] .= ', ' . $params['join_table_link_alias'] . '.' . $r_name . ' ' . $alias_name;
3223
+                                $ret_array['secondary_select'] .= ', '.$params['join_table_link_alias'].'.'.$r_name.' '.$alias_name;
3224 3224
                                 $secondarySelectedFields[$alias_name] = true;
3225 3225
                             }
3226 3226
                         }
3227 3227
                         if (!$table_joined) {
3228
-                            $ret_array['secondary_from'] .= ' ' . $join['join'] . ' AND ' . $params['join_table_alias'] . '.deleted=0';
3228
+                            $ret_array['secondary_from'] .= ' '.$join['join'].' AND '.$params['join_table_alias'].'.deleted=0';
3229 3229
                             if (isset($data['link_type']) && $data['link_type'] == 'relationship_info' && ($parentbean instanceof SugarBean)) {
3230
-                                $ret_array['secondary_where'] = $params['join_table_link_alias'] . '.' . $join['rel_key'] . "='" . $parentbean->id . "'";
3230
+                                $ret_array['secondary_where'] = $params['join_table_link_alias'].'.'.$join['rel_key']."='".$parentbean->id."'";
3231 3231
                             }
3232 3232
                         }
3233 3233
                     } else {
3234 3234
                         if (isset($data['db_concat_fields'])) {
3235
-                            $ret_array['select'] .= ' , ' . $this->db->concat($params['join_table_alias'], $data['db_concat_fields']) . ' ' . $field;
3235
+                            $ret_array['select'] .= ' , '.$this->db->concat($params['join_table_alias'], $data['db_concat_fields']).' '.$field;
3236 3236
                         } else {
3237
-                            $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $data['rname'] . ' ' . $field;
3237
+                            $ret_array['select'] .= ' , '.$params['join_table_alias'].'.'.$data['rname'].' '.$field;
3238 3238
                         }
3239 3239
                         if (isset($data['additionalFields'])) {
3240 3240
                             foreach ($data['additionalFields'] as $k => $v) {
3241 3241
                                 if (!empty($data['id_name']) && $data['id_name'] == $v && !empty($fields[$data['id_name']])) {
3242 3242
                                     continue;
3243 3243
                                 }
3244
-                                $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.' . $k . ' ' . $v;
3244
+                                $ret_array['select'] .= ' , '.$params['join_table_alias'].'.'.$k.' '.$v;
3245 3245
                             }
3246 3246
                         }
3247 3247
                         if (!$table_joined) {
3248
-                            $ret_array['from'] .= ' ' . $join['join'] . ' AND ' . $params['join_table_alias'] . '.deleted=0';
3248
+                            $ret_array['from'] .= ' '.$join['join'].' AND '.$params['join_table_alias'].'.deleted=0';
3249 3249
                             if (!empty($beanList[$rel_module]) && !empty($beanFiles[$beanList[$rel_module]])) {
3250 3250
                                 require_once($beanFiles[$beanList[$rel_module]]);
3251 3251
                                 $rel_mod = new $beanList[$rel_module]();
3252 3252
                                 if (isset($value['target_record_key']) && !empty($filter)) {
3253
-                                    $selectedFields[$this->table_name . '.' . $value['target_record_key']] = true;
3253
+                                    $selectedFields[$this->table_name.'.'.$value['target_record_key']] = true;
3254 3254
                                     $ret_array['select'] .= " , $this->table_name.{$value['target_record_key']} ";
3255 3255
                                 }
3256 3256
                                 if (isset($rel_mod->field_defs['assigned_user_id'])) {
3257
-                                    $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.assigned_user_id ' . $field . '_owner';
3257
+                                    $ret_array['select'] .= ' , '.$params['join_table_alias'].'.assigned_user_id '.$field.'_owner';
3258 3258
                                 } else {
3259
-                                    $ret_array['select'] .= ' , ' . $params['join_table_alias'] . '.created_by ' . $field . '_owner';
3259
+                                    $ret_array['select'] .= ' , '.$params['join_table_alias'].'.created_by '.$field.'_owner';
3260 3260
                                 }
3261
-                                $ret_array['select'] .= "  , '" . $rel_module . "' " . $field . '_mod';
3261
+                                $ret_array['select'] .= "  , '".$rel_module."' ".$field.'_mod';
3262 3262
                             }
3263 3263
                         }
3264 3264
                     }
@@ -3268,37 +3268,37 @@  discard block
 block discarded – undo
3268 3268
                     if (isset($data['db_concat_fields'])) {
3269 3269
                         $buildWhere = false;
3270 3270
                         if (in_array('first_name', $data['db_concat_fields']) && in_array('last_name', $data['db_concat_fields'])) {
3271
-                            $exp = '/\(\s*?' . $data['name'] . '.*?\%\'\s*?\)/';
3271
+                            $exp = '/\(\s*?'.$data['name'].'.*?\%\'\s*?\)/';
3272 3272
                             if (preg_match($exp, $where, $matches)) {
3273 3273
                                 $search_expression = $matches[0];
3274 3274
                                 //Create three search conditions - first + last, first, last
3275
-                                $first_name_search = str_replace($data['name'], $params['join_table_alias'] . '.first_name', $search_expression);
3276
-                                $last_name_search = str_replace($data['name'], $params['join_table_alias'] . '.last_name', $search_expression);
3275
+                                $first_name_search = str_replace($data['name'], $params['join_table_alias'].'.first_name', $search_expression);
3276
+                                $last_name_search = str_replace($data['name'], $params['join_table_alias'].'.last_name', $search_expression);
3277 3277
                                 $full_name_search = str_replace($data['name'], $this->db->concat($params['join_table_alias'], $data['db_concat_fields']), $search_expression);
3278 3278
                                 $buildWhere = true;
3279
-                                $where = str_replace($search_expression, '(' . $full_name_search . ' OR ' . $first_name_search . ' OR ' . $last_name_search . ')', $where);
3279
+                                $where = str_replace($search_expression, '('.$full_name_search.' OR '.$first_name_search.' OR '.$last_name_search.')', $where);
3280 3280
                             }
3281 3281
                         }
3282 3282
 
3283 3283
                         if (!$buildWhere) {
3284 3284
                             $db_field = $this->db->concat($params['join_table_alias'], $data['db_concat_fields']);
3285
-                            $where = preg_replace('/' . $data['name'] . '/', $db_field, $where);
3285
+                            $where = preg_replace('/'.$data['name'].'/', $db_field, $where);
3286 3286
 
3287 3287
                             // For relationship fields replace their alias by the corresponding link table and r_name
3288 3288
                             if (isset($data['relationship_fields'])) {
3289 3289
                                 foreach ($data['relationship_fields'] as $r_name => $alias_name) {
3290 3290
                                     $db_field = $this->db->concat($params['join_table_link_alias'], $r_name);
3291
-                                    $where = preg_replace('/' . $alias_name . '/', $db_field, $where);
3291
+                                    $where = preg_replace('/'.$alias_name.'/', $db_field, $where);
3292 3292
                                 }
3293 3293
                             }
3294 3294
                         }
3295 3295
                     } else {
3296
-                        $where = preg_replace('/(^|[\s(])' . $data['name'] . '/', '${1}' . $params['join_table_alias'] . '.' . $data['rname'], $where);
3296
+                        $where = preg_replace('/(^|[\s(])'.$data['name'].'/', '${1}'.$params['join_table_alias'].'.'.$data['rname'], $where);
3297 3297
 
3298 3298
                         // For relationship fields replace their alias by the corresponding link table and r_name
3299 3299
                         if (isset($data['relationship_fields'])) {
3300 3300
                             foreach ($data['relationship_fields'] as $r_name => $alias_name) {
3301
-                                $where = preg_replace('/(^|[\s(])' . $alias_name . '/', '${1}' . $params['join_table_link_alias'] . '.' . $r_name, $where);
3301
+                                $where = preg_replace('/(^|[\s(])'.$alias_name.'/', '${1}'.$params['join_table_link_alias'].'.'.$r_name, $where);
3302 3302
                             }
3303 3303
                         }
3304 3304
                     }
@@ -3312,12 +3312,12 @@  discard block
 block discarded – undo
3312 3312
             }
3313 3313
         }
3314 3314
         if (!empty($filter)) {
3315
-            if (isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name . '.assigned_user_id'])) {
3315
+            if (isset($this->field_defs['assigned_user_id']) && empty($selectedFields[$this->table_name.'.assigned_user_id'])) {
3316 3316
                 $ret_array['select'] .= ", $this->table_name.assigned_user_id ";
3317
-            } elseif (isset($this->field_defs['created_by']) && empty($selectedFields[$this->table_name . '.created_by'])) {
3317
+            } elseif (isset($this->field_defs['created_by']) && empty($selectedFields[$this->table_name.'.created_by'])) {
3318 3318
                 $ret_array['select'] .= ", $this->table_name.created_by ";
3319 3319
             }
3320
-            if (isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name . '.system_id'])) {
3320
+            if (isset($this->field_defs['system_id']) && empty($selectedFields[$this->table_name.'.system_id'])) {
3321 3321
                 $ret_array['select'] .= ", $this->table_name.system_id ";
3322 3322
             }
3323 3323
         }
@@ -3344,7 +3344,7 @@  discard block
 block discarded – undo
3344 3344
         //make call to process the order by clause
3345 3345
         $order_by = $this->process_order_by($order_by);
3346 3346
         if (!empty($order_by)) {
3347
-            $ret_array['order_by'] = " ORDER BY " . $order_by;
3347
+            $ret_array['order_by'] = " ORDER BY ".$order_by;
3348 3348
         }
3349 3349
         if ($singleSelect) {
3350 3350
             unset($ret_array['secondary_where']);
@@ -3356,7 +3356,7 @@  discard block
 block discarded – undo
3356 3356
             return $ret_array;
3357 3357
         }
3358 3358
 
3359
-        return $ret_array['select'] . $ret_array['from'] . $ret_array['where'] . $ret_array['order_by'];
3359
+        return $ret_array['select'].$ret_array['from'].$ret_array['where'].$ret_array['order_by'];
3360 3360
     }
3361 3361
 
3362 3362
 	public function get_relationship_field($field)
@@ -3431,9 +3431,9 @@  discard block
 block discarded – undo
3431 3431
 
3432 3432
                 if (empty($field_defs['table']) && !$suppress_table_name) {
3433 3433
                     if ($source == 'db') {
3434
-                        $list_column[0] = $bean_queried->table_name . '.' . $list_column[0];
3434
+                        $list_column[0] = $bean_queried->table_name.'.'.$list_column[0];
3435 3435
                     } elseif ($source == 'custom_fields') {
3436
-                        $list_column[0] = $bean_queried->table_name . '_cstm.' . $list_column[0];
3436
+                        $list_column[0] = $bean_queried->table_name.'_cstm.'.$list_column[0];
3437 3437
                     }
3438 3438
                 }
3439 3439
 
@@ -3489,7 +3489,7 @@  discard block
 block discarded – undo
3489 3489
          * if the row_offset is set to 'end' go to the end of the list
3490 3490
          */
3491 3491
         $toEnd = strval($row_offset) == 'end';
3492
-        $GLOBALS['log']->debug("process_list_query: " . $query);
3492
+        $GLOBALS['log']->debug("process_list_query: ".$query);
3493 3493
         if ($max_per_page == -1) {
3494 3494
             $max_per_page = $sugar_config['list_max_entries_per_page'];
3495 3495
         }
@@ -3548,14 +3548,14 @@  discard block
 block discarded – undo
3548 3548
             foreach ($this->field_defs as $field => $value) {
3549 3549
                 if (isset($row[$field])) {
3550 3550
                     $temp->$field = $row[$field];
3551
-                    $owner_field = $field . '_owner';
3551
+                    $owner_field = $field.'_owner';
3552 3552
                     if (isset($row[$owner_field])) {
3553 3553
                         $temp->$owner_field = $row[$owner_field];
3554 3554
                     }
3555 3555
 
3556
-                    $GLOBALS['log']->debug("$temp->object_name({$row['id']}): " . $field . " = " . $temp->$field);
3557
-                } elseif (isset($row[$this->table_name . '.' . $field])) {
3558
-                    $temp->$field = $row[$this->table_name . '.' . $field];
3556
+                    $GLOBALS['log']->debug("$temp->object_name({$row['id']}): ".$field." = ".$temp->$field);
3557
+                } elseif (isset($row[$this->table_name.'.'.$field])) {
3558
+                    $temp->$field = $row[$this->table_name.'.'.$field];
3559 3559
                 } else {
3560 3560
                     $temp->$field = "";
3561 3561
                 }
@@ -3608,22 +3608,22 @@  discard block
 block discarded – undo
3608 3608
     public function create_list_count_query($query)
3609 3609
     {
3610 3610
         // remove the 'order by' clause which is expected to be at the end of the query
3611
-        $pattern = '/\sORDER BY.*/is';  // ignores the case
3611
+        $pattern = '/\sORDER BY.*/is'; // ignores the case
3612 3612
         $replacement = '';
3613 3613
         $query = preg_replace($pattern, $replacement, $query);
3614 3614
         //handle distinct clause
3615 3615
         $star = '*';
3616 3616
         if (substr_count(strtolower($query), 'distinct')) {
3617 3617
             if (!empty($this->seed) && !empty($this->seed->table_name)) {
3618
-                $star = 'DISTINCT ' . $this->seed->table_name . '.id';
3618
+                $star = 'DISTINCT '.$this->seed->table_name.'.id';
3619 3619
             } else {
3620
-                $star = 'DISTINCT ' . $this->table_name . '.id';
3620
+                $star = 'DISTINCT '.$this->table_name.'.id';
3621 3621
             }
3622 3622
         }
3623 3623
 
3624 3624
         // change the select expression to 'count(*)'
3625
-        $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is';  // ignores the case
3626
-        $replacement = 'SELECT count(' . $star . ') c FROM ';
3625
+        $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is'; // ignores the case
3626
+        $replacement = 'SELECT count('.$star.') c FROM ';
3627 3627
 
3628 3628
         //if the passed query has union clause then replace all instances of the pattern.
3629 3629
         //this is very rare. I have seen this happening only from projects module.
@@ -3639,13 +3639,13 @@  discard block
 block discarded – undo
3639 3639
                 if (!empty($matches)) {
3640 3640
                     if (stristr($matches[0], "distinct")) {
3641 3641
                         if (!empty($this->seed) && !empty($this->seed->table_name)) {
3642
-                            $star = 'DISTINCT ' . $this->seed->table_name . '.id';
3642
+                            $star = 'DISTINCT '.$this->seed->table_name.'.id';
3643 3643
                         } else {
3644
-                            $star = 'DISTINCT ' . $this->table_name . '.id';
3644
+                            $star = 'DISTINCT '.$this->table_name.'.id';
3645 3645
                         }
3646 3646
                     }
3647 3647
                 } // if
3648
-                $replacement = 'SELECT count(' . $star . ') c FROM ';
3648
+                $replacement = 'SELECT count('.$star.') c FROM ';
3649 3649
                 $union_qs[$key] = preg_replace($pattern, $replacement, $union_query, 1);
3650 3650
             }
3651 3651
             $modified_select_query = implode(" UNION ALL ", $union_qs);
@@ -3711,7 +3711,7 @@  discard block
 block discarded – undo
3711 3711
             if (empty($where)) {
3712 3712
                 $where = $owner_where;
3713 3713
             } else {
3714
-                $where .= ' AND ' . $owner_where;
3714
+                $where .= ' AND '.$owner_where;
3715 3715
             }
3716 3716
         }
3717 3717
 
@@ -3723,12 +3723,12 @@  discard block
 block discarded – undo
3723 3723
             $group_where = SecurityGroup::getGroupWhere($this->table_name, $this->module_dir, $current_user->id);
3724 3724
             if (!empty($owner_where)) {
3725 3725
                 if (empty($where)) {
3726
-                    $where = " (" . $owner_where . " or " . $group_where . ") ";
3726
+                    $where = " (".$owner_where." or ".$group_where.") ";
3727 3727
                 } else {
3728
-                    $where .= " AND (" . $owner_where . " or " . $group_where . ") ";
3728
+                    $where .= " AND (".$owner_where." or ".$group_where.") ";
3729 3729
                 }
3730 3730
             } else {
3731
-                $where .= ' AND ' . $group_where;
3731
+                $where .= ' AND '.$group_where;
3732 3732
             }
3733 3733
         }
3734 3734
         /* END - SECURITY GROUPS */
@@ -3757,7 +3757,7 @@  discard block
 block discarded – undo
3757 3757
     public function process_detail_query($query, $row_offset, $limit = -1, $max_per_page = -1, $where = '', $offset = 0)
3758 3758
     {
3759 3759
         global $sugar_config;
3760
-        $GLOBALS['log']->debug("process_detail_query: " . $query);
3760
+        $GLOBALS['log']->debug("process_detail_query: ".$query);
3761 3761
         if ($max_per_page == -1) {
3762 3762
             $max_per_page = $sugar_config['list_max_entries_per_page'];
3763 3763
         }
@@ -3823,14 +3823,14 @@  discard block
 block discarded – undo
3823 3823
         }
3824 3824
         $custom_join = $this->getCustomJoin();
3825 3825
 
3826
-        $query = "SELECT $this->table_name.*" . $custom_join['select'] . " FROM $this->table_name ";
3826
+        $query = "SELECT $this->table_name.*".$custom_join['select']." FROM $this->table_name ";
3827 3827
 
3828 3828
         $query .= $custom_join['join'];
3829
-        $query .= " WHERE $this->table_name.id = " . $this->db->quoted($id);
3829
+        $query .= " WHERE $this->table_name.id = ".$this->db->quoted($id);
3830 3830
         if ($deleted) {
3831 3831
             $query .= " AND $this->table_name.deleted=0";
3832 3832
         }
3833
-        $GLOBALS['log']->debug("Retrieve $this->object_name : " . $query);
3833
+        $GLOBALS['log']->debug("Retrieve $this->object_name : ".$query);
3834 3834
         $result = $this->db->limitQuery($query, 0, 1, true, "Retrieving record by id $this->table_name:$id found ");
3835 3835
         if (empty($result)) {
3836 3836
             return null;
@@ -3981,7 +3981,7 @@  discard block
 block discarded – undo
3981 3981
             }
3982 3982
             if (isset($row[$field])) {
3983 3983
                 $this->$field = $row[$field];
3984
-                $owner = $field . '_owner';
3984
+                $owner = $field.'_owner';
3985 3985
                 if (!empty($row[$owner])) {
3986 3986
                     $this->$owner = $row[$owner];
3987 3987
                 }
@@ -4178,12 +4178,12 @@  discard block
 block discarded – undo
4178 4178
         $query = 'SELECT id';
4179 4179
         foreach ($fields as $field => $alias) {
4180 4180
             if (!empty($GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields'])) {
4181
-                $query .= ' ,' . $this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']) . ' as ' . $alias;
4181
+                $query .= ' ,'.$this->db->concat($table, $GLOBALS['dictionary'][$object]['fields'][$field]['db_concat_fields']).' as '.$alias;
4182 4182
             } elseif (!empty($GLOBALS['dictionary'][$object]['fields'][$field]) &&
4183 4183
                 (empty($GLOBALS['dictionary'][$object]['fields'][$field]['source']) ||
4184 4184
                     $GLOBALS['dictionary'][$object]['fields'][$field]['source'] != "non-db")
4185 4185
             ) {
4186
-                $query .= ' ,' . $table . '.' . $field . ' as ' . $alias;
4186
+                $query .= ' ,'.$table.'.'.$field.' as '.$alias;
4187 4187
             }
4188 4188
             if (!$return_array) {
4189 4189
                 $this->$alias = '';
@@ -4195,12 +4195,12 @@  discard block
 block discarded – undo
4195 4195
 
4196 4196
 
4197 4197
         if (isset($GLOBALS['dictionary'][$object]['fields']['assigned_user_id'])) {
4198
-            $query .= " , " . $table . ".assigned_user_id owner";
4198
+            $query .= " , ".$table.".assigned_user_id owner";
4199 4199
         } elseif (isset($GLOBALS['dictionary'][$object]['fields']['created_by'])) {
4200
-            $query .= " , " . $table . ".created_by owner";
4200
+            $query .= " , ".$table.".created_by owner";
4201 4201
         }
4202
-        $query .= ' FROM ' . $table . ' WHERE deleted=0 AND id=';
4203
-        $result = $GLOBALS['db']->query($query . "'$id'");
4202
+        $query .= ' FROM '.$table.' WHERE deleted=0 AND id=';
4203
+        $result = $GLOBALS['db']->query($query."'$id'");
4204 4204
         $row = $GLOBALS['db']->fetchByAssoc($result);
4205 4205
         if ($return_array) {
4206 4206
             return $row;
@@ -4208,9 +4208,9 @@  discard block
 block discarded – undo
4208 4208
         $owner = (empty($row['owner'])) ? '' : $row['owner'];
4209 4209
         foreach ($fields as $alias) {
4210 4210
             $this->$alias = (!empty($row[$alias])) ? $row[$alias] : '';
4211
-            $alias = $alias . '_owner';
4211
+            $alias = $alias.'_owner';
4212 4212
             $this->$alias = $owner;
4213
-            $a_mod = $alias . '_mod';
4213
+            $a_mod = $alias.'_mod';
4214 4214
             $this->$a_mod = $module;
4215 4215
         }
4216 4216
     }
@@ -4370,15 +4370,15 @@  discard block
 block discarded – undo
4370 4370
         $entire_where = $query_array['where'];
4371 4371
         if (!empty($where)) {
4372 4372
             if (empty($entire_where)) {
4373
-                $entire_where = ' WHERE ' . $where;
4373
+                $entire_where = ' WHERE '.$where;
4374 4374
             } else {
4375
-                $entire_where .= ' AND ' . $where;
4375
+                $entire_where .= ' AND '.$where;
4376 4376
             }
4377 4377
         }
4378 4378
 
4379
-        $query = 'SELECT ' . $child_seed->table_name . '.* ' . $query_array['from'] . ' ' . $entire_where;
4379
+        $query = 'SELECT '.$child_seed->table_name.'.* '.$query_array['from'].' '.$entire_where;
4380 4380
         if (!empty($order_by)) {
4381
-            $query .= " ORDER BY " . $order_by;
4381
+            $query .= " ORDER BY ".$order_by;
4382 4382
         }
4383 4383
 
4384 4384
         return $child_seed->process_list_query($query, $row_offset, $limit, $max, $where);
@@ -4414,9 +4414,9 @@  discard block
 block discarded – undo
4414 4414
      */
4415 4415
     public function process_full_list_query($query, $check_date = false)
4416 4416
     {
4417
-        $GLOBALS['log']->debug("process_full_list_query: query is " . $query);
4417
+        $GLOBALS['log']->debug("process_full_list_query: query is ".$query);
4418 4418
         $result = $this->db->query($query, false);
4419
-        $GLOBALS['log']->debug("process_full_list_query: result is " . print_r($result, true));
4419
+        $GLOBALS['log']->debug("process_full_list_query: result is ".print_r($result, true));
4420 4420
         $class = get_class($this);
4421 4421
         $isFirstTime = true;
4422 4422
         $bean = new $class();
@@ -4432,7 +4432,7 @@  discard block
 block discarded – undo
4432 4432
             foreach ($bean->field_defs as $field => $value) {
4433 4433
                 if (isset($row[$field])) {
4434 4434
                     $bean->$field = $row[$field];
4435
-                    $GLOBALS['log']->debug("process_full_list: $bean->object_name({$row['id']}): " . $field . " = " . $bean->$field);
4435
+                    $GLOBALS['log']->debug("process_full_list: $bean->object_name({$row['id']}): ".$field." = ".$bean->$field);
4436 4436
                 } else {
4437 4437
                     $bean->$field = '';
4438 4438
                 }
@@ -4524,7 +4524,7 @@  discard block
 block discarded – undo
4524 4524
         $this->call_custom_logic("before_restore", $custom_logic_arguments);
4525 4525
 
4526 4526
         $date_modified = $GLOBALS['timedate']->nowDb();
4527
-        $query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='" . $this->db->quote($id) . "'";
4527
+        $query = "UPDATE $this->table_name set deleted=0 , date_modified = '$date_modified' where id='".$this->db->quote($id)."'";
4528 4528
         $this->db->query($query, true, "Error marking record undeleted: ");
4529 4529
 
4530 4530
         $this->restoreFiles();
@@ -4554,9 +4554,9 @@  discard block
 block discarded – undo
4554 4554
         $directory = $this->deleteFileDirectory();
4555 4555
 
4556 4556
         foreach ($files as $file) {
4557
-            if (sugar_is_file('upload://deleted/' . $directory . '/' . $file)) {
4558
-                if (!sugar_rename('upload://deleted/' . $directory . '/' . $file, 'upload://' . $file)) {
4559
-                    $GLOBALS['log']->error('Could not move file ' . $directory . '/' . $file . ' from deleted directory');
4557
+            if (sugar_is_file('upload://deleted/'.$directory.'/'.$file)) {
4558
+                if (!sugar_rename('upload://deleted/'.$directory.'/'.$file, 'upload://'.$file)) {
4559
+                    $GLOBALS['log']->error('Could not move file '.$directory.'/'.$file.' from deleted directory');
4560 4560
                 }
4561 4561
             }
4562 4562
         }
@@ -4565,7 +4565,7 @@  discard block
 block discarded – undo
4565 4565
          * @var DBManager $db
4566 4566
          */
4567 4567
         global $db;
4568
-        $db->query('DELETE FROM cron_remove_documents WHERE bean_id=' . $db->quoted($this->id));
4568
+        $db->query('DELETE FROM cron_remove_documents WHERE bean_id='.$db->quoted($this->id));
4569 4569
 
4570 4570
         return true;
4571 4571
     }
@@ -4713,19 +4713,19 @@  discard block
 block discarded – undo
4713 4713
 
4714 4714
         $directory = $this->deleteFileDirectory();
4715 4715
 
4716
-        $isCreated = sugar_is_dir('upload://deleted/' . $directory);
4716
+        $isCreated = sugar_is_dir('upload://deleted/'.$directory);
4717 4717
         if (!$isCreated) {
4718
-            sugar_mkdir('upload://deleted/' . $directory, 0777, true);
4719
-            $isCreated = sugar_is_dir('upload://deleted/' . $directory);
4718
+            sugar_mkdir('upload://deleted/'.$directory, 0777, true);
4719
+            $isCreated = sugar_is_dir('upload://deleted/'.$directory);
4720 4720
         }
4721 4721
         if (!$isCreated) {
4722 4722
             return false;
4723 4723
         }
4724 4724
 
4725 4725
         foreach ($files as $file) {
4726
-            if (file_exists('upload://' . $file)) {
4727
-                if (!sugar_rename('upload://' . $file, 'upload://deleted/' . $directory . '/' . $file)) {
4728
-                    $GLOBALS['log']->error('Could not move file ' . $file . ' to deleted directory');
4726
+            if (file_exists('upload://'.$file)) {
4727
+                if (!sugar_rename('upload://'.$file, 'upload://deleted/'.$directory.'/'.$file)) {
4728
+                    $GLOBALS['log']->error('Could not move file '.$file.' to deleted directory');
4729 4729
                 }
4730 4730
             }
4731 4731
         }
@@ -4745,7 +4745,7 @@  discard block
 block discarded – undo
4745 4745
         }
4746 4746
         if (empty($record['id'])) {
4747 4747
             $record['id'] = $db->quoted(create_guid());
4748
-            $db->query('INSERT INTO cron_remove_documents (' . implode(', ', array_keys($record)) . ') VALUES(' . implode(', ', $record) . ')');
4748
+            $db->query('INSERT INTO cron_remove_documents ('.implode(', ', array_keys($record)).') VALUES('.implode(', ', $record).')');
4749 4749
         } else {
4750 4750
             $db->query("UPDATE cron_remove_documents SET date_modified={$record['date_modified']} WHERE id={$record['id']}");
4751 4751
         }
@@ -4766,7 +4766,7 @@  discard block
 block discarded – undo
4766 4766
      */
4767 4767
     public function build_related_list($query, &$template, $row_offset = 0, $limit = -1)
4768 4768
     {
4769
-        $GLOBALS['log']->debug("Finding linked records $this->object_name: " . $query);
4769
+        $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
4770 4770
         $db = DBManagerFactory::getInstance('listviews');
4771 4771
 
4772 4772
         if (!empty($row_offset) && $row_offset != 0 && !empty($limit) && $limit != -1) {
@@ -4813,7 +4813,7 @@  discard block
 block discarded – undo
4813 4813
     {
4814 4814
         $db = DBManagerFactory::getInstance('listviews');
4815 4815
         // No need to do an additional query
4816
-        $GLOBALS['log']->debug("Finding linked records $this->object_name: " . $query);
4816
+        $GLOBALS['log']->debug("Finding linked records $this->object_name: ".$query);
4817 4817
         if (empty($in) && !empty($query)) {
4818 4818
             $idList = $this->build_related_in($query);
4819 4819
             $in = $idList['in'];
@@ -4879,9 +4879,9 @@  discard block
 block discarded – undo
4879 4879
         while ($row = $this->db->fetchByAssoc($result)) {
4880 4880
             $idList[] = $row['id'];
4881 4881
             if (empty($ids)) {
4882
-                $ids = "('" . $row['id'] . "'";
4882
+                $ids = "('".$row['id']."'";
4883 4883
             } else {
4884
-                $ids .= ",'" . $row['id'] . "'";
4884
+                $ids .= ",'".$row['id']."'";
4885 4885
             }
4886 4886
         }
4887 4887
         if (empty($ids)) {
@@ -4905,7 +4905,7 @@  discard block
 block discarded – undo
4905 4905
      */
4906 4906
     public function build_related_list2($query, &$template, &$field_list)
4907 4907
     {
4908
-        $GLOBALS['log']->debug("Finding linked values $this->object_name: " . $query);
4908
+        $GLOBALS['log']->debug("Finding linked values $this->object_name: ".$query);
4909 4909
 
4910 4910
         $result = $this->db->query($query, true);
4911 4911
 
@@ -5019,9 +5019,9 @@  discard block
 block discarded – undo
5019 5019
     {
5020 5020
         $where_clause = $this->get_where($fields_array, $deleted);
5021 5021
         $custom_join = $this->getCustomJoin();
5022
-        $query = "SELECT $this->table_name.*" . $custom_join['select'] . " FROM $this->table_name " . $custom_join['join'];
5022
+        $query = "SELECT $this->table_name.*".$custom_join['select']." FROM $this->table_name ".$custom_join['join'];
5023 5023
         $query .= " $where_clause";
5024
-        $GLOBALS['log']->debug("Retrieve $this->object_name: " . $query);
5024
+        $GLOBALS['log']->debug("Retrieve $this->object_name: ".$query);
5025 5025
         //requireSingleResult has been deprecated.
5026 5026
         //$result = $this->db->requireSingleResult($query, true, "Retrieving record $where_clause:");
5027 5027
         $result = $this->db->limitQuery($query, 0, 1, true, "Retrieving record $where_clause:");
@@ -5060,7 +5060,7 @@  discard block
 block discarded – undo
5060 5060
             }
5061 5061
             $name = $this->db->getValidDBName($name);
5062 5062
 
5063
-            $where_clause .= "$name = " . $this->db->quoted($value);
5063
+            $where_clause .= "$name = ".$this->db->quoted($value);
5064 5064
         }
5065 5065
         if (!empty($where_clause)) {
5066 5066
             if ($deleted) {
@@ -5158,7 +5158,7 @@  discard block
 block discarded – undo
5158 5158
         $where = '';
5159 5159
 
5160 5160
         // make sure there is a date modified
5161
-        $date_modified = $this->db->convert("'" . $GLOBALS['timedate']->nowDb() . "'", 'datetime');
5161
+        $date_modified = $this->db->convert("'".$GLOBALS['timedate']->nowDb()."'", 'datetime');
5162 5162
 
5163 5163
         $row = null;
5164 5164
         if ($check_duplicates) {
@@ -5168,7 +5168,7 @@  discard block
 block discarded – undo
5168 5168
                 $where .= " AND $name = '$value' ";
5169 5169
             }
5170 5170
             $query .= $where;
5171
-            $result = $this->db->query($query, false, "Looking For Duplicate Relationship:" . $query);
5171
+            $result = $this->db->query($query, false, "Looking For Duplicate Relationship:".$query);
5172 5172
             $row = $this->db->fetchByAssoc($result);
5173 5173
         }
5174 5174
 
@@ -5177,16 +5177,16 @@  discard block
 block discarded – undo
5177 5177
             if (isset($data_values)) {
5178 5178
                 $relate_values = array_merge($relate_values, $data_values);
5179 5179
             }
5180
-            $query = "INSERT INTO $table (id, " . implode(',', array_keys($relate_values)) . ", date_modified) VALUES ('" . create_guid() . "', " . "'" . implode("', '", $relate_values) . "', " . $date_modified . ")";
5180
+            $query = "INSERT INTO $table (id, ".implode(',', array_keys($relate_values)).", date_modified) VALUES ('".create_guid()."', "."'".implode("', '", $relate_values)."', ".$date_modified.")";
5181 5181
 
5182
-            $this->db->query($query, false, "Creating Relationship:" . $query);
5182
+            $this->db->query($query, false, "Creating Relationship:".$query);
5183 5183
         } elseif ($do_update) {
5184 5184
             $conds = array();
5185 5185
             foreach ($data_values as $key => $value) {
5186
-                array_push($conds, $key . "='" . $this->db->quote($value) . "'");
5186
+                array_push($conds, $key."='".$this->db->quote($value)."'");
5187 5187
             }
5188
-            $query = "UPDATE $table SET " . implode(',', $conds) . ",date_modified=" . $date_modified . " " . $where;
5189
-            $this->db->query($query, false, "Updating Relationship:" . $query);
5188
+            $query = "UPDATE $table SET ".implode(',', $conds).",date_modified=".$date_modified." ".$where;
5189
+            $this->db->query($query, false, "Updating Relationship:".$query);
5190 5190
         }
5191 5191
     }
5192 5192
 
@@ -5197,7 +5197,7 @@  discard block
 block discarded – undo
5197 5197
             $query .= " AND $name = '$value' ";
5198 5198
         }
5199 5199
         $query .= " ORDER BY $select_id ";
5200
-        $result = $this->db->query($query, false, "Retrieving Relationship:" . $query);
5200
+        $result = $this->db->query($query, false, "Retrieving Relationship:".$query);
5201 5201
         $ids = array();
5202 5202
         while ($row = $this->db->fetchByAssoc($result)) {
5203 5203
             $ids[] = $row;
@@ -5208,13 +5208,13 @@  discard block
 block discarded – undo
5208 5208
     public function loadLayoutDefs()
5209 5209
     {
5210 5210
         global $layout_defs;
5211
-        if (empty($this->layout_def) && file_exists('modules/' . $this->module_dir . '/layout_defs.php')) {
5212
-            include_once('modules/' . $this->module_dir . '/layout_defs.php');
5213
-            if (file_exists('custom/modules/' . $this->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php')) {
5214
-                include_once('custom/modules/' . $this->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php');
5211
+        if (empty($this->layout_def) && file_exists('modules/'.$this->module_dir.'/layout_defs.php')) {
5212
+            include_once('modules/'.$this->module_dir.'/layout_defs.php');
5213
+            if (file_exists('custom/modules/'.$this->module_dir.'/Ext/Layoutdefs/layoutdefs.ext.php')) {
5214
+                include_once('custom/modules/'.$this->module_dir.'/Ext/Layoutdefs/layoutdefs.ext.php');
5215 5215
             }
5216 5216
             if (empty($layout_defs[get_class($this)])) {
5217
-                echo "\$layout_defs[" . get_class($this) . "]; does not exist";
5217
+                echo "\$layout_defs[".get_class($this)."]; does not exist";
5218 5218
             }
5219 5219
 
5220 5220
             $this->layout_def = $layout_defs[get_class($this)];
@@ -5440,8 +5440,8 @@  discard block
 block discarded – undo
5440 5440
         $tmp = explode(",", $order_by);
5441 5441
         $comma = ' ';
5442 5442
         foreach ($tmp as $stmp) {
5443
-            $stmp = (substr_count($stmp, ".") > 0 ? trim($stmp) : "$qualify." . trim($stmp));
5444
-            $order_by_clause .= $comma . $stmp;
5443
+            $stmp = (substr_count($stmp, ".") > 0 ? trim($stmp) : "$qualify.".trim($stmp));
5444
+            $order_by_clause .= $comma.$stmp;
5445 5445
             $comma = ", ";
5446 5446
         }
5447 5447
         return $order_by_clause;
@@ -5457,19 +5457,19 @@  discard block
 block discarded – undo
5457 5457
         $street_field
5458 5458
     ) {
5459 5459
         if (isset($this->$street_field)) {
5460
-            $street_field_2 = $street_field . '_2';
5461
-            $street_field_3 = $street_field . '_3';
5462
-            $street_field_4 = $street_field . '_4';
5460
+            $street_field_2 = $street_field.'_2';
5461
+            $street_field_3 = $street_field.'_3';
5462
+            $street_field_4 = $street_field.'_4';
5463 5463
             if (isset($this->$street_field_2)) {
5464
-                $this->$street_field .= "\n" . $this->$street_field_2;
5464
+                $this->$street_field .= "\n".$this->$street_field_2;
5465 5465
                 unset($this->$street_field_2);
5466 5466
             }
5467 5467
             if (isset($this->$street_field_3)) {
5468
-                $this->$street_field .= "\n" . $this->$street_field_3;
5468
+                $this->$street_field .= "\n".$this->$street_field_3;
5469 5469
                 unset($this->$street_field_3);
5470 5470
             }
5471 5471
             if (isset($this->$street_field_4)) {
5472
-                $this->$street_field .= "\n" . $this->$street_field_4;
5472
+                $this->$street_field .= "\n".$this->$street_field_4;
5473 5473
                 unset($this->$street_field_4);
5474 5474
             }
5475 5475
             $this->$street_field = trim($this->$street_field, "\n");
Please login to merge, or discard this patch.
include/InlineEditing/InlineEditing.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 
43 43
     global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList;
44 44
 
45
-    $bean = BeanFactory::getBean($module,$id);
45
+    $bean = BeanFactory::getBean($module, $id);
46 46
 
47
-    if(!checkAccess($bean)){
47
+    if (!checkAccess($bean)) {
48 48
         return false;
49 49
     }
50 50
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     $mod_strings = return_module_language($current_language, $module);
55 55
 
56 56
     // set the filename for this control
57
-    $file = create_cache_directory('include/InlineEditing/') . $module . $view . $alt_type . $fieldname . '.tpl';
57
+    $file = create_cache_directory('include/InlineEditing/').$module.$view.$alt_type.$fieldname.'.tpl';
58 58
 
59 59
     if (!is_file($file)
60 60
         || inDeveloperMode()
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         if ($vardef['type'] == 'link') {
100 100
             $vardef['type'] = 'relate';
101 101
             $vardef['rname'] = 'name';
102
-            $vardef['id_name'] = $vardef['name'] . '_id';
102
+            $vardef['id_name'] = $vardef['name'].'_id';
103 103
             if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) {
104 104
                 $vardef['module'] = $focus->{$vardef['name']}->getRelatedModuleName();
105 105
             }
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
         // Remove all the copyright comments
136 136
         $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents);
137 137
         // remove extra wrong javascript which breaks auto complete on flexi relationship parent fields
138
-        $contents = preg_replace("/<script language=\"javascript\">if\(typeof sqs_objects == \'undefined\'\){var sqs_objects = new Array;}sqs_objects\[\'EditView_parent_name\'\].*?<\/script>/","",$contents);
138
+        $contents = preg_replace("/<script language=\"javascript\">if\(typeof sqs_objects == \'undefined\'\){var sqs_objects = new Array;}sqs_objects\[\'EditView_parent_name\'\].*?<\/script>/", "", $contents);
139 139
 
140 140
 
141 141
         if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) {
142 142
 
143
-            $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents);
144
-            $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents);
143
+            $contents = str_replace('"'.$vardef['id_name'].'"', '{/literal}"{$fields.'.$vardef['name'].'.id_name}"{literal}', $contents);
144
+            $contents = str_replace('"'.$vardef['name'].'"', '{/literal}"{$fields.'.$vardef['name'].'.name}"{literal}', $contents);
145 145
             // regex below fixes button javascript for flexi relationship
146
-            if($vardef['type'] == 'parent') {
146
+            if ($vardef['type'] == 'parent') {
147 147
                 $contents = str_replace("onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"{\$fields.parent_name.id_name}", "onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"parent_id", $contents);
148 148
             }
149 149
         }
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
     }
178 178
     $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
179 179
     if (!isset($match[2]) || $match[2] == '') {
180
-        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
180
+        $ss->assign('CALENDAR_FORMAT', $date_format.' '.$t23.$time_separator."%M");
181 181
     } else {
182 182
         $pm = $match[2] == "pm" ? "%P" : "%p";
183
-        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
183
+        $ss->assign('CALENDAR_FORMAT', $date_format.' '.$t23.$time_separator."%M".$pm);
184 184
     }
185 185
 
186 186
     $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
     }
220 220
 
221 221
     if ($fieldlist[$fieldname]['type'] == 'link') {
222
-        $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id';
222
+        $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'].'_id';
223 223
 
224 224
         if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) {
225 225
             $relateField = $fieldlist[$fieldname]['name'];
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         }
228 228
     }
229 229
 
230
-    if($fieldlist[$fieldname]['type'] == 'parent'){
230
+    if ($fieldlist[$fieldname]['type'] == 'parent') {
231 231
         $fieldlist['parent_id']['name'] = 'parent_id';
232 232
     }
233 233
 
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
     }
239 239
 
240 240
     if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) {
241
-        if($value){
241
+        if ($value) {
242 242
             $relateIdField = $fieldlist[$fieldname]['id_name'];
243
-            $rel_value =  $bean->$relateIdField;
243
+            $rel_value = $bean->$relateIdField;
244 244
 
245 245
         }
246 246
         $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $rel_value;
247 247
         $fieldlist[$fieldname]['value'] = $value;
248 248
         $fieldlist[$fieldname]['id_name'] = $aow_field;
249
-        $fieldlist[$fieldname]['name'] = $aow_field . '_display';
249
+        $fieldlist[$fieldname]['name'] = $aow_field.'_display';
250 250
     } else if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime')) {
251 251
         $value = $focus->convertField($value, $fieldlist[$fieldname]);
252 252
         if (!$value) {
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
 
311 311
         if ($bean->field_defs[$field]['type'] == "multienum") {
312 312
             $bean->$field = encodeMultienumValue($value);
313
-        }else if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent'){
313
+        } else if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent') {
314 314
             $save_field = $bean->field_defs[$field]['id_name'];
315 315
             $bean->$save_field = $value;
316 316
             if ($bean->field_defs[$field]['type'] == 'parent') {
317 317
                 $bean->parent_type = $_REQUEST['parent_type'];
318 318
                 $bean->fill_in_additional_parent_fields(); // get up to date parent info as need it to display name
319 319
             }
320
-        }else{
320
+        } else {
321 321
             $bean->$field = $value;
322 322
         }
323 323
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
     $fieldlist[$field] = $bean->getFieldDefinition($field);
344 344
 
345
-    if(is_array($listViewDefs)){
345
+    if (is_array($listViewDefs)) {
346 346
         $fieldlist[$field] = array_merge($fieldlist[$field], $listViewDefs);
347 347
     }
348 348
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
         $vardef['module'] = $bean->module_dir;
381 381
 
382 382
         $SugarWidgetSubPanelDetailViewLink = new SugarWidgetSubPanelDetailViewLink($vardef);
383
-        $value = "<b>" . $SugarWidgetSubPanelDetailViewLink->displayList($vardef) . "</b>";
383
+        $value = "<b>".$SugarWidgetSubPanelDetailViewLink->displayList($vardef)."</b>";
384 384
 
385 385
     }
386 386
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
         }
394 394
         $datetime_format = $timedate->get_date_time_format();
395 395
         // create utc date (as it's utc in db)
396
-        $datetime = DateTime::createFromFormat("Y-m-d H:i:s", $value,new DateTimeZone('UTC'));
396
+        $datetime = DateTime::createFromFormat("Y-m-d H:i:s", $value, new DateTimeZone('UTC'));
397 397
         // convert it to timezone the user uses
398 398
         $datetime = $timedate->tzUser($datetime);
399 399
 
@@ -432,24 +432,24 @@  discard block
 block discarded – undo
432 432
     }
433 433
 
434 434
     //if field is of type relate.
435
-    if ($vardef['type'] == "relate" || $vardef['type'] == "parent")  {
435
+    if ($vardef['type'] == "relate" || $vardef['type'] == "parent") {
436 436
 
437
-        if($vardef['source'] == "non-db"){
437
+        if ($vardef['source'] == "non-db") {
438 438
 
439
-            if($vardef['module'] == "Employees"){
439
+            if ($vardef['module'] == "Employees") {
440 440
                 $vardef['ext2'] = "Users";
441 441
                 $vardef['rname'] = "full_name";
442 442
             }
443 443
 
444 444
         }
445
-        if($vardef['type'] == "parent") {
445
+        if ($vardef['type'] == "parent") {
446 446
             $vardef['module'] = $bean->parent_type;
447 447
             $name = $bean->parent_name;
448 448
         }
449 449
         $idName = $vardef['id_name'];
450 450
         $record = $bean->$idName;
451 451
 
452
-        if($vardef['name'] != "assigned_user_name") {
452
+        if ($vardef['name'] != "assigned_user_name") {
453 453
             $value = "<a class=\"listViewTdLinkS1\" href=\"index.php?action=DetailView&module=".$vardef['module']."&record=$record\">";
454 454
         } else {
455 455
             $value = "";
@@ -457,26 +457,26 @@  discard block
 block discarded – undo
457 457
 
458 458
 
459 459
         //To fix github bug 880 (the rname was null and was causing a 500 error in the getFieldValueFromModule call to $fieldname
460
-        $fieldName = 'name';//$vardef['name'];
461
-        if(!is_null($vardef['rname']))
460
+        $fieldName = 'name'; //$vardef['name'];
461
+        if (!is_null($vardef['rname']))
462 462
             $fieldName = $vardef['rname'];
463 463
 
464
-        if($vardef['ext2']){
464
+        if ($vardef['ext2']) {
465 465
 
466
-            $value .= getFieldValueFromModule($fieldName,$vardef['ext2'],$record);
466
+            $value .= getFieldValueFromModule($fieldName, $vardef['ext2'], $record);
467 467
 
468
-        }else if(!empty($vardef['rname'])){
469
-            $value .= getFieldValueFromModule($fieldName,$vardef['module'],$record);
468
+        } else if (!empty($vardef['rname'])) {
469
+            $value .= getFieldValueFromModule($fieldName, $vardef['module'], $record);
470 470
 
471 471
         } else {
472 472
             $value .= $name;
473 473
         }
474 474
 
475
-        if($vardef['name'] != "assigned_user_name") {
475
+        if ($vardef['name'] != "assigned_user_name") {
476 476
             $value .= "</a>";
477 477
         }
478 478
     }
479
-	if($vardef['type'] == "url")
479
+	if ($vardef['type'] == "url")
480 480
 	{
481 481
 		$value = '<a href='.$value.' target="_blank">'.$value.'</a>';
482 482
 	}
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 function getFieldValueFromModule($fieldname, $module, $id)
488 488
 {
489 489
     //Github bug 880, if the fieldname is null, do no call from bean
490
-    if(is_null($fieldname))
490
+    if (is_null($fieldname))
491 491
         return '';
492 492
 
493 493
     $bean = BeanFactory::getBean($module, $id);
@@ -508,11 +508,11 @@  discard block
 block discarded – undo
508 508
     return $value;
509 509
 }
510 510
 
511
-function checkAccess($bean){
511
+function checkAccess($bean) {
512 512
 
513
-    if($bean->ACLAccess('EditView')) {
513
+    if ($bean->ACLAccess('EditView')) {
514 514
         return true;
515
-    }else {
515
+    } else {
516 516
         return false;
517 517
     }
518 518
 }
Please login to merge, or discard this patch.
include/SugarEmailAddress/SugarEmailAddress.php 1 patch
Spacing   +173 added lines, -173 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.
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
     /**
82 82
      * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
83 83
      */
84
-    public function SugarEmailAddress(){
84
+    public function SugarEmailAddress() {
85 85
         $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
86
-        if(isset($GLOBALS['log'])) {
86
+        if (isset($GLOBALS['log'])) {
87 87
             $GLOBALS['log']->deprecated($deprecatedMessage);
88 88
         }
89 89
         else {
@@ -99,16 +99,16 @@  discard block
 block discarded – undo
99 99
      * @param string $module
100 100
      */
101 101
     function handleLegacySave($bean, $prefix = "") {
102
-        if(!isset($_REQUEST) || !isset($_REQUEST['useEmailWidget'])) {
102
+        if (!isset($_REQUEST) || !isset($_REQUEST['useEmailWidget'])) {
103 103
             if (empty($this->addresses) || !isset($_REQUEST['massupdate'])) {
104 104
                 $this->addresses = array();
105 105
                 $optOut = (isset($bean->email_opt_out) && $bean->email_opt_out == "1") ? true : false;
106 106
                 $invalid = (isset($bean->invalid_email) && $bean->invalid_email == "1") ? true : false;
107 107
 
108 108
                 $isPrimary = true;
109
-                for($i = 1; $i <= 10; $i++){
109
+                for ($i = 1; $i <= 10; $i++) {
110 110
                     $email = 'email'.$i;
111
-                    if(isset($bean->$email) && !empty($bean->$email)){
111
+                    if (isset($bean->$email) && !empty($bean->$email)) {
112 112
                         $opt_out_field = $email.'_opt_out';
113 113
                         $invalid_field = $email.'_invalid';
114 114
                         $field_optOut = (isset($bean->$opt_out_field)) ? $bean->$opt_out_field : $optOut;
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
                 }
120 120
             }
121 121
         }
122
-        $this->populateAddresses($bean->id, $bean->module_dir, array(),'');
123
-        if(isset($_REQUEST) && isset($_REQUEST['useEmailWidget'])) {
122
+        $this->populateAddresses($bean->id, $bean->module_dir, array(), '');
123
+        if (isset($_REQUEST) && isset($_REQUEST['useEmailWidget'])) {
124 124
             $this->populateLegacyFields($bean);
125 125
         }
126 126
     }
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
         return;
143 143
     }
144 144
 
145
-    function populateLegacyFields(&$bean){
145
+    function populateLegacyFields(&$bean) {
146 146
         $primary_found = false;
147 147
         $alternate_found = false;
148 148
         $alternate2_found = false;
149
-        foreach($this->addresses as $k=>$address) {
149
+        foreach ($this->addresses as $k=>$address) {
150 150
             if ($primary_found && $alternate_found)
151 151
                 break;
152 152
             if ($address['primary_address'] == 1 && !$primary_found) {
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             } elseif (!$alternate_found) {
156 156
                 $alternate_index = $k;
157 157
                 $alternate_found = true;
158
-            } elseif (!$alternate2_found){
158
+            } elseif (!$alternate2_found) {
159 159
                 $alternate2_index = $k;
160 160
                 $alternate2_found = true;
161 161
             }
@@ -192,27 +192,27 @@  discard block
 block discarded – undo
192 192
         $args = func_get_args();
193 193
         return call_user_func_array(array($this, '_save'), $args);
194 194
     }
195
-    private function _save($id, $module, $new_addrs=array(), $primary='', $replyTo='', $invalid='', $optOut='', $in_workflow=false) {
196
-        if(empty($this->addresses) || $in_workflow){
197
-            $this->populateAddresses($id, $module, $new_addrs,$primary);
195
+    private function _save($id, $module, $new_addrs = array(), $primary = '', $replyTo = '', $invalid = '', $optOut = '', $in_workflow = false) {
196
+        if (empty($this->addresses) || $in_workflow) {
197
+            $this->populateAddresses($id, $module, $new_addrs, $primary);
198 198
         }
199 199
 
200 200
         //find all email addresses..
201
-        $current_links=array();
201
+        $current_links = array();
202 202
         // Need to correct this to handle the Employee/User split
203 203
         $module = $this->getCorrectedModule($module);
204
-        $q2="select *  from email_addr_bean_rel eabr WHERE eabr.bean_id = '".$this->db->quote($id)."' AND eabr.bean_module = '".$this->db->quote($module)."' and eabr.deleted=0";
204
+        $q2 = "select *  from email_addr_bean_rel eabr WHERE eabr.bean_id = '".$this->db->quote($id)."' AND eabr.bean_module = '".$this->db->quote($module)."' and eabr.deleted=0";
205 205
         $r2 = $this->db->query($q2);
206
-        while(($row2=$this->db->fetchByAssoc($r2)) != null ) {
207
-            $current_links[$row2['email_address_id']]=$row2;
206
+        while (($row2 = $this->db->fetchByAssoc($r2)) != null) {
207
+            $current_links[$row2['email_address_id']] = $row2;
208 208
         }
209 209
 
210 210
         $isConversion = (isset($_REQUEST) && isset($_REQUEST['action']) && $_REQUEST['action'] == 'ConvertLead') ? true : false;
211 211
 
212 212
         if (!empty($this->addresses)) {
213 213
             // insert new relationships and create email address record, if they don't exist
214
-            foreach($this->addresses as $address) {
215
-                if(!empty($address['email_address'])) {
214
+            foreach ($this->addresses as $address) {
215
+                if (!empty($address['email_address'])) {
216 216
                     $guid = create_guid();
217 217
                     $emailId = isset($address['email_address_id'])
218 218
                         && isset($current_links[$address['email_address_id']])
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
                     $emailId = $this->AddUpdateEmailAddress($address['email_address'],
221 221
                                                             $address['invalid_email'],
222 222
                                                             $address['opt_out'],
223
-                                                            $emailId);// this will save the email address if not found
223
+                                                            $emailId); // this will save the email address if not found
224 224
 
225 225
                     //verify linkage and flags.
226
-                    $upd_eabr="";
226
+                    $upd_eabr = "";
227 227
                     if (isset($current_links[$emailId])) {
228 228
                         if (!$isConversion) { // do not update anything if this is for lead conversion
229
-                        if ($address['primary_address'] != $current_links[$emailId]['primary_address'] or $address['reply_to_address'] != $current_links[$emailId]['reply_to_address'] ) {
230
-                            $upd_eabr="UPDATE email_addr_bean_rel SET primary_address='".$this->db->quote($address['primary_address'])."', reply_to_address='".$this->db->quote($address['reply_to_address'])."' WHERE id='".$this->db->quote($current_links[$emailId]['id'])."'";
229
+                        if ($address['primary_address'] != $current_links[$emailId]['primary_address'] or $address['reply_to_address'] != $current_links[$emailId]['reply_to_address']) {
230
+                            $upd_eabr = "UPDATE email_addr_bean_rel SET primary_address='".$this->db->quote($address['primary_address'])."', reply_to_address='".$this->db->quote($address['reply_to_address'])."' WHERE id='".$this->db->quote($current_links[$emailId]['id'])."'";
231 231
                         }
232 232
 
233 233
                         unset($current_links[$emailId]);
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
         // for lead conversion, do not delete email addresses
259 259
         if (!empty($current_links) && !$isConversion) {
260 260
 
261
-            $delete="";
261
+            $delete = "";
262 262
             foreach ($current_links as $eabr) {
263 263
 
264
-                $delete.=empty($delete) ? "'".$this->db->quote($eabr['id']) . "' " : ",'" . $this->db->quote($eabr['id']) . "'";
264
+                $delete .= empty($delete) ? "'".$this->db->quote($eabr['id'])."' " : ",'".$this->db->quote($eabr['id'])."'";
265 265
             }
266 266
 
267
-            $eabr_unlink="update email_addr_bean_rel set deleted=1 where id in ({$delete})";
267
+            $eabr_unlink = "update email_addr_bean_rel set deleted=1 where id in ({$delete})";
268 268
             $this->db->query($eabr_unlink);
269 269
         }
270 270
         $this->stateBeforeWorkflow = null;
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
         )
287 287
     {
288 288
         $emailCaps = strtoupper(trim($email));
289
-        if(empty($emailCaps))
289
+        if (empty($emailCaps))
290 290
             return 0;
291 291
 
292 292
         $q = "SELECT *
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
         $r = $this->db->query($q, true);
325 325
 
326 326
         $retArr = array();
327
-        while($a = $this->db->fetchByAssoc($r)) {
327
+        while ($a = $this->db->fetchByAssoc($r)) {
328 328
             $retArr[] = $a['bean_id'];
329 329
         }
330
-        if(count($retArr) > 0) {
330
+        if (count($retArr) > 0) {
331 331
             return $retArr;
332 332
         } else {
333 333
             return false;
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 
348 348
         $email = trim($email);
349 349
 
350
-        if(empty($email)) {
350
+        if (empty($email)) {
351 351
             return array();
352 352
         }
353 353
 
@@ -356,12 +356,12 @@  discard block
 block discarded – undo
356 356
                 WHERE ea.email_address_caps = $emailCaps and eabl.deleted=0 ";
357 357
         $r = $this->db->query($q);
358 358
 
359
-        while($a = $this->db->fetchByAssoc($r)) {
360
-            if(isset($beanList[$a['bean_module']]) && !empty($beanList[$a['bean_module']])) {
359
+        while ($a = $this->db->fetchByAssoc($r)) {
360
+            if (isset($beanList[$a['bean_module']]) && !empty($beanList[$a['bean_module']])) {
361 361
                 $className = $beanList[$a['bean_module']];
362 362
 
363
-                if(isset($beanFiles[$className]) && !empty($beanFiles[$className])) {
364
-                    if(!class_exists($className)) {
363
+                if (isset($beanFiles[$className]) && !empty($beanFiles[$className])) {
364
+                    if (!class_exists($className)) {
365 365
                         require_once($beanFiles[$className]);
366 366
                     }
367 367
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
      * @param string $replyTo GUID of reply-to address
390 390
      * @param string $invalid GUID of invalid address
391 391
      */
392
-    function populateAddresses($id, $module, $new_addrs=array(), $primary='', $replyTo='', $invalid='', $optOut='') {
392
+    function populateAddresses($id, $module, $new_addrs = array(), $primary = '', $replyTo = '', $invalid = '', $optOut = '') {
393 393
         $module = $this->getCorrectedModule($module);
394 394
         //One last check for the ConvertLead action in which case we need to change $module to 'Leads'
395 395
         $module = (isset($_REQUEST) && isset($_REQUEST['action']) && $_REQUEST['action'] == 'ConvertLead') ? 'Leads' : $module;
@@ -400,54 +400,54 @@  discard block
 block discarded – undo
400 400
         $hasEmailValue = false;
401 401
         $email_ids = array();
402 402
 
403
-        if (isset($_REQUEST) && isset($_REQUEST[$module .'_email_widget_id'])) {
403
+        if (isset($_REQUEST) && isset($_REQUEST[$module.'_email_widget_id'])) {
404 404
 
405 405
             $fromRequest = false;
406 406
             // determine which array to process
407
-            foreach($_REQUEST as $k => $v) {
408
-                if(strpos($k, 'emailAddress') !== false) {
407
+            foreach ($_REQUEST as $k => $v) {
408
+                if (strpos($k, 'emailAddress') !== false) {
409 409
                    $fromRequest = true;
410 410
                    break;
411 411
                 }
412
-            $widget_id = $_REQUEST[$module .'_email_widget_id'];
412
+            $widget_id = $_REQUEST[$module.'_email_widget_id'];
413 413
     }
414 414
 
415 415
             //Iterate over the widgets for this module, in case there are multiple email widgets for this module
416
-            while(isset($_REQUEST[$module . $widget_id . "emailAddress" . $widgetCount]))
416
+            while (isset($_REQUEST[$module.$widget_id."emailAddress".$widgetCount]))
417 417
             {
418
-                if (empty($_REQUEST[$module . $widget_id . "emailAddress" . $widgetCount])) {
418
+                if (empty($_REQUEST[$module.$widget_id."emailAddress".$widgetCount])) {
419 419
                     $widgetCount++;
420 420
                     continue;
421 421
                 }
422 422
 
423 423
                 $hasEmailValue = true;
424 424
 
425
-                $eId = $module . $widget_id;
426
-                if(isset($_REQUEST[$eId . 'emailAddressPrimaryFlag'])) {
427
-                   $primaryValue = $_REQUEST[$eId . 'emailAddressPrimaryFlag'];
428
-                } else if(isset($_REQUEST[$module . 'emailAddressPrimaryFlag'])) {
429
-                   $primaryValue = $_REQUEST[$module . 'emailAddressPrimaryFlag'];
425
+                $eId = $module.$widget_id;
426
+                if (isset($_REQUEST[$eId.'emailAddressPrimaryFlag'])) {
427
+                   $primaryValue = $_REQUEST[$eId.'emailAddressPrimaryFlag'];
428
+                } else if (isset($_REQUEST[$module.'emailAddressPrimaryFlag'])) {
429
+                   $primaryValue = $_REQUEST[$module.'emailAddressPrimaryFlag'];
430 430
                 }
431 431
 
432 432
                 $optOutValues = array();
433
-                if(isset($_REQUEST[$eId .'emailAddressOptOutFlag'])) {
434
-                   $optOutValues = $_REQUEST[$eId .'emailAddressOptOutFlag'];
435
-                } else if(isset($_REQUEST[$module . 'emailAddressOptOutFlag'])) {
436
-                   $optOutValues = $_REQUEST[$module . 'emailAddressOptOutFlag'];
433
+                if (isset($_REQUEST[$eId.'emailAddressOptOutFlag'])) {
434
+                   $optOutValues = $_REQUEST[$eId.'emailAddressOptOutFlag'];
435
+                } else if (isset($_REQUEST[$module.'emailAddressOptOutFlag'])) {
436
+                   $optOutValues = $_REQUEST[$module.'emailAddressOptOutFlag'];
437 437
                 }
438 438
 
439 439
                 $invalidValues = array();
440
-                if(isset($_REQUEST[$eId .'emailAddressInvalidFlag'])) {
441
-                   $invalidValues = $_REQUEST[$eId .'emailAddressInvalidFlag'];
442
-                } else if(isset($_REQUEST[$module . 'emailAddressInvalidFlag'])) {
443
-                   $invalidValues = $_REQUEST[$module . 'emailAddressInvalidFlag'];
440
+                if (isset($_REQUEST[$eId.'emailAddressInvalidFlag'])) {
441
+                   $invalidValues = $_REQUEST[$eId.'emailAddressInvalidFlag'];
442
+                } else if (isset($_REQUEST[$module.'emailAddressInvalidFlag'])) {
443
+                   $invalidValues = $_REQUEST[$module.'emailAddressInvalidFlag'];
444 444
                 }
445 445
 
446 446
                 $deleteValues = array();
447
-                if(isset($_REQUEST[$eId .'emailAddressDeleteFlag'])) {
448
-                   $deleteValues = $_REQUEST[$eId .'emailAddressDeleteFlag'];
449
-                } else if(isset($_REQUEST[$module . 'emailAddressDeleteFlag'])) {
450
-                   $deleteValues = $_REQUEST[$module . 'emailAddressDeleteFlag'];
447
+                if (isset($_REQUEST[$eId.'emailAddressDeleteFlag'])) {
448
+                   $deleteValues = $_REQUEST[$eId.'emailAddressDeleteFlag'];
449
+                } else if (isset($_REQUEST[$module.'emailAddressDeleteFlag'])) {
450
+                   $deleteValues = $_REQUEST[$module.'emailAddressDeleteFlag'];
451 451
                 }
452 452
 
453 453
                 // prep from form save
@@ -455,36 +455,36 @@  discard block
 block discarded – undo
455 455
                 $replyToField = '';
456 456
                 $invalidField = '';
457 457
                 $optOutField = '';
458
-                if($fromRequest && empty($primary) && isset($primaryValue)) {
458
+                if ($fromRequest && empty($primary) && isset($primaryValue)) {
459 459
                     $primaryField = $primaryValue;
460 460
                 }
461 461
 
462
-                if($fromRequest && empty($replyTo)) {
463
-                    if(isset($_REQUEST[$eId .'emailAddressReplyToFlag'])) {
464
-                       $replyToField = $_REQUEST[$eId .'emailAddressReplyToFlag'];
465
-                    } else if(isset($_REQUEST[$module . 'emailAddressReplyToFlag'])) {
466
-                       $replyToField = $_REQUEST[$module . 'emailAddressReplyToFlag'];
462
+                if ($fromRequest && empty($replyTo)) {
463
+                    if (isset($_REQUEST[$eId.'emailAddressReplyToFlag'])) {
464
+                       $replyToField = $_REQUEST[$eId.'emailAddressReplyToFlag'];
465
+                    } else if (isset($_REQUEST[$module.'emailAddressReplyToFlag'])) {
466
+                       $replyToField = $_REQUEST[$module.'emailAddressReplyToFlag'];
467 467
                     }
468 468
                 }
469
-                if($fromRequest && empty($new_addrs)) {
470
-                    foreach($_REQUEST as $k => $v) {
471
-                        if(preg_match('/'.$eId.'emailAddress[0-9]+$/i', $k) && !empty($v)) {
469
+                if ($fromRequest && empty($new_addrs)) {
470
+                    foreach ($_REQUEST as $k => $v) {
471
+                        if (preg_match('/'.$eId.'emailAddress[0-9]+$/i', $k) && !empty($v)) {
472 472
                             $new_addrs[$k] = $v;
473 473
                         }
474 474
                     }
475 475
                 }
476
-                if($fromRequest && empty($email_ids)) {
477
-                    foreach($_REQUEST as $k => $v) {
478
-                        if(preg_match('/'.$eId.'emailAddressId[0-9]+$/i', $k) && !empty($v)) {
476
+                if ($fromRequest && empty($email_ids)) {
477
+                    foreach ($_REQUEST as $k => $v) {
478
+                        if (preg_match('/'.$eId.'emailAddressId[0-9]+$/i', $k) && !empty($v)) {
479 479
                             $key = str_replace('emailAddressId', 'emailAddress', $k);
480 480
                             $email_ids[$key] = $v;
481 481
                         }
482 482
                     }
483 483
                 }
484 484
 
485
-                if($fromRequest && empty($new_addrs)) {
486
-                    foreach($_REQUEST as $k => $v) {
487
-                        if(preg_match('/'.$eId.'emailAddressVerifiedValue[0-9]+$/i', $k) && !empty($v)) {
485
+                if ($fromRequest && empty($new_addrs)) {
486
+                    foreach ($_REQUEST as $k => $v) {
487
+                        if (preg_match('/'.$eId.'emailAddressVerifiedValue[0-9]+$/i', $k) && !empty($v)) {
488 488
                             $validateFlag = str_replace("Value", "Flag", $k);
489 489
                             if (isset($_REQUEST[$validateFlag]) && $_REQUEST[$validateFlag] == "true")
490 490
                               $new_addrs[$k] = $v;
@@ -493,21 +493,21 @@  discard block
 block discarded – undo
493 493
                 }
494 494
 
495 495
                 //empty the addresses array if the post happened from email address widget.
496
-                if($post_from_email_address_widget) {
497
-                    $this->addresses=array();  //this gets populated during retrieve of the contact bean.
496
+                if ($post_from_email_address_widget) {
497
+                    $this->addresses = array(); //this gets populated during retrieve of the contact bean.
498 498
                 } else {
499 499
                     $optOutValues = array();
500 500
                     $invalidValues = array();
501
-                    foreach($new_addrs as $k=>$email) {
501
+                    foreach ($new_addrs as $k=>$email) {
502 502
                        preg_match('/emailAddress([0-9])+$/', $k, $matches);
503 503
                        $count = $matches[1];
504
-                       $result = $this->db->query("SELECT opt_out, invalid_email from email_addresses where email_address_caps = '" . $this->db->quote(strtoupper($email)) . "'");
505
-                       if(!empty($result)) {
506
-                          $row=$this->db->fetchByAssoc($result);
507
-                          if(!empty($row['opt_out'])) {
504
+                       $result = $this->db->query("SELECT opt_out, invalid_email from email_addresses where email_address_caps = '".$this->db->quote(strtoupper($email))."'");
505
+                       if (!empty($result)) {
506
+                          $row = $this->db->fetchByAssoc($result);
507
+                          if (!empty($row['opt_out'])) {
508 508
                              $optOutValues[$k] = "emailAddress$count";
509 509
                           }
510
-                          if(!empty($row['invalid_email'])) {
510
+                          if (!empty($row['invalid_email'])) {
511 511
                              $invalidValues[$k] = "emailAddress$count";
512 512
                           }
513 513
                        }
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
                 }
516 516
                 // Re-populate the addresses class variable if we have new address(es).
517 517
                 if (!empty($new_addrs)) {
518
-                    foreach($new_addrs as $k => $reqVar) {
518
+                    foreach ($new_addrs as $k => $reqVar) {
519 519
                         //$key = preg_match("/^$eId/s", $k) ? substr($k, strlen($eId)) : $k;
520 520
                         $reqVar = trim($reqVar);
521
-                        if(strpos($k, 'emailAddress') !== false) {
522
-                            if(!empty($reqVar) && !in_array($k, $deleteValues)) {
521
+                        if (strpos($k, 'emailAddress') !== false) {
522
+                            if (!empty($reqVar) && !in_array($k, $deleteValues)) {
523 523
                                 $email_id   = (array_key_exists($k, $email_ids)) ? $email_ids[$k] : null;
524 524
                                 $primary    = ($k == $primaryValue) ? true : false;
525 525
                                 $replyTo    = ($k == $replyToField) ? true : false;
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
         }
537 537
 
538 538
         //If no widgets, set addresses array to empty
539
-        if($post_from_email_address_widget && !$hasEmailValue) {
539
+        if ($post_from_email_address_widget && !$hasEmailValue) {
540 540
            $this->addresses = array();
541 541
         }
542 542
     }
@@ -547,9 +547,9 @@  discard block
 block discarded – undo
547 547
      * @param bool $primary Default false
548 548
      * @param bool $replyTo Default false
549 549
      */
550
-    function addAddress($addr, $primary=false, $replyTo=false, $invalid=false, $optOut=false, $email_id = null) {
550
+    function addAddress($addr, $primary = false, $replyTo = false, $invalid = false, $optOut = false, $email_id = null) {
551 551
         $addr = html_entity_decode($addr, ENT_QUOTES);
552
-        if(preg_match($this->regex, $addr)) {
552
+        if (preg_match($this->regex, $addr)) {
553 553
             $primaryFlag = ($primary) ? '1' : '0';
554 554
             $replyToFlag = ($replyTo) ? '1' : '0';
555 555
             $invalidFlag = ($invalid) ? '1' : '0';
@@ -585,17 +585,17 @@  discard block
 block discarded – undo
585 585
      * Updates invalid_email and opt_out flags for each address
586 586
      */
587 587
     function updateFlags() {
588
-        if(!empty($this->addresses)) {
589
-            foreach($this->addresses as $addressMeta) {
590
-                if(isset($addressMeta['email_address']) && !empty($addressMeta['email_address'])) {
588
+        if (!empty($this->addresses)) {
589
+            foreach ($this->addresses as $addressMeta) {
590
+                if (isset($addressMeta['email_address']) && !empty($addressMeta['email_address'])) {
591 591
                     $address = $this->db->quote($this->_cleanAddress($addressMeta['email_address']));
592 592
 
593 593
                     $q = "SELECT * FROM email_addresses WHERE email_address = '{$address}'";
594 594
                     $r = $this->db->query($q);
595 595
                     $a = $this->db->fetchByAssoc($r);
596 596
 
597
-                    if(!empty($a)) {
598
-                        if(isset($a['invalid_email']) && isset($addressMeta['invalid_email']) && isset($addressMeta['opt_out']) && $a['invalid_email'] != $addressMeta['invalid_email'] || $a['opt_out'] != $addressMeta['opt_out']) {
597
+                    if (!empty($a)) {
598
+                        if (isset($a['invalid_email']) && isset($addressMeta['invalid_email']) && isset($addressMeta['opt_out']) && $a['invalid_email'] != $addressMeta['invalid_email'] || $a['opt_out'] != $addressMeta['opt_out']) {
599 599
                             $qUpdate = "UPDATE email_addresses SET invalid_email = ".intval($addressMeta['invalid_email']).", opt_out = ".intval($addressMeta['opt_out']).", date_modified = '".TimeDate::getInstance()->nowDb()."' WHERE id = '".$this->db->quote($a['id'])."'";
600 600
                             $rUpdate = $this->db->query($qUpdate);
601 601
                         }
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
     public function splitEmailAddress($addr)
609 609
     {
610 610
         $email = $this->_cleanAddress($addr);
611
-        if(!preg_match($this->regex, $email)) {
611
+        if (!preg_match($this->regex, $email)) {
612 612
             $email = ''; // remove bad email addr
613 613
         }
614 614
         $name = trim(str_replace(array($email, '<', '>', '"', "'"), '', $addr));
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
     function _cleanAddress($addr) {
625 625
         $addr = trim(from_html($addr));
626 626
 
627
-        if(strpos($addr, "<") !== false && strpos($addr, ">") !== false) {
628
-            $address = trim(substr($addr, strrpos($addr, "<") +1, strrpos($addr, ">") - strrpos($addr, "<") -1));
627
+        if (strpos($addr, "<") !== false && strpos($addr, ">") !== false) {
628
+            $address = trim(substr($addr, strrpos($addr, "<") + 1, strrpos($addr, ">") - strrpos($addr, "<") - 1));
629 629
         } else {
630 630
             $address = trim($addr);
631 631
         }
@@ -646,11 +646,11 @@  discard block
 block discarded – undo
646 646
         $r = $this->db->query($q);
647 647
         $a = $this->db->fetchByAssoc($r);
648 648
 
649
-        if(!empty($a) && !empty($a['id'])) {
649
+        if (!empty($a) && !empty($a['id'])) {
650 650
             return $a['id'];
651 651
         } else {
652 652
             $guid = '';
653
-            if(!empty($address)){
653
+            if (!empty($address)) {
654 654
                 $guid = create_guid();
655 655
                 $now = TimeDate::getInstance()->nowDb();
656 656
                 $qa = "INSERT INTO email_addresses (id, email_address, email_address_caps, date_created, date_modified, deleted)
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
      *        to propagate to the new SugarEmailAddress - see bug 39188
673 673
      * @return String GUID of Email Address or '' if cleaned address was empty.
674 674
      */
675
-    public function AddUpdateEmailAddress($addr,$invalid=0,$opt_out=0,$id=null)
675
+    public function AddUpdateEmailAddress($addr, $invalid = 0, $opt_out = 0, $id = null)
676 676
     {
677 677
         // sanity checks to avoid SQL injection.
678 678
         $invalid = intval($invalid);
@@ -722,12 +722,12 @@  discard block
 block discarded – undo
722 722
             if ($duplicate_email['invalid_email'] != $new_invalid ||
723 723
                 $duplicate_email['opt_out'] != $new_opt_out ||
724 724
                 (trim($duplicate_email['email_address']) != $address)) {
725
-                $upd_q = 'UPDATE ' . $this->table_name . ' ' .
726
-                    'SET email_address=\'' . $address . '\', ' .
727
-                    'invalid_email=' . $new_invalid . ', ' .
728
-                    'opt_out=' . $new_opt_out . ', ' .
729
-                    'date_modified=' . $this->db->now() . ' ' .
730
-                    'WHERE id=\'' . $this->db->quote($duplicate_email['id']) . '\'';
725
+                $upd_q = 'UPDATE '.$this->table_name.' '.
726
+                    'SET email_address=\''.$address.'\', '.
727
+                    'invalid_email='.$new_invalid.', '.
728
+                    'opt_out='.$new_opt_out.', '.
729
+                    'date_modified='.$this->db->now().' '.
730
+                    'WHERE id=\''.$this->db->quote($duplicate_email['id']).'\'';
731 731
                 $upd_r = $this->db->query($upd_q);
732 732
             }
733 733
             return $duplicate_email['id'];
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
         else {
736 736
             // no case-insensitive address match - it's new, or undeleted.
737 737
             $guid = '';
738
-            if(!empty($address)){
738
+            if (!empty($address)) {
739 739
                 $guid = create_guid();
740 740
                 $now = TimeDate::getInstance()->nowDb();
741 741
                 $qa = "INSERT INTO email_addresses (id, email_address, email_address_caps, date_created, date_modified, deleted, invalid_email, opt_out)
@@ -751,12 +751,12 @@  discard block
 block discarded – undo
751 751
      * @param object $focus Object in focus
752 752
      * @return string email
753 753
      */
754
-    function getPrimaryAddress($focus,$parent_id=null,$parent_type=null) {
754
+    function getPrimaryAddress($focus, $parent_id = null, $parent_type = null) {
755 755
 
756
-        $parent_type=empty($parent_type) ? $focus->module_dir : $parent_type;
756
+        $parent_type = empty($parent_type) ? $focus->module_dir : $parent_type;
757 757
         // Bug63174: Email address is not shown in the list view for employees
758 758
         $parent_type = $this->getCorrectedModule($parent_type);
759
-        $parent_id=empty($parent_id) ? $focus->id : $parent_id;
759
+        $parent_id = empty($parent_id) ? $focus->id : $parent_id;
760 760
 
761 761
         $q = "SELECT ea.email_address FROM email_addresses ea
762 762
                 LEFT JOIN email_addr_bean_rel ear ON ea.id = ear.email_address_id
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
         $r = $this->db->limitQuery($q, 0, 1);
769 769
         $a = $this->db->fetchByAssoc($r);
770 770
 
771
-        if(isset($a['email_address'])) {
771
+        if (isset($a['email_address'])) {
772 772
             return $a['email_address'];
773 773
         }
774 774
         return '';
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
         $r = $this->db->query($q);
810 810
         $a = $this->db->fetchByAssoc($r);
811 811
 
812
-        if(isset($a['email_address'])) {
812
+        if (isset($a['email_address'])) {
813 813
             return $a['email_address'];
814 814
         }
815 815
         return '';
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
                 ORDER BY ear.reply_to_address, ear.primary_address DESC";
835 835
         $r = $this->db->query($q);
836 836
 
837
-        while($a = $this->db->fetchByAssoc($r, FALSE)) {
837
+        while ($a = $this->db->fetchByAssoc($r, FALSE)) {
838 838
             $return[] = $a;
839 839
         }
840 840
 
@@ -848,9 +848,9 @@  discard block
 block discarded – undo
848 848
      * @param bool asMetadata Default false
849 849
      * @return string HTML/JS for widget
850 850
      */
851
-    function getEmailAddressWidgetEditView($id, $module, $asMetadata=false, $tpl='',$tabindex='0')
851
+    function getEmailAddressWidgetEditView($id, $module, $asMetadata = false, $tpl = '', $tabindex = '0')
852 852
     {
853
-        if ( !($this->smarty instanceOf Sugar_Smarty ) )
853
+        if (!($this->smarty instanceOf Sugar_Smarty))
854 854
             $this->smarty = new Sugar_Smarty();
855 855
 
856 856
         global $app_strings, $dictionary, $beanList;
@@ -861,33 +861,33 @@  discard block
 block discarded – undo
861 861
         $passedModule = $module;
862 862
         $module = $this->getCorrectedModule($module);
863 863
         $saveModule = $module;
864
-        if(isset($_POST['is_converted']) && $_POST['is_converted']==true){
865
-            $id=$_POST['return_id'];
866
-            $module=$_POST['return_module'];
864
+        if (isset($_POST['is_converted']) && $_POST['is_converted'] == true) {
865
+            $id = $_POST['return_id'];
866
+            $module = $_POST['return_module'];
867 867
         }
868 868
         $prefillDataArr = array();
869
-        if(!empty($id)) {
869
+        if (!empty($id)) {
870 870
             $prefillDataArr = $this->getAddressesByGUID($id, $module);
871 871
             //When coming from convert leads, sometimes module is Contacts while the id is for a lead.
872 872
             if (empty($prefillDataArr) && $module == "Contacts")
873 873
                 $prefillDataArr = $this->getAddressesByGUID($id, "Leads");
874
-        } else if(isset($_REQUEST['full_form']) && !empty($_REQUEST['emailAddressWidget'])){
875
-            $widget_id = isset($_REQUEST[$module . '_email_widget_id']) ? $_REQUEST[$module . '_email_widget_id'] : '0';
874
+        } else if (isset($_REQUEST['full_form']) && !empty($_REQUEST['emailAddressWidget'])) {
875
+            $widget_id = isset($_REQUEST[$module.'_email_widget_id']) ? $_REQUEST[$module.'_email_widget_id'] : '0';
876 876
             $count = 0;
877
-            $key = $module . $widget_id . 'emailAddress'.$count;
878
-            while(isset($_REQUEST[$key])) {
877
+            $key = $module.$widget_id.'emailAddress'.$count;
878
+            while (isset($_REQUEST[$key])) {
879 879
                    $email = $_REQUEST[$key];
880
-                   $prefillDataArr[] =  array('email_address'=>$email,
880
+                   $prefillDataArr[] = array('email_address'=>$email,
881 881
                                              'primary_address'=>isset($_REQUEST['emailAddressPrimaryFlag']) && $_REQUEST['emailAddressPrimaryFlag'] == $key,
882 882
                                              'invalid_email'=>isset($_REQUEST['emailAddressInvalidFlag']) && in_array($key, $_REQUEST['emailAddressInvalidFlag']),
883 883
                                              'opt_out'=>isset($_REQUEST['emailAddressOptOutFlag']) && in_array($key, $_REQUEST['emailAddressOptOutFlag']),
884 884
                                              'reply_to_address'=>false
885 885
                                         );
886
-                   $key = $module . $widget_id . 'emailAddress' . ++$count;
886
+                   $key = $module.$widget_id.'emailAddress'.++$count;
887 887
             } //while
888 888
         }
889 889
 
890
-        if(!empty($prefillDataArr)) {
890
+        if (!empty($prefillDataArr)) {
891 891
             $json = new JSON(JSON_LOOSE_TYPE);
892 892
             $prefillData = $json->encode($prefillDataArr);
893 893
             $prefill = !empty($prefillDataArr) ? 'true' : 'false';
@@ -910,23 +910,23 @@  discard block
 block discarded – undo
910 910
         $form = $this->view;
911 911
 
912 912
         //determine if this should be a quickcreate form, or a quick create form under subpanels
913
-        if ($this->view == "QuickCreate"){
913
+        if ($this->view == "QuickCreate") {
914 914
             // Fixed #1120 - fixed email validation for: Accounts -> Contacts subpanel -> Select -> Create Contact -> Save.
915 915
             // If email is required it should highlight this field and show an error message.
916 916
             // It didnt because the the form was named form_DCSubpanelQuickCreate_Contacts instead of expected form_SubpanelQuickCreate_Contacts
917
-            if($this->object_name = 'EmailAddress' && $saveModule == 'Contacts') {
918
-                $form = 'form_'.$this->view .'_'.$module;
917
+            if ($this->object_name = 'EmailAddress' && $saveModule == 'Contacts') {
918
+                $form = 'form_'.$this->view.'_'.$module;
919 919
             } else {
920
-                $form = 'form_DC'.$this->view .'_'.$module;
920
+                $form = 'form_DC'.$this->view.'_'.$module;
921 921
             }
922
-            if(isset($_REQUEST['action']) && $_REQUEST['action']=='SubpanelCreates' ||  $_REQUEST['action']=='SubpanelEdits'){
923
-                $form = 'form_Subpanel'.$this->view .'_'.$module;
922
+            if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'SubpanelCreates' || $_REQUEST['action'] == 'SubpanelEdits') {
923
+                $form = 'form_Subpanel'.$this->view.'_'.$module;
924 924
             }
925 925
         }
926 926
 
927 927
         $this->smarty->assign('emailView', $form);
928 928
 
929
-        if($module == 'Users') {
929
+        if ($module == 'Users') {
930 930
             $this->smarty->assign('useReplyTo', true);
931 931
         } else {
932 932
             $this->smarty->assign('useOptOut', true);
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
         $newEmail = $this->smarty->fetch($template);
938 938
 
939 939
 
940
-        if($asMetadata) {
940
+        if ($asMetadata) {
941 941
             // used by Email 2.0
942 942
             $ret = array();
943 943
             $ret['prefillData'] = $prefillDataArr;
@@ -955,18 +955,18 @@  discard block
 block discarded – undo
955 955
      * @param object $focus Bean in focus
956 956
      * @return string HTML/JS for widget
957 957
      */
958
-    function getEmailAddressWidgetDetailView($focus, $tpl='')
958
+    function getEmailAddressWidgetDetailView($focus, $tpl = '')
959 959
     {
960
-        if ( !($this->smarty instanceOf Sugar_Smarty ) )
960
+        if (!($this->smarty instanceOf Sugar_Smarty))
961 961
             $this->smarty = new Sugar_Smarty();
962 962
 
963 963
         global $app_strings;
964 964
         global $current_user;
965 965
         $assign = array();
966
-        if(empty($focus->id))return '';
966
+        if (empty($focus->id))return '';
967 967
         $prefillData = $this->getAddressesByGUID($focus->id, $focus->module_dir);
968 968
 
969
-        foreach($prefillData as $addressItem) {
969
+        foreach ($prefillData as $addressItem) {
970 970
             $key = ($addressItem['primary_address'] == 1) ? 'primary' : "";
971 971
             $key = ($addressItem['reply_to_address'] == 1) ? 'reply_to' : $key;
972 972
             $key = ($addressItem['opt_out'] == 1) ? 'opt_out' : $key;
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
      */
993 993
     function getEmailAddressWidgetDuplicatesView($focus)
994 994
     {
995
-        if ( !($this->smarty instanceOf Sugar_Smarty ) )
995
+        if (!($this->smarty instanceOf Sugar_Smarty))
996 996
             $this->smarty = new Sugar_Smarty();
997 997
 
998 998
         $count = 0;
@@ -1002,49 +1002,49 @@  discard block
 block discarded – undo
1002 1002
         $invalid = array();
1003 1003
         $mod = isset($focus) ? $focus->module_dir : "";
1004 1004
 
1005
-        $widget_id = $_POST[$mod .'_email_widget_id'];
1006
-        $this->smarty->assign('email_widget_id',$widget_id);
1007
-        $this->smarty->assign('emailAddressWidget',$_POST['emailAddressWidget']);
1005
+        $widget_id = $_POST[$mod.'_email_widget_id'];
1006
+        $this->smarty->assign('email_widget_id', $widget_id);
1007
+        $this->smarty->assign('emailAddressWidget', $_POST['emailAddressWidget']);
1008 1008
 
1009
-        if(isset($_POST[$mod . $widget_id . 'emailAddressPrimaryFlag'])) {
1010
-           $primary = $_POST[$mod . $widget_id . 'emailAddressPrimaryFlag'];
1009
+        if (isset($_POST[$mod.$widget_id.'emailAddressPrimaryFlag'])) {
1010
+           $primary = $_POST[$mod.$widget_id.'emailAddressPrimaryFlag'];
1011 1011
         }
1012 1012
 
1013
-        while(isset($_POST[$mod . $widget_id . "emailAddress" . $count])) {
1014
-            $emails[] = $_POST[$mod . $widget_id . 'emailAddress' . $count];
1013
+        while (isset($_POST[$mod.$widget_id."emailAddress".$count])) {
1014
+            $emails[] = $_POST[$mod.$widget_id.'emailAddress'.$count];
1015 1015
             $count++;
1016 1016
         }
1017 1017
 
1018
-        if($count == 0) {
1018
+        if ($count == 0) {
1019 1019
            return "";
1020 1020
         }
1021 1021
 
1022
-        if(isset($_POST[$mod . $widget_id . 'emailAddressOptOutFlag'])) {
1023
-           foreach($_POST[$mod . $widget_id . 'emailAddressOptOutFlag'] as $v) {
1022
+        if (isset($_POST[$mod.$widget_id.'emailAddressOptOutFlag'])) {
1023
+           foreach ($_POST[$mod.$widget_id.'emailAddressOptOutFlag'] as $v) {
1024 1024
               $optOut[] = $v;
1025 1025
            }
1026 1026
         }
1027 1027
 
1028
-        if(isset($_POST[$mod . $widget_id . 'emailAddressInvalidFlag'])) {
1029
-           foreach($_POST[$mod . $widget_id . 'emailAddressInvalidFlag'] as $v) {
1028
+        if (isset($_POST[$mod.$widget_id.'emailAddressInvalidFlag'])) {
1029
+           foreach ($_POST[$mod.$widget_id.'emailAddressInvalidFlag'] as $v) {
1030 1030
               $invalid[] = $v;
1031 1031
            }
1032 1032
         }
1033 1033
 
1034
-        if(isset($_POST[$mod . $widget_id . 'emailAddressReplyToFlag'])) {
1035
-           foreach($_POST[$mod . $widget_id . 'emailAddressReplyToFlag'] as $v) {
1034
+        if (isset($_POST[$mod.$widget_id.'emailAddressReplyToFlag'])) {
1035
+           foreach ($_POST[$mod.$widget_id.'emailAddressReplyToFlag'] as $v) {
1036 1036
               $replyTo[] = $v;
1037 1037
            }
1038 1038
         }
1039 1039
 
1040
-        if(isset($_POST[$mod . $widget_id . 'emailAddressDeleteFlag'])) {
1041
-           foreach($_POST[$mod . $widget_id . 'emailAddressDeleteFlag'] as $v) {
1040
+        if (isset($_POST[$mod.$widget_id.'emailAddressDeleteFlag'])) {
1041
+           foreach ($_POST[$mod.$widget_id.'emailAddressDeleteFlag'] as $v) {
1042 1042
               $delete[] = $v;
1043 1043
            }
1044 1044
         }
1045 1045
 
1046
-        while(isset($_POST[$mod . $widget_id . "emailAddressVerifiedValue" . $count])) {
1047
-            $verified[] = $_POST[$mod . $widget_id . 'emailAddressVerifiedValue' . $count];
1046
+        while (isset($_POST[$mod.$widget_id."emailAddressVerifiedValue".$count])) {
1047
+            $verified[] = $_POST[$mod.$widget_id.'emailAddressVerifiedValue'.$count];
1048 1048
             $count++;
1049 1049
         }
1050 1050
 
@@ -1069,33 +1069,33 @@  discard block
 block discarded – undo
1069 1069
         $count = 0;
1070 1070
         $mod = isset($focus) ? $focus->module_dir : "";
1071 1071
 
1072
-        $widget_id = $_POST[$mod .'_email_widget_id'];
1073
-        $get .= '&' . $mod . '_email_widget_id='. $widget_id;
1072
+        $widget_id = $_POST[$mod.'_email_widget_id'];
1073
+        $get .= '&'.$mod.'_email_widget_id='.$widget_id;
1074 1074
         $get .= '&emailAddressWidget='.$_POST['emailAddressWidget'];
1075 1075
 
1076
-        while(isset($_REQUEST[$mod . $widget_id . 'emailAddress' . $count])) {
1077
-              $get .= "&" . $mod . $widget_id . "emailAddress" . $count . "=" . urlencode($_REQUEST[$mod . $widget_id . 'emailAddress' . $count]);
1076
+        while (isset($_REQUEST[$mod.$widget_id.'emailAddress'.$count])) {
1077
+              $get .= "&".$mod.$widget_id."emailAddress".$count."=".urlencode($_REQUEST[$mod.$widget_id.'emailAddress'.$count]);
1078 1078
               $count++;
1079 1079
         } //while
1080 1080
 
1081
-        while(isset($_REQUEST[$mod . $widget_id . 'emailAddressVerifiedValue' . $count])) {
1082
-              $get .= "&" . $mod . $widget_id . "emailAddressVerifiedValue" . $count . "=" . urlencode($_REQUEST[$mod . $widget_id . 'emailAddressVerifiedValue' . $count]);
1081
+        while (isset($_REQUEST[$mod.$widget_id.'emailAddressVerifiedValue'.$count])) {
1082
+              $get .= "&".$mod.$widget_id."emailAddressVerifiedValue".$count."=".urlencode($_REQUEST[$mod.$widget_id.'emailAddressVerifiedValue'.$count]);
1083 1083
               $count++;
1084 1084
         } //while
1085 1085
 
1086 1086
         $options = array('emailAddressPrimaryFlag', 'emailAddressOptOutFlag', 'emailAddressInvalidFlag', 'emailAddressDeleteFlag', 'emailAddressReplyToFlag');
1087 1087
 
1088
-        foreach($options as $option) {
1088
+        foreach ($options as $option) {
1089 1089
             $count = 0;
1090 1090
             $optionIdentifier = $mod.$widget_id.$option;
1091
-            if(isset($_REQUEST[$optionIdentifier])) {
1092
-               if(is_array($_REQUEST[$optionIdentifier])) {
1093
-                   foreach($_REQUEST[$optionIdentifier] as $optOut) {
1094
-                      $get .= "&" . $optionIdentifier . "[" . $count . "]=" . $optOut;
1091
+            if (isset($_REQUEST[$optionIdentifier])) {
1092
+               if (is_array($_REQUEST[$optionIdentifier])) {
1093
+                   foreach ($_REQUEST[$optionIdentifier] as $optOut) {
1094
+                      $get .= "&".$optionIdentifier."[".$count."]=".$optOut;
1095 1095
                       $count++;
1096 1096
                    } //foreach
1097 1097
                } else {
1098
-                   $get .= "&" . $optionIdentifier . "=" . $_REQUEST[$optionIdentifier];
1098
+                   $get .= "&".$optionIdentifier."=".$_REQUEST[$optionIdentifier];
1099 1099
                }
1100 1100
             } //if
1101 1101
         } //foreach
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
  * @return string The value for the bean_module column in the email_addr_bean_rel table
1114 1114
  */
1115 1115
     function getCorrectedModule(&$module) {
1116
-        return ($module == "Employees")? "Users" : $module;
1116
+        return ($module == "Employees") ? "Users" : $module;
1117 1117
     }
1118 1118
 
1119 1119
     public function stash($parentBeanId, $moduleName)
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
         $ids = array();
1124 1124
         while ($row = $this->db->fetchByAssoc($result, false))
1125 1125
         {
1126
-            $ids[] =$this->db->quote($row['email_address_id']); // avoid 2nd order SQL Injection
1126
+            $ids[] = $this->db->quote($row['email_address_id']); // avoid 2nd order SQL Injection
1127 1127
         }
1128 1128
         if (!empty($ids))
1129 1129
         {
@@ -1147,15 +1147,15 @@  discard block
 block discarded – undo
1147 1147
  * @param string $view DetailView or EditView
1148 1148
  * @return string
1149 1149
  */
1150
-function getEmailAddressWidget($focus, $field, $value, $view, $tabindex='0') {
1150
+function getEmailAddressWidget($focus, $field, $value, $view, $tabindex = '0') {
1151 1151
     $sea = new SugarEmailAddress();
1152 1152
     $sea->setView($view);
1153 1153
 
1154
-        if($view == 'EditView' || $view == 'QuickCreate' || $view == 'ConvertLead') {
1154
+        if ($view == 'EditView' || $view == 'QuickCreate' || $view == 'ConvertLead') {
1155 1155
             $module = $focus->module_dir;
1156 1156
             if ($view == 'ConvertLead' && $module == "Contacts")  $module = "Leads";
1157 1157
 
1158
-            return $sea->getEmailAddressWidgetEditView($focus->id, $module, false,'',$tabindex);
1158
+            return $sea->getEmailAddressWidgetEditView($focus->id, $module, false, '', $tabindex);
1159 1159
         }
1160 1160
 
1161 1161
     return $sea->getEmailAddressWidgetDetailView($focus);
Please login to merge, or discard this patch.
include/utils/sugar_file_utils.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
     $temp = tempnam($dir, 'temp');
187 187
 
188 188
     if (!($f = @fopen($temp, $mode))) {
189
-        $temp = $dir . DIRECTORY_SEPARATOR . uniqid('temp');
189
+        $temp = $dir.DIRECTORY_SEPARATOR.uniqid('temp');
190 190
         if (!($f = @fopen($temp, $mode))) {
191 191
             trigger_error("sugar_file_put_contents_atomic() : error writing temporary file '$temp'", E_USER_WARNING);
192 192
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
     }
394 394
     if (!is_windows()) {
395 395
         $conf_inst = SugarConfig::getInstance();
396
-        $mode = $conf_inst->get('default_permissions.' . $key, $mode);
396
+        $mode = $conf_inst->get('default_permissions.'.$key, $mode);
397 397
     }
398 398
 
399 399
     return $mode;
Please login to merge, or discard this patch.