Completed
Push — developer ( 9c89f4...5b19f1 )
by Błażej
155:55 queued 109:20
created
api/mobile_services/historycall.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * All Rights Reserved.
10 10
  *************************************************************************************************************************************/
11 11
 class HistoryCall{
12
-    public $restler;
12
+	public $restler;
13 13
 	public $userID;
14 14
 	public $debug = true;
15 15
 	public $permittedActions = array('addCallLogs');
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 		1 => 'Outgoing received',
25 25
 	);
26 26
 	
27
-    public function post($type = '', $authorization = '', $data = ''){
27
+	public function post($type = '', $authorization = '', $data = ''){
28 28
 		$authorization = json_decode($authorization);
29 29
 		$adb = PearDatabase::getInstance(); $log = vglobal('log');
30 30
 		$log->info("Start HistoryCall metod");
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 			$dane = print_r( array( $type,$authorization, $data, $resultData ) ,true);
41 41
 			file_put_contents($file,'-----> '.date("Y-m-d H:i:s").' <-----'.PHP_EOL.$dane.PHP_EOL,FILE_APPEND | LOCK_EX);
42 42
 		}
43
-        return $resultData;
44
-    }
43
+		return $resultData;
44
+	}
45 45
 	
46 46
 	public function addCallLogs($data){
47 47
 		$adb = PearDatabase::getInstance(); $log = vglobal('log');
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * The Initial Developer of the Original Code is YetiForce. Portions created by YetiForce are Copyright (C) www.yetiforce.com. 
9 9
  * All Rights Reserved.
10 10
  *************************************************************************************************************************************/
11
-class HistoryCall{
11
+class HistoryCall {
12 12
     public $restler;
13 13
 	public $userID;
14 14
 	public $debug = true;
@@ -24,29 +24,29 @@  discard block
 block discarded – undo
24 24
 		1 => 'Outgoing received',
25 25
 	);
26 26
 	
27
-    public function post($type = '', $authorization = '', $data = ''){
27
+    public function post($type = '', $authorization = '', $data = '') {
28 28
 		$authorization = json_decode($authorization);
29 29
 		$adb = PearDatabase::getInstance(); $log = vglobal('log');
30 30
 		$log->info("Start HistoryCall metod");
31
-		if( $authorization->phoneKey == '' || !$this->checkPermissions($authorization) ){
32
-			$resultData = Array('status' => 0,'message' =>  'No permission to: HistoryCall');
33
-		}elseif( in_array($type,$this->permittedActions) ){
31
+		if ($authorization->phoneKey == '' || !$this->checkPermissions($authorization)) {
32
+			$resultData = Array('status' => 0, 'message' =>  'No permission to: HistoryCall');
33
+		}elseif (in_array($type, $this->permittedActions)) {
34 34
 			$resultData = $this->$type($data);
35
-		}else{
36
-			$resultData = Array('status' => 0,'message' =>  'Method not found: '.$type);
35
+		} else {
36
+			$resultData = Array('status' => 0, 'message' =>  'Method not found: ' . $type);
37 37
 		}
38
-		if($this->debug){
38
+		if ($this->debug) {
39 39
 			$file = 'api/mobile_services_HistoryCall_logs.txt';
40
-			$dane = print_r( array( $type,$authorization, $data, $resultData ) ,true);
41
-			file_put_contents($file,'-----> '.date("Y-m-d H:i:s").' <-----'.PHP_EOL.$dane.PHP_EOL,FILE_APPEND | LOCK_EX);
40
+			$dane = print_r(array($type, $authorization, $data, $resultData), true);
41
+			file_put_contents($file, '-----> ' . date("Y-m-d H:i:s") . ' <-----' . PHP_EOL . $dane . PHP_EOL, FILE_APPEND | LOCK_EX);
42 42
 		}
43 43
         return $resultData;
44 44
     }
45 45
 	
46
-	public function addCallLogs($data){
46
+	public function addCallLogs($data) {
47 47
 		$adb = PearDatabase::getInstance(); $log = vglobal('log');
48 48
 		include_once 'include/main/WebUI.php';
49
-		$log->info("Start HistoryCall::addCallLogs | user id: ".$this->userID);
49
+		$log->info("Start HistoryCall::addCallLogs | user id: " . $this->userID);
50 50
 		$resultData = array('status' => 2);
51 51
 		$user = new Users();
52 52
 		$count = 0;
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 			$destination = $this->findPhoneNumber($to_number);
60 60
 			
61 61
 			$CallHistory = CRMEntity::getInstance('CallHistory');
62
-			$CallHistory->column_fields['assigned_user_id'] =  $this->userID;
63
-			$CallHistory->column_fields['callhistorytype'] = $this->getType( $call->type , $call->duration);
62
+			$CallHistory->column_fields['assigned_user_id'] = $this->userID;
63
+			$CallHistory->column_fields['callhistorytype'] = $this->getType($call->type, $call->duration);
64 64
 			$CallHistory->column_fields['country'] = $call->country_iso;
65 65
 			$CallHistory->column_fields['to_number'] = $to_number;
66 66
 			$CallHistory->column_fields['from_number'] = $from_number;
@@ -73,70 +73,70 @@  discard block
 block discarded – undo
73 73
 			$CallHistory->column_fields['ipAddress'] = $data->ipAddress;
74 74
 			$CallHistory->column_fields['simSerial'] = $data->simSerial;
75 75
 			$CallHistory->column_fields['subscriberId'] = $data->subscriberId;
76
-			if($destination)
76
+			if ($destination)
77 77
 				$CallHistory->column_fields['destination'] = $destination;
78 78
 			$CallHistory->save('CallHistory');
79 79
 			$count++;
80 80
 		}
81 81
 		$resultData = array('status' => 1, 'count' => $count);
82
-		$log->info("End HistoryCall::addCallLogs | return: ".print_r( $resultData,true));
82
+		$log->info("End HistoryCall::addCallLogs | return: " . print_r($resultData, true));
83 83
 		return $resultData;
84 84
 	}
85 85
 	
86
-	public function checkPermissions($authorization){
86
+	public function checkPermissions($authorization) {
87 87
 		$adb = PearDatabase::getInstance(); $log = vglobal('log');
88
-		$log->info("Start HistoryCall::checkPermissions | ".print_r( $authorization,true));
88
+		$log->info("Start HistoryCall::checkPermissions | " . print_r($authorization, true));
89 89
 		$return = false;	
90
-		$result = $adb->pquery("SELECT yetiforce_mobile_keys.user FROM yetiforce_mobile_keys INNER JOIN vtiger_users ON vtiger_users.id = yetiforce_mobile_keys.user WHERE service = ? && `key` = ? && vtiger_users.user_name = ?",array('historycall', $authorization->phoneKey, $authorization->userName),true);
91
-		if($adb->num_rows($result) > 0 ){
90
+		$result = $adb->pquery("SELECT yetiforce_mobile_keys.user FROM yetiforce_mobile_keys INNER JOIN vtiger_users ON vtiger_users.id = yetiforce_mobile_keys.user WHERE service = ? && `key` = ? && vtiger_users.user_name = ?", array('historycall', $authorization->phoneKey, $authorization->userName), true);
91
+		if ($adb->num_rows($result) > 0) {
92 92
 			$this->userID = $adb->query_result_raw($result, 0, 'user');
93 93
 			$return = true;	
94 94
 		}
95
-		$log->info("End HistoryCall::checkPermissions | return: ".$return);
95
+		$log->info("End HistoryCall::checkPermissions | return: " . $return);
96 96
 		return $return;
97 97
 	}
98 98
 	
99
-	public function findPhoneNumber($number){
99
+	public function findPhoneNumber($number) {
100 100
 		$adb = PearDatabase::getInstance(); $log = vglobal('log');
101 101
 		$crmid = false;
102 102
 		$modulesInstance = array();
103 103
 		$sql = "SELECT columnname,tablename,vtiger_tab.name FROM vtiger_field INNER JOIN vtiger_tab ON vtiger_tab.tabid = vtiger_field.tabid WHERE vtiger_tab.presence = 0 && uitype = '11' && vtiger_tab.name IN ('Contacts','Accounts','Leads','OSSEmployees','Vendors')";
104
-		$result = $adb->query($sql,true);
105
-		for($i = 0; $i < $adb->num_rows($result); $i++){
104
+		$result = $adb->query($sql, true);
105
+		for ($i = 0; $i < $adb->num_rows($result); $i++) {
106 106
 			$module = $adb->query_result_raw($result, $i, 'name');
107 107
 			$columnname = $adb->query_result_raw($result, $i, 'columnname');
108 108
 			$tablename = $adb->query_result_raw($result, $i, 'tablename');
109
-			if(!$modulesInstance[$module]){
110
-				include_once 'modules/'.$module.'/'.$module.'.php';
109
+			if (!$modulesInstance[$module]) {
110
+				include_once 'modules/' . $module . '/' . $module . '.php';
111 111
 				$moduleInstance = CRMEntity::getInstance($module);
112 112
 				$modulesInstance[$module] = $moduleInstance->tab_name_index;
113 113
 			}
114 114
 			$table_index = $modulesInstance[$module][$tablename];
115
-			if( strpos($number, '+') !== false )
115
+			if (strpos($number, '+') !== false)
116 116
 				$number = substr($number, 3);
117
-			$number = preg_replace('/\D/', '',$number);
117
+			$number = preg_replace('/\D/', '', $number);
118 118
 			$sqlNumber = '';
119 119
 			foreach (str_split($number) as $num) {
120
-				$sqlNumber .= '[^0-9]*'.$num;
120
+				$sqlNumber .= '[^0-9]*' . $num;
121 121
 			}
122 122
 			$sql = "SELECT crmid FROM $tablename INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $tablename.$table_index WHERE vtiger_crmentity.deleted = 0 && $columnname RLIKE '$sqlNumber';";
123
-			$resultData = $adb->query($sql,true);
124
-			if($adb->num_rows($resultData) > 0 ){
123
+			$resultData = $adb->query($sql, true);
124
+			if ($adb->num_rows($resultData) > 0) {
125 125
 				$crmid = $adb->query_result_raw($resultData, 0, 'crmid');
126 126
 				break;
127 127
 			}
128 128
 		}
129 129
 		return $crmid;
130 130
 	}
131
-	public function getType($type, $duration){
132
-		if($type == 2){
131
+	public function getType($type, $duration) {
132
+		if ($type == 2) {
133 133
 			return $duration > 0 ? $this->outgoingStatus[1] : $this->outgoingStatus[0];
134
-		}else{
135
-			return !$this->types[$type]? $type : $this->types[$type];
134
+		} else {
135
+			return !$this->types[$type] ? $type : $this->types[$type];
136 136
 		}
137 137
 	}
138 138
 	
139
-	public function getDate($timestamp){
139
+	public function getDate($timestamp) {
140 140
 		$timestamp = substr($timestamp, 0, 10);
141 141
 		return date("Y-m-d H:i:s", $timestamp);
142 142
 	}
Please login to merge, or discard this patch.