@@ -8,7 +8,7 @@ discard block |
||
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,31 +24,31 @@ discard block |
||
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(); |
30 | 30 | $log = vglobal('log'); |
31 | 31 | $log->info("Start HistoryCall metod"); |
32 | - if( $authorization->phoneKey == '' || !$this->checkPermissions($authorization) ){ |
|
33 | - $resultData = Array('status' => 0,'message' => 'No permission to: HistoryCall'); |
|
34 | - }elseif( in_array($type,$this->permittedActions) ){ |
|
32 | + if ($authorization->phoneKey == '' || !$this->checkPermissions($authorization)) { |
|
33 | + $resultData = Array('status' => 0, 'message' => 'No permission to: HistoryCall'); |
|
34 | + }elseif (in_array($type, $this->permittedActions)) { |
|
35 | 35 | $resultData = $this->$type($data); |
36 | - }else{ |
|
37 | - $resultData = Array('status' => 0,'message' => 'Method not found: '.$type); |
|
36 | + } else { |
|
37 | + $resultData = Array('status' => 0, 'message' => 'Method not found: ' . $type); |
|
38 | 38 | } |
39 | - if($this->debug){ |
|
39 | + if ($this->debug) { |
|
40 | 40 | $file = 'api/mobile_services_HistoryCall_logs.txt'; |
41 | - $dane = print_r( array( $type,$authorization, $data, $resultData ) ,true); |
|
42 | - file_put_contents($file,'-----> '.date("Y-m-d H:i:s").' <-----'.PHP_EOL.$dane.PHP_EOL,FILE_APPEND | LOCK_EX); |
|
41 | + $dane = print_r(array($type, $authorization, $data, $resultData), true); |
|
42 | + file_put_contents($file, '-----> ' . date("Y-m-d H:i:s") . ' <-----' . PHP_EOL . $dane . PHP_EOL, FILE_APPEND | LOCK_EX); |
|
43 | 43 | } |
44 | 44 | return $resultData; |
45 | 45 | } |
46 | 46 | |
47 | - public function addCallLogs($data){ |
|
47 | + public function addCallLogs($data) { |
|
48 | 48 | $adb = PearDatabase::getInstance(); |
49 | 49 | $log = vglobal('log'); |
50 | 50 | include_once 'include/main/WebUI.php'; |
51 | - $log->info("Start HistoryCall::addCallLogs | user id: ".$this->userID); |
|
51 | + $log->info("Start HistoryCall::addCallLogs | user id: " . $this->userID); |
|
52 | 52 | $resultData = array('status' => 2); |
53 | 53 | $user = new Users(); |
54 | 54 | $count = 0; |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | $destination = $this->findPhoneNumber($to_number); |
62 | 62 | |
63 | 63 | $CallHistory = CRMEntity::getInstance('CallHistory'); |
64 | - $CallHistory->column_fields['assigned_user_id'] = $this->userID; |
|
65 | - $CallHistory->column_fields['callhistorytype'] = $this->getType( $call->type , $call->duration); |
|
64 | + $CallHistory->column_fields['assigned_user_id'] = $this->userID; |
|
65 | + $CallHistory->column_fields['callhistorytype'] = $this->getType($call->type, $call->duration); |
|
66 | 66 | $CallHistory->column_fields['country'] = $call->country_iso; |
67 | 67 | $CallHistory->column_fields['to_number'] = $to_number; |
68 | 68 | $CallHistory->column_fields['from_number'] = $from_number; |
@@ -75,73 +75,73 @@ discard block |
||
75 | 75 | $CallHistory->column_fields['ipAddress'] = $data->ipAddress; |
76 | 76 | $CallHistory->column_fields['simSerial'] = $data->simSerial; |
77 | 77 | $CallHistory->column_fields['subscriberId'] = $data->subscriberId; |
78 | - if($destination) |
|
78 | + if ($destination) |
|
79 | 79 | $CallHistory->column_fields['destination'] = $destination; |
80 | 80 | $CallHistory->save('CallHistory'); |
81 | 81 | $count++; |
82 | 82 | } |
83 | 83 | $resultData = array('status' => 1, 'count' => $count); |
84 | - $log->info("End HistoryCall::addCallLogs | return: ".print_r( $resultData,true)); |
|
84 | + $log->info("End HistoryCall::addCallLogs | return: " . print_r($resultData, true)); |
|
85 | 85 | return $resultData; |
86 | 86 | } |
87 | 87 | |
88 | - public function checkPermissions($authorization){ |
|
88 | + public function checkPermissions($authorization) { |
|
89 | 89 | $adb = PearDatabase::getInstance(); |
90 | 90 | $log = vglobal('log'); |
91 | - $log->info("Start HistoryCall::checkPermissions | ".print_r( $authorization,true)); |
|
91 | + $log->info("Start HistoryCall::checkPermissions | " . print_r($authorization, true)); |
|
92 | 92 | $return = false; |
93 | - $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); |
|
94 | - if($adb->num_rows($result) > 0 ){ |
|
93 | + $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); |
|
94 | + if ($adb->num_rows($result) > 0) { |
|
95 | 95 | $this->userID = $adb->query_result_raw($result, 0, 'user'); |
96 | 96 | $return = true; |
97 | 97 | } |
98 | - $log->info("End HistoryCall::checkPermissions | return: ".$return); |
|
98 | + $log->info("End HistoryCall::checkPermissions | return: " . $return); |
|
99 | 99 | return $return; |
100 | 100 | } |
101 | 101 | |
102 | - public function findPhoneNumber($number){ |
|
102 | + public function findPhoneNumber($number) { |
|
103 | 103 | $adb = PearDatabase::getInstance(); |
104 | 104 | $log = vglobal('log'); |
105 | 105 | $crmid = false; |
106 | 106 | $modulesInstance = array(); |
107 | 107 | $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')"; |
108 | - $result = $adb->query($sql,true); |
|
108 | + $result = $adb->query($sql, true); |
|
109 | 109 | $rows = $adb->num_rows($result); |
110 | - for($i = 0; $i < $rows; $i++){ |
|
110 | + for ($i = 0; $i < $rows; $i++) { |
|
111 | 111 | $module = $adb->query_result_raw($result, $i, 'name'); |
112 | 112 | $columnname = $adb->query_result_raw($result, $i, 'columnname'); |
113 | 113 | $tablename = $adb->query_result_raw($result, $i, 'tablename'); |
114 | - if(!$modulesInstance[$module]){ |
|
115 | - include_once 'modules/'.$module.'/'.$module.'.php'; |
|
114 | + if (!$modulesInstance[$module]) { |
|
115 | + include_once 'modules/' . $module . '/' . $module . '.php'; |
|
116 | 116 | $moduleInstance = CRMEntity::getInstance($module); |
117 | 117 | $modulesInstance[$module] = $moduleInstance->tab_name_index; |
118 | 118 | } |
119 | 119 | $table_index = $modulesInstance[$module][$tablename]; |
120 | - if( strpos($number, '+') !== false ) |
|
120 | + if (strpos($number, '+') !== false) |
|
121 | 121 | $number = substr($number, 3); |
122 | - $number = preg_replace('/\D/', '',$number); |
|
122 | + $number = preg_replace('/\D/', '', $number); |
|
123 | 123 | $sqlNumber = ''; |
124 | 124 | foreach (str_split($number) as $num) { |
125 | - $sqlNumber .= '[^0-9]*'.$num; |
|
125 | + $sqlNumber .= '[^0-9]*' . $num; |
|
126 | 126 | } |
127 | 127 | $sql = "SELECT crmid FROM $tablename INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $tablename.$table_index WHERE vtiger_crmentity.deleted = 0 && $columnname RLIKE '$sqlNumber';"; |
128 | - $resultData = $adb->query($sql,true); |
|
129 | - if($adb->num_rows($resultData) > 0 ){ |
|
128 | + $resultData = $adb->query($sql, true); |
|
129 | + if ($adb->num_rows($resultData) > 0) { |
|
130 | 130 | $crmid = $adb->query_result_raw($resultData, 0, 'crmid'); |
131 | 131 | break; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | return $crmid; |
135 | 135 | } |
136 | - public function getType($type, $duration){ |
|
137 | - if($type == 2){ |
|
136 | + public function getType($type, $duration) { |
|
137 | + if ($type == 2) { |
|
138 | 138 | return $duration > 0 ? $this->outgoingStatus[1] : $this->outgoingStatus[0]; |
139 | - }else{ |
|
140 | - return !$this->types[$type]? $type : $this->types[$type]; |
|
139 | + } else { |
|
140 | + return !$this->types[$type] ? $type : $this->types[$type]; |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - public function getDate($timestamp){ |
|
144 | + public function getDate($timestamp) { |
|
145 | 145 | $timestamp = substr($timestamp, 0, 10); |
146 | 146 | return date("Y-m-d H:i:s", $timestamp); |
147 | 147 | } |