@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | ASTPP 3.0 |
33 | 33 | Voicemail data get |
34 | 34 | ******/ |
35 | - function get_sipdevices_list($flag, $accountid = "",$entitytype='',$start = "", $limit = "") { |
|
35 | + function get_sipdevices_list($flag, $accountid = "", $entitytype = '', $start = "", $limit = "") { |
|
36 | 36 | if ($accountid != "") { |
37 | 37 | $where = array("accountid" => $accountid); |
38 | 38 | } |
39 | 39 | $this->db_model->build_search('fssipdevices_list_search'); |
40 | - $instant_search=$this->session->userdata('left_panel_search_'.$entitytype.'_sipdevices'); |
|
41 | - if(!empty($instant_search)){ |
|
42 | - $like_str="(username like '%$instant_search%' OR creation_date like '%$instant_search%' OR last_modified_date like '%$instant_search%')"; |
|
40 | + $instant_search = $this->session->userdata('left_panel_search_'.$entitytype.'_sipdevices'); |
|
41 | + if ( ! empty($instant_search)) { |
|
42 | + $like_str = "(username like '%$instant_search%' OR creation_date like '%$instant_search%' OR last_modified_date like '%$instant_search%')"; |
|
43 | 43 | $this->db->where($like_str); |
44 | 44 | } |
45 | 45 | $query = array(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $add_array = $deviceinfo->result_array(); |
50 | 50 | foreach ($add_array as $key => $value) { |
51 | 51 | $vars = json_decode($value['dir_vars']); |
52 | - $vars_new = json_decode($value['dir_params'],true); |
|
52 | + $vars_new = json_decode($value['dir_params'], true); |
|
53 | 53 | $passowrds = json_decode($value['dir_params']); |
54 | 54 | $query[] = array('id' => $value['id'], |
55 | 55 | 'username' => $value['username'], |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | $where = array('id' => $add_array['accountcode']); |
89 | 89 | $query = $this->db_model->getSelect("*", "accounts", $where); |
90 | 90 | $query = $query->result_array(); |
91 | - $account_data=$query[0]; |
|
91 | + $account_data = $query[0]; |
|
92 | 92 | |
93 | 93 | $log_type = $this->session->userdata("logintype"); |
94 | 94 | |
95 | - $reseller_id = $log_type==1 ? $account_data['reseller_id']:0; |
|
95 | + $reseller_id = $log_type == 1 ? $account_data['reseller_id'] : 0; |
|
96 | 96 | |
97 | - $sip_profile_id = isset($add_array['sip_profile_id'])?$add_array['sip_profile_id']:$this->common->get_field_name('id','sip_profiles',array('name'=>'default')); |
|
97 | + $sip_profile_id = isset($add_array['sip_profile_id']) ? $add_array['sip_profile_id'] : $this->common->get_field_name('id', 'sip_profiles', array('name'=>'default')); |
|
98 | 98 | |
99 | 99 | $parms_array = array('password' => $add_array['fs_password'], |
100 | 100 | 'vm-enabled' => $add_array['voicemail_enabled'], |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | 'vm-email-all-messages' => $add_array['vm_send_all_message'] |
106 | 106 | ); |
107 | 107 | |
108 | - $add_array['status'] = isset($add_array['status'])?$add_array['status']:"0"; |
|
108 | + $add_array['status'] = isset($add_array['status']) ? $add_array['status'] : "0"; |
|
109 | 109 | $parms_array_vars = array('effective_caller_id_name' => $add_array['effective_caller_id_name'], |
110 | 110 | 'effective_caller_id_number' => $add_array['effective_caller_id_number'], |
111 | 111 | 'user_context' => 'default'); |
@@ -128,16 +128,16 @@ discard block |
||
128 | 128 | ASTPP 3.0 |
129 | 129 | Email broadcast when Sip Device create |
130 | 130 | ******/ |
131 | - $mail = (isset($add_array['voicemail_mail_to']) && $add_array['voicemail_mail_to'] != "")?$add_array['voicemail_mail_to']:$account_data['email']; |
|
131 | + $mail = (isset($add_array['voicemail_mail_to']) && $add_array['voicemail_mail_to'] != "") ? $add_array['voicemail_mail_to'] : $account_data['email']; |
|
132 | 132 | |
133 | - $add_array['id']=$add_array['accountcode']; |
|
134 | - $add_array['reseller_id']=$account_data['reseller_id']; |
|
135 | - $add_array['email']=$mail; |
|
136 | - $add_array['first_name']=$account_data['first_name']; |
|
137 | - $add_array['last_name']=$account_data['last_name']; |
|
138 | - $add_array['number']=$add_array['fs_username']; |
|
133 | + $add_array['id'] = $add_array['accountcode']; |
|
134 | + $add_array['reseller_id'] = $account_data['reseller_id']; |
|
135 | + $add_array['email'] = $mail; |
|
136 | + $add_array['first_name'] = $account_data['first_name']; |
|
137 | + $add_array['last_name'] = $account_data['last_name']; |
|
138 | + $add_array['number'] = $add_array['fs_username']; |
|
139 | 139 | //$add_array['password']=$this->common->decode($add_array['fs_password']); |
140 | - $add_array['password']=$add_array['fs_password']; |
|
140 | + $add_array['password'] = $add_array['fs_password']; |
|
141 | 141 | //echo "<pre>"; print_r($add_array); exit; |
142 | 142 | $this->common->mail_to_users('add_sip_device', $add_array); |
143 | 143 | /****************************/ |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | $parms_array_vars = array('effective_caller_id_name' => $add_array['effective_caller_id_name'], |
164 | 164 | 'effective_caller_id_number' => $add_array['effective_caller_id_number'],); |
165 | 165 | $log_type = $this->session->userdata("logintype"); |
166 | - if($log_type == 0 || $log_type == 3 || $log_type == 1){ |
|
167 | - $add_array['sip_profile_id']=$this->common->get_field_name('id','sip_profiles',array('name'=>'default')); |
|
166 | + if ($log_type == 0 || $log_type == 3 || $log_type == 1) { |
|
167 | + $add_array['sip_profile_id'] = $this->common->get_field_name('id', 'sip_profiles', array('name'=>'default')); |
|
168 | 168 | } |
169 | - $add_array['status'] = isset($add_array['status'])?$add_array['status']:"0"; |
|
169 | + $add_array['status'] = isset($add_array['status']) ? $add_array['status'] : "0"; |
|
170 | 170 | /* |
171 | 171 | ASTPP 3.0 edit modified date |
172 | 172 | */ |
173 | - $new_array = array('last_modified_date'=>gmdate('Y-m-d H:i:s'),'username' => $add_array['fs_username'], 'accountid' => $add_array['accountcode'],'status' => $add_array['status'], |
|
173 | + $new_array = array('last_modified_date'=>gmdate('Y-m-d H:i:s'), 'username' => $add_array['fs_username'], 'accountid' => $add_array['accountcode'], 'status' => $add_array['status'], |
|
174 | 174 | 'dir_params' => json_encode($parms_array), |
175 | 175 | 'dir_vars' => json_encode($parms_array_vars), 'sip_profile_id' => $add_array['sip_profile_id']); |
176 | 176 | /*******************************************/ |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | $add_array = $deviceinfo->result_array(); |
192 | 192 | foreach ($add_array as $key => $value) { |
193 | 193 | $vars = json_decode($value['dir_vars']); |
194 | - $vars_new = json_decode($value['dir_params'],true); |
|
194 | + $vars_new = json_decode($value['dir_params'], true); |
|
195 | 195 | $passowrds = json_decode($value['dir_params']); |
196 | - $query = array('id' => $value['id'],'fs_username' => $value['username'], |
|
196 | + $query = array('id' => $value['id'], 'fs_username' => $value['username'], |
|
197 | 197 | 'accountcode' => $value['accountid'], |
198 | 198 | 'status' => $value['status'], |
199 | 199 | 'sip_profile_id' => $value['sip_profile_id'], |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | $deviceinfo = array(); |
224 | 224 | $this->db_model->build_search('fssipdevices_list_search'); |
225 | 225 | $accountinfo = $this->session->userdata("accountinfo"); |
226 | - $reseller_id=$accountinfo['type']==1 ? $accountinfo['id'] : 0; |
|
226 | + $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0; |
|
227 | 227 | $query = array(); |
228 | 228 | $logintype = $this->session->userdata("logintype"); |
229 | 229 | |
230 | - $where['reseller_id']=$reseller_id; |
|
230 | + $where['reseller_id'] = $reseller_id; |
|
231 | 231 | |
232 | 232 | if ($flag) { |
233 | 233 | $deviceinfo = $this->db_model->select("*", "sip_devices", $where, "id", "ASC", $limit, $start); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $add_array = $deviceinfo->result_array(); |
236 | 236 | foreach ($add_array as $key => $value) { |
237 | 237 | $vars = json_decode($value['dir_vars']); |
238 | - $vars_new = json_decode($value['dir_params'],true); |
|
238 | + $vars_new = json_decode($value['dir_params'], true); |
|
239 | 239 | $passowrds = json_decode($value['dir_params']); |
240 | 240 | /* |
241 | 241 | ASTPP 3.0 |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | /* |
310 | 310 | ASTPP 3.0 ADD creation date |
311 | 311 | */ |
312 | - $data['creation_date']=gmdate('Y-m-d H:i:s'); |
|
312 | + $data['creation_date'] = gmdate('Y-m-d H:i:s'); |
|
313 | 313 | /***********************************/ |
314 | 314 | unset($data['action']); |
315 | 315 | $this->db->insert('freeswich_servers', $data); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | /* |
322 | 322 | ASTPP 3.0 edit modified date add |
323 | 323 | */ |
324 | - $data['last_modified_date']=gmdate('Y-m-d H:i:s'); |
|
324 | + $data['last_modified_date'] = gmdate('Y-m-d H:i:s'); |
|
325 | 325 | /***********************************************/ |
326 | 326 | $this->db->where('id', $id); |
327 | 327 | $this->db->update('freeswich_servers', $data); |
@@ -334,21 +334,21 @@ discard block |
||
334 | 334 | return true; |
335 | 335 | } |
336 | 336 | |
337 | - function reload_freeswitch($command,$server_host="") { |
|
338 | - $response=''; |
|
337 | + function reload_freeswitch($command, $server_host = "") { |
|
338 | + $response = ''; |
|
339 | 339 | $query = $this->db_model->getSelect("*", "freeswich_servers", ""); |
340 | 340 | $fs_data = $query->result_array(); |
341 | 341 | foreach ($fs_data as $fs_key => $fs_value) { |
342 | 342 | $fp = $this->freeswitch_lib->event_socket_create($fs_value["freeswitch_host"], $fs_value["freeswitch_port"], $fs_value["freeswitch_password"]); |
343 | 343 | if ($fp) { |
344 | - $response.= $this->freeswitch_lib->event_socket_request($fp, $command); |
|
344 | + $response .= $this->freeswitch_lib->event_socket_request($fp, $command); |
|
345 | 345 | fclose($fp); |
346 | 346 | } |
347 | 347 | } |
348 | 348 | return $response; |
349 | 349 | } |
350 | 350 | function reload_live_freeswitch($command) { |
351 | - $response=''; |
|
351 | + $response = ''; |
|
352 | 352 | $query = $this->db_model->getSelect("*", "freeswich_servers", ""); |
353 | 353 | $fs_data = $query->result_array(); |
354 | 354 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | fclose($fp); |
360 | 360 | } |
361 | 361 | } |
362 | - $response = str_replace("0 total.","",$response); |
|
362 | + $response = str_replace("0 total.", "", $response); |
|
363 | 363 | return $response; |
364 | 364 | } |
365 | 365 |
@@ -59,8 +59,8 @@ |
||
59 | 59 | //set_error_handler('xml_not_found'); |
60 | 60 | |
61 | 61 | //Define file name |
62 | -$file = "astpp." . $_REQUEST['section'] . ".php"; |
|
62 | +$file = "astpp.".$_REQUEST['section'].".php"; |
|
63 | 63 | |
64 | 64 | //Include file |
65 | -include_once("scripts/" . $file); |
|
65 | +include_once("scripts/".$file); |
|
66 | 66 | ?> |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | case 'development': |
30 | 30 | // error_reporting(E_ALL); |
31 | - error_reporting(E_ERROR|E_WARNING|E_PARSE); |
|
31 | + error_reporting(E_ERROR | E_WARNING | E_PARSE); |
|
32 | 32 | break; |
33 | 33 | |
34 | 34 | case 'testing': |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | $config = $lib->get_configurations($db); |
56 | 56 | |
57 | 57 | //Set default decimal points |
58 | -$decimal_points = ($config['decimal_points'] <= 0)?4:$config['decimal_points']; |
|
58 | +$decimal_points = ($config['decimal_points'] <= 0) ? 4 : $config['decimal_points']; |
|
59 | 59 | |
60 | 60 | //Define logger object |
61 | 61 | $logger = new logger($lib); |
62 | 62 | |
63 | -if(isset($_SERVER["CONTENT_TYPE"]) && $_SERVER["CONTENT_TYPE"] == "application/json") { |
|
63 | +if (isset($_SERVER["CONTENT_TYPE"]) && $_SERVER["CONTENT_TYPE"] == "application/json") { |
|
64 | 64 | |
65 | 65 | $db->run("SET NAMES utf8"); |
66 | - $data = json_decode(file_get_contents("php://input"),true); |
|
66 | + $data = json_decode(file_get_contents("php://input"), true); |
|
67 | 67 | //error_log(print_r($data,true)); |
68 | - $logger->log(print_r($data,true)); |
|
69 | - process_cdr($data,$db,$logger,$decimal_points); |
|
68 | + $logger->log(print_r($data, true)); |
|
69 | + process_cdr($data, $db, $logger, $decimal_points); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | //$db->cleanup(); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | ############################################################################### |
23 | 23 | |
24 | 24 | //Define user rates array for parsing |
25 | -$CONST_USER_RATE = array ( |
|
25 | +$CONST_USER_RATE = array( |
|
26 | 26 | 'RID' => 'id', |
27 | 27 | 'RCD' => 'code', |
28 | 28 | 'RDS' => 'destination', |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | ); |
37 | 37 | |
38 | 38 | //Define carrier rates array for parsing |
39 | -$CONST_CARRIER_RATE = array ( |
|
39 | +$CONST_CARRIER_RATE = array( |
|
40 | 40 | 'CID' => 'id', |
41 | 41 | 'CCD' => 'code', |
42 | 42 | 'CDS' => 'destination', |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | public function cleanup($bind) { |
51 | - if (!is_array($bind)) { |
|
52 | - if (!empty($bind)) |
|
51 | + if ( ! is_array($bind)) { |
|
52 | + if ( ! empty($bind)) |
|
53 | 53 | $bind = array($bind); |
54 | 54 | else |
55 | 55 | $bind = array(); |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | try { |
66 | 66 | $pdostmt = $this->prepare($this->sql); |
67 | 67 | if ($pdostmt->execute($this->bind) !== false) { |
68 | - if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql)) |
|
68 | + if (preg_match("/^(".implode("|", array("select", "describe", "pragma")).") /i", $this->sql)) |
|
69 | 69 | return $pdostmt->fetchAll(PDO::FETCH_ASSOC); |
70 | - elseif (preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql)) |
|
70 | + elseif (preg_match("/^(".implode("|", array("delete", "insert", "update")).") /i", $this->sql)) |
|
71 | 71 | return $pdostmt->rowCount(); |
72 | 72 | } |
73 | 73 | } catch (PDOException $e) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | //Build acl xml |
39 | -function load_acl($logger, $db,$config) { |
|
39 | +function load_acl($logger, $db, $config) { |
|
40 | 40 | $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; |
41 | 41 | $xml .= "<document type=\"freeswitch/xml\">\n"; |
42 | 42 | $xml .= " <section name=\"Configuration\" description=\"Configuration\">\n"; |
@@ -46,29 +46,29 @@ discard block |
||
46 | 46 | |
47 | 47 | //For customer and provider ips |
48 | 48 | $query = "SELECT ip FROM ip_map,accounts WHERE ip_map.accountid=accounts.id AND accounts.status=0 AND deleted=0"; |
49 | - $logger->log("ACL Query : " . $query); |
|
49 | + $logger->log("ACL Query : ".$query); |
|
50 | 50 | $res_acl = $db->run($query); |
51 | 51 | $logger->log($res_acl); |
52 | 52 | |
53 | 53 | foreach ($res_acl as $res_acl_key => $res_acl_value) { |
54 | - $xml .= " <node type=\"allow\" cidr=\"" . $res_acl_value['ip'] . "\"/>\n"; |
|
54 | + $xml .= " <node type=\"allow\" cidr=\"".$res_acl_value['ip']."\"/>\n"; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | //For gateways |
58 | 58 | $query = "SELECT * FROM gateways WHERE status=0"; |
59 | - $logger->log("Sofia Gateway Query : " . $query); |
|
59 | + $logger->log("Sofia Gateway Query : ".$query); |
|
60 | 60 | $sp_gw = $db->run($query); |
61 | 61 | $logger->log($sp_gw); |
62 | 62 | |
63 | 63 | foreach ($sp_gw as $sp_gw_key => $sp_gw_value) { |
64 | 64 | |
65 | - $sp_gw_settings = json_decode($sp_gw_value['gateway_data'], true); |
|
65 | + $sp_gw_settings = json_decode($sp_gw_value['gateway_data'], true); |
|
66 | 66 | foreach ($sp_gw_settings as $sp_gw_settings_key => $sp_gw_settings_value) { |
67 | 67 | if ($sp_gw_settings_value != "" && $sp_gw_settings_key == "proxy") |
68 | 68 | { |
69 | - $tmp_ip_arr = explode(":",$sp_gw_settings_value); |
|
70 | - if (!filter_var($tmp_ip_arr[0], FILTER_VALIDATE_IP) === false) { |
|
71 | - $xml .= " <node type=\"allow\" cidr=\"" . $tmp_ip_arr[0] . "/32\"/>\n"; |
|
69 | + $tmp_ip_arr = explode(":", $sp_gw_settings_value); |
|
70 | + if ( ! filter_var($tmp_ip_arr[0], FILTER_VALIDATE_IP) === false) { |
|
71 | + $xml .= " <node type=\"allow\" cidr=\"".$tmp_ip_arr[0]."/32\"/>\n"; |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | |
79 | 79 | //For opensips |
80 | - if($config['opensips'] == '0') |
|
80 | + if ($config['opensips'] == '0') |
|
81 | 81 | { |
82 | 82 | $xml .= "<node type=\"allow\" cidr=\"".$config['opensips_domain']."/32\"/>\n"; |
83 | 83 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $xml .= " </list>\n"; |
86 | 86 | |
87 | 87 | //For loopback |
88 | - if($config['opensips'] == '0') |
|
88 | + if ($config['opensips'] == '0') |
|
89 | 89 | { |
90 | 90 | $xml .= "<list name=\"loopback.auto\" default=\"allow\">\n"; |
91 | 91 | $xml .= "<node type=\"allow\" cidr=\"".$config['opensips_domain']."/32\"/>\n"; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | //For event handing |
96 | 96 | $xml .= "<list name=\"event\" default=\"deny\">\n"; |
97 | - $xml .= ($config['opensips'] == "0")?"<node type=\"allow\" cidr=\"".$config['opensips_domain']."/32\"/>\n":"\n"; |
|
97 | + $xml .= ($config['opensips'] == "0") ? "<node type=\"allow\" cidr=\"".$config['opensips_domain']."/32\"/>\n" : "\n"; |
|
98 | 98 | $xml .= "<node type=\"allow\" cidr=\"127.0.0.0/8\"/>\n"; |
99 | 99 | $xml .= "</list>\n"; |
100 | 100 | $xml .= " </network-lists>\n"; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $xml .= " <profiles>\n"; |
115 | 115 | |
116 | 116 | $query = "SELECT * FROM sip_profiles WHERE status=0"; |
117 | - $logger->log("Sofia Query : " . $query); |
|
117 | + $logger->log("Sofia Query : ".$query); |
|
118 | 118 | $res_sp = $db->run($query); |
119 | 119 | //$logger->log($res_sp); |
120 | 120 | |
@@ -122,40 +122,40 @@ discard block |
||
122 | 122 | |
123 | 123 | $settings = json_decode($sp_value['profile_data'], true); |
124 | 124 | //$logger->log(print_r($settings,true)); |
125 | - $xml .= " <profile name=\"" . $sp_value['name'] . "\">\n"; |
|
125 | + $xml .= " <profile name=\"".$sp_value['name']."\">\n"; |
|
126 | 126 | |
127 | 127 | $xml .= " <domains>\n"; |
128 | - $xml .= " <domain name=\"" . $sp_value['sip_ip'] . "\" alias=\"true\" parse=\"true\"/>\n"; |
|
128 | + $xml .= " <domain name=\"".$sp_value['sip_ip']."\" alias=\"true\" parse=\"true\"/>\n"; |
|
129 | 129 | $xml .= " </domains>\n"; |
130 | 130 | /*$xml .= " <aliases>\n"; |
131 | 131 | $xml .= " <alias name=\"" . $sp_value['sip_ip'] . "\"/>\n"; |
132 | 132 | $xml .= " </aliases>\n";*/ |
133 | 133 | |
134 | 134 | $xml .= " <settings>\n"; |
135 | - $xml .= " <param name=\"sip-ip\" value=\"" . $sp_value['sip_ip'] . "\"/>\n"; |
|
136 | - $xml .= " <param name=\"sip-port\" value=\"" . $sp_value['sip_port'] . "\"/>\n"; |
|
137 | - foreach($settings as $set_key => $set_val) |
|
135 | + $xml .= " <param name=\"sip-ip\" value=\"".$sp_value['sip_ip']."\"/>\n"; |
|
136 | + $xml .= " <param name=\"sip-port\" value=\"".$sp_value['sip_port']."\"/>\n"; |
|
137 | + foreach ($settings as $set_key => $set_val) |
|
138 | 138 | { |
139 | - $xml .= " <param name=\"" . $set_key . "\" value=\"" . $set_val . "\"/>\n"; |
|
139 | + $xml .= " <param name=\"".$set_key."\" value=\"".$set_val."\"/>\n"; |
|
140 | 140 | } |
141 | 141 | $xml .= " </settings>\n"; |
142 | 142 | |
143 | 143 | |
144 | 144 | //Gateway block start |
145 | 145 | $xml .= " <gateways>\n"; |
146 | - $query = "SELECT * FROM gateways WHERE sip_profile_id=" . $sp_value['id'] . " AND status=0"; |
|
147 | - $logger->log("Sofia Gateway Query : " . $query); |
|
146 | + $query = "SELECT * FROM gateways WHERE sip_profile_id=".$sp_value['id']." AND status=0"; |
|
147 | + $logger->log("Sofia Gateway Query : ".$query); |
|
148 | 148 | $sp_gw = $db->run($query); |
149 | 149 | $logger->log($sp_gw); |
150 | 150 | foreach ($sp_gw as $sp_gw_key => $sp_gw_value) { |
151 | - $xml .= " <gateway name=\"" . $sp_gw_value['name'] . "\">\n"; |
|
151 | + $xml .= " <gateway name=\"".$sp_gw_value['name']."\">\n"; |
|
152 | 152 | |
153 | 153 | |
154 | 154 | |
155 | - $sp_gw_settings = json_decode($sp_gw_value['gateway_data'], true); |
|
155 | + $sp_gw_settings = json_decode($sp_gw_value['gateway_data'], true); |
|
156 | 156 | foreach ($sp_gw_settings as $sp_gw_settings_key => $sp_gw_settings_value) { |
157 | 157 | if ($sp_gw_settings_value != "") |
158 | - $xml .= " <param name=\"" . $sp_gw_settings_key . "\" value=\"" . $sp_gw_settings_value . "\"/>\n"; |
|
158 | + $xml .= " <param name=\"".$sp_gw_settings_key."\" value=\"".$sp_gw_settings_value."\"/>\n"; |
|
159 | 159 | } |
160 | 160 | $xml .= " </gateway>\n"; |
161 | 161 | } |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | function load_directory($logger, $db) { |
178 | 178 | $xml = ""; |
179 | 179 | |
180 | - $query = "SELECT username,dir_params,dir_vars,number as accountcode,accountid FROM sip_devices,accounts WHERE accounts.status=0 AND accounts.deleted=0 AND accounts.id=sip_devices.accountid AND username='" . $_REQUEST['user']."' limit 1"; |
|
180 | + $query = "SELECT username,dir_params,dir_vars,number as accountcode,accountid FROM sip_devices,accounts WHERE accounts.status=0 AND accounts.deleted=0 AND accounts.id=sip_devices.accountid AND username='".$_REQUEST['user']."' limit 1"; |
|
181 | 181 | |
182 | - $logger->log("Directory Query : " . $query); |
|
182 | + $logger->log("Directory Query : ".$query); |
|
183 | 183 | $res_dir = $db->run($query); |
184 | 184 | $logger->log($res_dir); |
185 | 185 | |
@@ -187,21 +187,21 @@ discard block |
||
187 | 187 | $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; |
188 | 188 | $xml .= "<document type=\"freeswitch/xml\">\n"; |
189 | 189 | $xml .= " <section name=\"Directory\" description=\"Directory\">\n"; |
190 | - $xml .= " <domain name=\"" . $_REQUEST['domain'] . "\" alias=\"true\">\n"; |
|
191 | - $xml .= " <user id=\"" . $_REQUEST['user'] . "\">\n"; |
|
190 | + $xml .= " <domain name=\"".$_REQUEST['domain']."\" alias=\"true\">\n"; |
|
191 | + $xml .= " <user id=\"".$_REQUEST['user']."\">\n"; |
|
192 | 192 | |
193 | 193 | $params = json_decode($res_dir_value['dir_params'], true); |
194 | 194 | |
195 | 195 | $vars = json_decode($res_dir_value['dir_vars'], true); |
196 | 196 | $param_xml = $var_xml = ""; |
197 | - foreach($params as $parms_key => $res_dir_params) |
|
197 | + foreach ($params as $parms_key => $res_dir_params) |
|
198 | 198 | { |
199 | - $param_xml .= "<param name=\"" . $parms_key . "\" value=\"" . $res_dir_params . "\"/>\n"; |
|
199 | + $param_xml .= "<param name=\"".$parms_key."\" value=\"".$res_dir_params."\"/>\n"; |
|
200 | 200 | } |
201 | 201 | |
202 | - foreach($vars as $var_key => $res_dir_vars) |
|
202 | + foreach ($vars as $var_key => $res_dir_vars) |
|
203 | 203 | { |
204 | - $var_xml .= "<variable name=\"" . $var_key . "\" value=\"" . $res_dir_vars . "\"/>\n"; |
|
204 | + $var_xml .= "<variable name=\"".$var_key."\" value=\"".$res_dir_vars."\"/>\n"; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | $xml .= " <variables>\n"; |
215 | 215 | $xml .= $var_xml; |
216 | 216 | $xml .= "<variable name=\"sipcall\" value=\"true\"/>\n"; |
217 | - $xml .= "<variable name=\"accountcode\" value=\"" . $res_dir_value['accountcode'] . "\"/>\n"; |
|
218 | - $xml .= "<variable name=\"domain_name\" value=\"" . $_REQUEST['domain'] . "\"/>\n"; |
|
217 | + $xml .= "<variable name=\"accountcode\" value=\"".$res_dir_value['accountcode']."\"/>\n"; |
|
218 | + $xml .= "<variable name=\"domain_name\" value=\"".$_REQUEST['domain']."\"/>\n"; |
|
219 | 219 | $xml .= " </variables>\n"; |
220 | 220 | |
221 | 221 | $xml .= " </user>\n"; |
@@ -54,25 +54,25 @@ discard block |
||
54 | 54 | $number_len = strlen($destination_number); |
55 | 55 | $number_loop_str = '('; |
56 | 56 | while ($number_len > 0) { |
57 | - $number_loop_str .= " code='" . substr($destination_number, 0, $number_len) . "' OR "; |
|
57 | + $number_loop_str .= " code='".substr($destination_number, 0, $number_len)."' OR "; |
|
58 | 58 | $number_len -= 1; |
59 | 59 | } |
60 | 60 | $number_loop_str .= " code='--')"; |
61 | 61 | |
62 | - $query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE " . $number_loop_str . " AND B.package_id = A.id AND A.ratecard_id=" . $rates_array['ratecard_id'] . " AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC"; |
|
63 | - $logger->log("Package Query : " . $query); |
|
62 | + $query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE ".$number_loop_str." AND B.package_id = A.id AND A.ratecard_id=".$rates_array['ratecard_id']." AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC"; |
|
63 | + $logger->log("Package Query : ".$query); |
|
64 | 64 | $res_package = $db->run($query); |
65 | 65 | |
66 | 66 | foreach ($res_package as $res_package_key => $package_info) { |
67 | 67 | if (isset($package_info['package_id'])) { |
68 | - $query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=" . $package_info['code'] . " AND package_id=" . $package_info['package_id'] . " AND user_id=" . $user_id; |
|
69 | - $logger->log("Package usage Query : " . $query); |
|
68 | + $query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=".$package_info['code']." AND package_id=".$package_info['package_id']." AND user_id=".$user_id; |
|
69 | + $logger->log("Package usage Query : ".$query); |
|
70 | 70 | $res_pkg_usg = $db->run($query); |
71 | 71 | $package_usage_info = $res_pkg_usg[0]; |
72 | 72 | |
73 | 73 | $used_seconds = (isset($package_usage_info['used_seconds'])) ? $package_usage_info['used_seconds'] : 0; |
74 | 74 | |
75 | - $logger->log("Included seconds : " . $package_info['includedseconds'] . ", Used seconds : " . $used_seconds); |
|
75 | + $logger->log("Included seconds : ".$package_info['includedseconds'].", Used seconds : ".$used_seconds); |
|
76 | 76 | if ($package_info['includedseconds'] > $used_seconds) { |
77 | 77 | $remaining_seconds = $package_info['includedseconds'] - ($duration + $used_seconds); |
78 | 78 | if ($remaining_seconds > 0) { |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | $flag = true; |
86 | 86 | $xml_cdr->variables->package_id = $package_info['package_id']; |
87 | 87 | |
88 | - $query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (" . $package_info['package_id'] . "," . $user_id . ",'" . $package_info['code'] . "'," . $dud_sec . ") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+" . $dud_sec; |
|
89 | - $logger->log("Package Usage Query : " . $query); |
|
88 | + $query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (".$package_info['package_id'].",".$user_id.",'".$package_info['code']."',".$dud_sec.") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+".$dud_sec; |
|
89 | + $logger->log("Package Usage Query : ".$query); |
|
90 | 90 | $db->run($query); |
91 | 91 | |
92 | 92 | break; |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | |
100 | 100 | //Process user/vendor cdr |
101 | 101 | function do_cdr_process($xml_cdr, $debit, $cost, $vendor_cost, $rates_array, $parent_id = 0, $parent_rates, $carrier_rates_array, $logger, $db) { |
102 | - $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . $xml_cdr->variables->entity_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->carrier_id . "','" . $xml_cdr->callflow[0]->caller_profile->originatee->originatee_caller_profile->network_addr . "','" . $xml_cdr->variables->sip_contact_host . "','" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . ",'" . $xml_cdr->variables->vendor_id . "'," . $vendor_cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . @$carrier_rates_array['code'] . "','" . @$carrier_rates_array['destination'] . "','" . @$carrier_rates_array['cost'] . "','" . $xml_cdr->variables->call_direction . "','" . urldecode($xml_cdr->variables->profile_start_stamp) . "','" . urldecode($xml_cdr->variables->answer_stamp) . "','" . urldecode($xml_cdr->variables->bridge_stamp) . "','" . urldecode($xml_cdr->variables->progress_stamp) . "','" . urldecode($xml_cdr->variables->progress_media_stamp) . "','" . urldecode($xml_cdr->variables->end_stamp) . "'," . $xml_cdr->variables->billmsec . "," . $xml_cdr->variables->answermsec . "," . $xml_cdr->variables->waitmsec . "," . $xml_cdr->variables->progress_mediamsec . "," . $xml_cdr->variables->flow_billmsec; |
|
102 | + $query_string = "'".$xml_cdr->variables->uuid."','".$xml_cdr->variables->user_id."','".$xml_cdr->variables->entity_id."','".urldecode($xml_cdr->variables->effective_caller_id_name)."','".$xml_cdr->variables->effective_caller_id_number."','".$xml_cdr->variables->effective_destination_number."',".$xml_cdr->variables->duration.",'".$xml_cdr->variables->carrier_id."','".$xml_cdr->callflow[0]->caller_profile->originatee->originatee_caller_profile->network_addr."','".$xml_cdr->variables->sip_contact_host."','".$xml_cdr->variables->hangup_cause."','".urldecode($xml_cdr->variables->start_stamp)."',".$debit.",".$cost.",'".$xml_cdr->variables->vendor_id."',".$vendor_cost.",".$rates_array['ratecard_id'].",".$xml_cdr->variables->package_id.",'".$rates_array['code']."','".$rates_array['destination']."','".$rates_array['cost']."','".$parent_id."','".@$parent_rates['code']."','".@$parent_rates['destination']."','".@$parent_rates['cost']."','".@$carrier_rates_array['code']."','".@$carrier_rates_array['destination']."','".@$carrier_rates_array['cost']."','".$xml_cdr->variables->call_direction."','".urldecode($xml_cdr->variables->profile_start_stamp)."','".urldecode($xml_cdr->variables->answer_stamp)."','".urldecode($xml_cdr->variables->bridge_stamp)."','".urldecode($xml_cdr->variables->progress_stamp)."','".urldecode($xml_cdr->variables->progress_media_stamp)."','".urldecode($xml_cdr->variables->end_stamp)."',".$xml_cdr->variables->billmsec.",".$xml_cdr->variables->answermsec.",".$xml_cdr->variables->waitmsec.",".$xml_cdr->variables->progress_mediamsec.",".$xml_cdr->variables->flow_billmsec; |
|
103 | 103 | |
104 | 104 | $query = "INSERT INTO tbl_cdrs (uniqueid,user_id,entity_id,callerid_name,callerid_number,dstnum,duration,carrier_id,carrierip,callerip,disposition,start_stamp,debit,cost,vendor_id,vendor_cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,carrier_code,carrier_code_destination ,carrier_cost,call_direction,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($query_string)"; |
105 | 105 | |
106 | - $logger->log("CDR Query : " . $query); |
|
106 | + $logger->log("CDR Query : ".$query); |
|
107 | 107 | $db->run($query); |
108 | 108 | } |
109 | 109 | |
110 | 110 | //Process reseller cdr |
111 | 111 | function do_reseller_cdr_process($xml_cdr, $debit, $cost, $rates_array, $parent_id = 0, $parent_rates, $logger, $db) { |
112 | - $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . $xml_cdr->variables->call_direction . "'"; |
|
112 | + $query_string = "'".$xml_cdr->variables->uuid."','".$xml_cdr->variables->user_id."','".urldecode($xml_cdr->variables->effective_caller_id_name)."','".$xml_cdr->variables->effective_caller_id_number."','".$xml_cdr->variables->effective_destination_number."',".$xml_cdr->variables->duration.",'".$xml_cdr->variables->hangup_cause."','".urldecode($xml_cdr->variables->start_stamp)."',".$debit.",".$cost.",".$rates_array['ratecard_id'].",".$xml_cdr->variables->package_id.",'".$rates_array['code']."','".$rates_array['destination']."','".$rates_array['cost']."','".$parent_id."','".@$parent_rates['code']."','".@$parent_rates['destination']."','".@$parent_rates['cost']."','".$xml_cdr->variables->call_direction."'"; |
|
113 | 113 | |
114 | 114 | $query = "INSERT INTO tbl_cdrs_reseller (uniqueid,reseller_id,callerid_name,callerid_number,dstnum,duration,disposition,start_stamp,debit,cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,call_direction) values ($query_string)"; |
115 | 115 | |
116 | - $logger->log("CDR Query : " . $query); |
|
116 | + $logger->log("CDR Query : ".$query); |
|
117 | 117 | $db->run($query); |
118 | 118 | } |
119 | 119 | |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
122 | 122 | if ($amount > 0) { |
123 | 123 | $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
124 | - $query = "UPDATE tbl_users SET credit=credit$math_sign" . $amount . " WHERE id=" . $user_id; |
|
125 | - $logger->log("Balance update : " . $query); |
|
124 | + $query = "UPDATE tbl_users SET credit=credit$math_sign".$amount." WHERE id=".$user_id; |
|
125 | + $logger->log("Balance update : ".$query); |
|
126 | 126 | $db->run($query); |
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
130 | 130 | //Get user info |
131 | 131 | function get_user_info($parent_id, $db) { |
132 | - $query = "SELECT * FROM tbl_users WHERE id=" . $parent_id; |
|
132 | + $query = "SELECT * FROM tbl_users WHERE id=".$parent_id; |
|
133 | 133 | $res_user = $db->run($query); |
134 | 134 | return $res_user[0]; |
135 | 135 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | ############################################################################### |
23 | 23 | |
24 | 24 | //Process CDR |
25 | -function process_cdr($data,$db,$logger,$decimal_points) |
|
25 | +function process_cdr($data, $db, $logger, $decimal_points) |
|
26 | 26 | { |
27 | 27 | //$logger->log(print_r($data,true));//exit; |
28 | 28 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | |
47 | 47 | if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING') |
48 | 48 | { |
49 | - $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']; |
|
50 | - }else{ |
|
49 | + $hangup_cause = isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']; |
|
50 | + } else { |
|
51 | 51 | $hangup_cause = $dataVariable['hangup_cause']; |
52 | 52 | } |
53 | 53 | |
54 | 54 | if ($dataVariable['error_cdr'] == '1') |
55 | 55 | { |
56 | 56 | //Get actual hangup cause |
57 | - $hangup_cause= (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']); |
|
57 | + $hangup_cause = (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /*#### PATCH FOR ONE WAY AUDIO ####*/ |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | /*#### ************* END *************####*/ |
66 | 66 | |
67 | 67 | //Don't thing this will be useful anytime. Need to remove it after testing. |
68 | - if($hangup_cause == "NONE") |
|
68 | + if ($hangup_cause == "NONE") |
|
69 | 69 | { |
70 | 70 | $hangup_cause = $dataVariable['current_application_data']; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $dataVariable['hangup_cause'] = $hangup_cause; |
74 | 74 | |
75 | - if ( ($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) { |
|
75 | + if (($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) { |
|
76 | 76 | $dataVariable['billsec'] = 0; |
77 | 77 | } |
78 | 78 | |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | $actual_calltype = $dataVariable['calltype']; |
87 | 87 | |
88 | 88 | //Normalize origination and termination rates array |
89 | - if(isset($dataVariable['origination_rates'])) |
|
89 | + if (isset($dataVariable['origination_rates'])) |
|
90 | 90 | $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
91 | - if(isset($dataVariable['termination_rates'])) |
|
91 | + if (isset($dataVariable['termination_rates'])) |
|
92 | 92 | $termination_rate = normalize_rate($dataVariable['termination_rates']); |
93 | 93 | |
94 | 94 | //If receiver account id found then explicitly set call direction and call type |
95 | - if(isset($dataVariable['receiver_accid'])) |
|
95 | + if (isset($dataVariable['receiver_accid'])) |
|
96 | 96 | { |
97 | 97 | $dataVariable['call_direction'] = "outbound"; |
98 | 98 | $dataVariable['calltype'] = "STANDARD"; |
@@ -101,23 +101,23 @@ discard block |
||
101 | 101 | //Check if cusotmer have any package seconds left to use |
102 | 102 | if ($actual_duration > 0) |
103 | 103 | { |
104 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
105 | - if(!empty($package_array)) |
|
104 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
105 | + if ( ! empty($package_array)) |
|
106 | 106 | { |
107 | 107 | $dataVariable['calltype'] = "FREE"; |
108 | - $dataVariable['package_id']= $package_array['package_id']; |
|
108 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | 112 | //Calculate debit of customer call |
113 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
113 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
114 | 114 | |
115 | 115 | //Calculate cost for customer call for provider |
116 | - $provider_cost = calc_cost($dataVariable,$termination_rate,$logger,$decimal_points); |
|
116 | + $provider_cost = calc_cost($dataVariable, $termination_rate, $logger, $decimal_points); |
|
117 | 117 | |
118 | 118 | //Calculate parent cost if customer have any parent |
119 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
120 | - $logger->log("Debit :".$debit ." Cost : ".$cost ." Provider Cost : ".$parent_cost); |
|
119 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
120 | + $logger->log("Debit :".$debit." Cost : ".$cost." Provider Cost : ".$parent_cost); |
|
121 | 121 | |
122 | 122 | //Initialize final cost variable to use for billing |
123 | 123 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
@@ -125,33 +125,33 @@ discard block |
||
125 | 125 | //Outbound call entry for all type of calls |
126 | 126 | $logger->log("*********************** OUTBOUND CALL ENTRY START *************"); |
127 | 127 | |
128 | - $cdr_string = get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger); |
|
128 | + $cdr_string = get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger); |
|
129 | 129 | |
130 | 130 | $query = "INSERT INTO cdrs (uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)"; |
131 | 131 | $logger->log($query); |
132 | 132 | $db->run($query); |
133 | 133 | |
134 | 134 | //Update customer balance |
135 | - if($debit > 0 && $dataVariable['calltype'] != "FREE") |
|
135 | + if ($debit > 0 && $dataVariable['calltype'] != "FREE") |
|
136 | 136 | { |
137 | 137 | update_balance($accountid, $debit, 0, $logger, $db); |
138 | 138 | } |
139 | 139 | |
140 | 140 | //Update parent or provider balance |
141 | - if($parent_cost > 0){ |
|
141 | + if ($parent_cost > 0) { |
|
142 | 142 | update_balance($termination_rate['PROVIDER'], ($parent_cost * -1), 3, $logger, $db); |
143 | 143 | } |
144 | 144 | |
145 | 145 | //Resellers CDR entry |
146 | 146 | $flag_parent = false; |
147 | - insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
147 | + insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
148 | 148 | |
149 | 149 | $logger->log("*********************** OUTBOUND CALL ENTRY END *************"); |
150 | 150 | |
151 | 151 | |
152 | 152 | //************ ADDING EXTRA ENTRY For local/DID Inbound call **************************** |
153 | - $receiver_parentid=0; |
|
154 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "") |
|
153 | + $receiver_parentid = 0; |
|
154 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "") |
|
155 | 155 | { |
156 | 156 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************"); |
157 | 157 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $dataVariable['calltype'] = "DID"; |
161 | 161 | |
162 | 162 | //Override variables if call for DID PSTN |
163 | - if(isset($dataVariable['caller_did_account_id'])) |
|
163 | + if (isset($dataVariable['caller_did_account_id'])) |
|
164 | 164 | { |
165 | 165 | $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
166 | 166 | $dataVariable['call_direction'] = "outbound"; |
@@ -171,17 +171,17 @@ discard block |
||
171 | 171 | |
172 | 172 | |
173 | 173 | //Get call receiver account information |
174 | - $receiver_carddata = get_accounts($dataVariable['receiver_accid'],$logger,$db); |
|
174 | + $receiver_carddata = get_accounts($dataVariable['receiver_accid'], $logger, $db); |
|
175 | 175 | $receiver_parentid = $receiver_carddata['reseller_id']; |
176 | 176 | |
177 | 177 | //For additional cdr entry of receiver |
178 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$receiver_parentid,$flag_parent,$dataVariable['receiver_accid'],$logger,$db,$decimal_points); |
|
178 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $receiver_parentid, $flag_parent, $dataVariable['receiver_accid'], $logger, $db, $decimal_points); |
|
179 | 179 | |
180 | 180 | $flag_parent = true; |
181 | 181 | $dataVariable['uuid'] = $dataVariable['uuid'].$dataVariable['calltype']."_".$receiver_parentid; |
182 | 182 | |
183 | 183 | //Insert parent reseller cdr |
184 | - insert_parent_data($dataVariable,$actual_calltype,$receiver_parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
184 | + insert_parent_data($dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
185 | 185 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************"); |
186 | 186 | } |
187 | 187 | //***************************************************************************************** |
@@ -189,16 +189,16 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | //Insert parent resellers cdr |
192 | -function insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points) |
|
192 | +function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points) |
|
193 | 193 | { |
194 | - while($parentid > 0 ) |
|
194 | + while ($parentid > 0) |
|
195 | 195 | { |
196 | 196 | $logger->log("*************** IN PARENT DATA SECTION ********"); |
197 | 197 | $dataVariable['calltype'] = $actual_calltype; |
198 | - $carddata = get_accounts($parentid,$logger,$db); |
|
198 | + $carddata = get_accounts($parentid, $logger, $db); |
|
199 | 199 | $accountid = $carddata['id']; |
200 | 200 | |
201 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
201 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
202 | 202 | |
203 | 203 | //If receiver account id found then explicitly set call direction and call type |
204 | 204 | /*if(isset($dataVariable['receiver_accid'])) |
@@ -208,31 +208,31 @@ discard block |
||
208 | 208 | }*/ |
209 | 209 | |
210 | 210 | //Check if reseller have any package seconds left to use |
211 | - if ($actual_duration > 0) { |
|
212 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
213 | - if(!empty($package_array)) |
|
211 | + if ($actual_duration > 0) { |
|
212 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
213 | + if ( ! empty($package_array)) |
|
214 | 214 | { |
215 | 215 | $dataVariable['calltype'] = "FREE"; |
216 | - $dataVariable['package_id']= $package_array['package_id']; |
|
216 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | 220 | //Get parent id for cost calculation |
221 | 221 | $parentid = $carddata['reseller_id']; |
222 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
222 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
223 | 223 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
224 | 224 | |
225 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
225 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
226 | 226 | { |
227 | 227 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******"); |
228 | 228 | $flag_parent = true; |
229 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points); |
|
229 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points); |
|
230 | 230 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******"); |
231 | 231 | return true; |
232 | 232 | |
233 | - }else{ |
|
233 | + } else { |
|
234 | 234 | |
235 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
235 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
236 | 236 | |
237 | 237 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
238 | 238 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | $db->run($query); |
241 | 241 | |
242 | 242 | //Update reseller balance |
243 | - if( $debit > 0 && $dataVariable['calltype'] != "FREE"){ |
|
243 | + if ($debit > 0 && $dataVariable['calltype'] != "FREE") { |
|
244 | 244 | update_balance($accountid, $debit, 0, $logger, $db); |
245 | 245 | } |
246 | 246 | } |
@@ -250,40 +250,40 @@ discard block |
||
250 | 250 | } |
251 | 251 | |
252 | 252 | //Insert callee cdr entry for DID calls |
253 | -function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points) |
|
253 | +function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points) |
|
254 | 254 | { |
255 | 255 | $localVariable = $dataVariable; |
256 | 256 | $localVariable['call_direction'] = "inbound"; |
257 | 257 | $localVariable['uuid'] = $localVariable['uuid'].$dataVariable['calltype']."_".$accountid; |
258 | 258 | |
259 | - if($dataVariable['calltype'] == "LOCAL") |
|
259 | + if ($dataVariable['calltype'] == "LOCAL") |
|
260 | 260 | { |
261 | 261 | $origination_rate[$accountid]['CODE'] = $dataVariable['effective_destination_number']; |
262 | 262 | $origination_rate[$accountid]['DESTINATION'] = $dataVariable['calltype']; |
263 | - if($flag_parent == false){ |
|
264 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,0,0,$logger); |
|
263 | + if ($flag_parent == false) { |
|
264 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, 0, 0, $logger); |
|
265 | 265 | } |
266 | - else{ |
|
267 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
266 | + else { |
|
267 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
268 | 268 | } |
269 | - }else{ |
|
269 | + } else { |
|
270 | 270 | |
271 | 271 | $origination_rate_did = normalize_origination_rate($dataVariable['origination_rates_did']); |
272 | - $debit = calc_cost($dataVariable,$origination_rate_did[$accountid],$logger,$decimal_points); |
|
272 | + $debit = calc_cost($dataVariable, $origination_rate_did[$accountid], $logger, $decimal_points); |
|
273 | 273 | |
274 | - if($flag_parent == false){ |
|
274 | + if ($flag_parent == false) { |
|
275 | 275 | |
276 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate_did,$provider_cost,$parentid,$debit,0,$logger); |
|
276 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger); |
|
277 | 277 | } |
278 | - else{ |
|
279 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
278 | + else { |
|
279 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | - if($flag_parent == false) |
|
283 | + if ($flag_parent == false) |
|
284 | 284 | { |
285 | 285 | $query = "INSERT INTO cdrs(uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)"; |
286 | - }else{ |
|
286 | + } else { |
|
287 | 287 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
288 | 288 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
289 | 289 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $logger->log($query); |
292 | 292 | $db->run($query); |
293 | 293 | |
294 | - if($debit > 0 && ($dataVariable['calltype'] != "FREE" && $dataVariable['calltype'] != "LOCAL")) |
|
294 | + if ($debit > 0 && ($dataVariable['calltype'] != "FREE" && $dataVariable['calltype'] != "LOCAL")) |
|
295 | 295 | { |
296 | 296 | update_balance($accountid, $debit, 0, $logger, $db); |
297 | 297 | } |
@@ -299,29 +299,29 @@ discard block |
||
299 | 299 | } |
300 | 300 | |
301 | 301 | //Generate CDR string for insert query for customer. |
302 | -function get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger) |
|
302 | +function get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger) |
|
303 | 303 | { |
304 | 304 | |
305 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
305 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
306 | 306 | |
307 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'],ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").", |
|
308 | -'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'" ).", |
|
307 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'], ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").", |
|
308 | +'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'").", |
|
309 | 309 | ".(($termination_rate['DESTINATION']) ? "'".$termination_rate['DESTINATION']."'" : "'".''."'").",".(($termination_rate['COST']) ? "'".$termination_rate['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."','".convert_to_gmt(urldecode($dataVariable['profile_start_stamp']))."','".convert_to_gmt(urldecode($dataVariable['answer_stamp']))."','".convert_to_gmt(urldecode($dataVariable['bridge_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_media_stamp']))."','".convert_to_gmt(urldecode($dataVariable['end_stamp']))."',".$dataVariable['billmsec'].",'".$dataVariable['answermsec']."','".$dataVariable['waitmsec']."','".$dataVariable['progress_mediamsec']."','".$dataVariable['flow_billmsec']."'"; |
310 | 310 | |
311 | 311 | } |
312 | 312 | |
313 | 313 | //Generate CDR string for insert query for reseller |
314 | -function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost) |
|
314 | +function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost) |
|
315 | 315 | { |
316 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
317 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
|
316 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
317 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | //Update user balance |
321 | 321 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
322 | 322 | $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
323 | - $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
324 | - $logger->log("Balance update : " . $query); |
|
323 | + $query = "UPDATE accounts SET balance=balance-".$amount." WHERE id=".$user_id; |
|
324 | + $logger->log("Balance update : ".$query); |
|
325 | 325 | $db->run($query); |
326 | 326 | } |
327 | 327 | |
@@ -329,13 +329,13 @@ discard block |
||
329 | 329 | function normalize_rate($dataVariable) |
330 | 330 | { |
331 | 331 | $rates = urldecode($dataVariable); |
332 | - $data = explode("|",$rates); |
|
332 | + $data = explode("|", $rates); |
|
333 | 333 | |
334 | 334 | $newarray = array(); |
335 | - foreach($data as $key => $value) |
|
335 | + foreach ($data as $key => $value) |
|
336 | 336 | { |
337 | - $data1 = explode(":",$value); |
|
338 | - foreach($data1 as $newkey => $newvalue) |
|
337 | + $data1 = explode(":", $value); |
|
338 | + foreach ($data1 as $newkey => $newvalue) |
|
339 | 339 | { |
340 | 340 | $newarray[$data1[0]] = $data1[$newkey]; |
341 | 341 | } |
@@ -347,16 +347,16 @@ discard block |
||
347 | 347 | function normalize_origination_rate($dataVariable) |
348 | 348 | { |
349 | 349 | $rates = urldecode($dataVariable); |
350 | - $data = explode("|",$rates); |
|
350 | + $data = explode("|", $rates); |
|
351 | 351 | $newarray = array(); |
352 | 352 | $newarray1 = array(); |
353 | - foreach($data as $key => $value) |
|
353 | + foreach ($data as $key => $value) |
|
354 | 354 | { |
355 | - $data1 = explode(":",$value); |
|
356 | - foreach($data1 as $newkey => $newvalue) |
|
355 | + $data1 = explode(":", $value); |
|
356 | + foreach ($data1 as $newkey => $newvalue) |
|
357 | 357 | { |
358 | 358 | $newarray[$data1[0]] = $data1[$newkey]; |
359 | - if($newvalue == "ACCID" ){ |
|
359 | + if ($newvalue == "ACCID") { |
|
360 | 360 | $newarray1[$data1[1]] = $newarray; |
361 | 361 | } |
362 | 362 | } |
@@ -365,13 +365,13 @@ discard block |
||
365 | 365 | } |
366 | 366 | |
367 | 367 | // Calculate cost for billing |
368 | -function calc_cost($dataVariable, $rates, $logger,$decimal_points) |
|
368 | +function calc_cost($dataVariable, $rates, $logger, $decimal_points) |
|
369 | 369 | { |
370 | 370 | //$logger->log(print_r($rates,true)); |
371 | 371 | $duration = $dataVariable['billsec']; |
372 | - $call_cost=0; |
|
372 | + $call_cost = 0; |
|
373 | 373 | $duration -= $rates['INCLUDEDSECONDS']; |
374 | - if ($duration > 0 && ($dataVariable['hangup_cause'] == 'NORMAL_CLEARING' || $dataVariable['hangup_cause'] == 'ALLOTTED_TIMEOUT')) { |
|
374 | + if ($duration > 0 && ($dataVariable['hangup_cause'] == 'NORMAL_CLEARING' || $dataVariable['hangup_cause'] == 'ALLOTTED_TIMEOUT')) { |
|
375 | 375 | |
376 | 376 | $rates['INC'] = ($rates['INC'] == 0) ? 1 : $rates['INC']; |
377 | 377 | $call_cost = $rates['CONNECTIONCOST']; |
@@ -380,46 +380,46 @@ discard block |
||
380 | 380 | |
381 | 381 | if ($billseconds > 0) |
382 | 382 | { |
383 | - $call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60); |
|
383 | + $call_cost += (ceil($billseconds / $rates['INC']) * $rates['INC']) * ($rates['COST'] / 60); |
|
384 | 384 | } |
385 | 385 | } |
386 | - $call_cost = number_format($call_cost,$decimal_points); |
|
386 | + $call_cost = number_format($call_cost, $decimal_points); |
|
387 | 387 | $logger->log("Return cost ".$call_cost); |
388 | 388 | return $call_cost; |
389 | 389 | } |
390 | 390 | |
391 | 391 | // get intial package information |
392 | -function package_calculation($destination_number,$pricelist_id,$duration,$call_direction,$accountid,$db,$logger) |
|
392 | +function package_calculation($destination_number, $pricelist_id, $duration, $call_direction, $accountid, $db, $logger) |
|
393 | 393 | { |
394 | 394 | $package_array = array(); |
395 | - $custom_destination = number_loop($destination_number,"patterns",$db); |
|
395 | + $custom_destination = number_loop($destination_number, "patterns", $db); |
|
396 | 396 | |
397 | 397 | $query = "SELECT * FROM packages as P inner join package_patterns as PKGPTR on P.id = PKGPTR.package_id WHERE ".$custom_destination." AND status = 0 AND pricelist_id = ".$pricelist_id." ORDER BY LENGTH(PKGPTR.patterns) DESC LIMIT 1"; |
398 | 398 | |
399 | 399 | $package_info = $db->run($query); |
400 | - if($package_info){ |
|
400 | + if ($package_info) { |
|
401 | 401 | $package_info = $package_info[0]; |
402 | 402 | |
403 | - if( ($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2") ) { |
|
403 | + if (($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2")) { |
|
404 | 404 | |
405 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
405 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
406 | 406 | |
407 | - if(!$counter_info) { |
|
407 | + if ( ! $counter_info) { |
|
408 | 408 | $Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (".$package_info['package_id'].",".$accountid.")"; |
409 | - $logger->log("Insert Counters : " . $Insert_query); |
|
409 | + $logger->log("Insert Counters : ".$Insert_query); |
|
410 | 410 | $db->run($Insert_Query); |
411 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
411 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | //print_r($counter_info); |
415 | - if ( $package_info['includedseconds'] > ($counter_info['seconds'] )) { |
|
415 | + if ($package_info['includedseconds'] > ($counter_info['seconds'])) { |
|
416 | 416 | $availableseconds = $package_info['includedseconds'] - $counter_info['seconds']; |
417 | 417 | $freeseconds = ($availableseconds >= $duration) ? $duration : $availableseconds; |
418 | 418 | $duration = ($availableseconds >= $duration) ? $duration : $availableseconds; |
419 | - $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds ). " WHERE id = ". $counter_info['id']; |
|
420 | - $logger->log("Update Counters : " . $update_query); |
|
419 | + $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds)." WHERE id = ".$counter_info['id']; |
|
420 | + $logger->log("Update Counters : ".$update_query); |
|
421 | 421 | $db->run($update_query); |
422 | - $package_array['package_id']= $package_info['package_id']; |
|
422 | + $package_array['package_id'] = $package_info['package_id']; |
|
423 | 423 | $package_array['calltype'] = "FREE"; |
424 | 424 | } |
425 | 425 | } |
@@ -428,21 +428,21 @@ discard block |
||
428 | 428 | } |
429 | 429 | |
430 | 430 | // Getting used package minutes in counter table |
431 | -function get_counters($accountid,$package_id,$db,$logger) |
|
431 | +function get_counters($accountid, $package_id, $db, $logger) |
|
432 | 432 | { |
433 | 433 | $query_counter = "SELECT id,seconds FROM counters WHERE accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1"; |
434 | 434 | $counter = $db->run($query_counter); |
435 | - $logger->log("GET Counters : " . $query_counter); |
|
436 | - if($counter) |
|
435 | + $logger->log("GET Counters : ".$query_counter); |
|
436 | + if ($counter) |
|
437 | 437 | return $counter[0]; |
438 | 438 | else |
439 | 439 | return ""; |
440 | 440 | } |
441 | 441 | |
442 | 442 | //Get user info |
443 | -function get_accounts($parent_id,$logger, $db) { |
|
444 | - $query = "SELECT * FROM accounts WHERE id=" . $parent_id; |
|
445 | - $logger->log("GET configuration : " . $query); |
|
443 | +function get_accounts($parent_id, $logger, $db) { |
|
444 | + $query = "SELECT * FROM accounts WHERE id=".$parent_id; |
|
445 | + $logger->log("GET configuration : ".$query); |
|
446 | 446 | $res_user = $db->run($query); |
447 | 447 | return $res_user[0]; |
448 | 448 | } |
@@ -452,27 +452,27 @@ discard block |
||
452 | 452 | { |
453 | 453 | $query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'"; |
454 | 454 | $config = $db->run($query); |
455 | - $logger->log("GET configuration : " . $query); |
|
455 | + $logger->log("GET configuration : ".$query); |
|
456 | 456 | return $config[0]; |
457 | 457 | } |
458 | 458 | |
459 | 459 | // String append prefix for checking rates |
460 | -function number_loop($destination,$field,$db) |
|
460 | +function number_loop($destination, $field, $db) |
|
461 | 461 | { |
462 | - $max_len_prefix = strlen($destination); |
|
462 | + $max_len_prefix = strlen($destination); |
|
463 | 463 | $number_prefix = '('; |
464 | - while ($max_len_prefix > 0) |
|
464 | + while ($max_len_prefix > 0) |
|
465 | 465 | { |
466 | - $number_prefix .= "$field='^".substr($destination,0,$max_len_prefix).".*' OR "; |
|
466 | + $number_prefix .= "$field='^".substr($destination, 0, $max_len_prefix).".*' OR "; |
|
467 | 467 | $max_len_prefix--; |
468 | 468 | } |
469 | - $number_prefix .= "$field='^defaultprefix.*')";//echo $number_prefix;exit; |
|
469 | + $number_prefix .= "$field='^defaultprefix.*')"; //echo $number_prefix;exit; |
|
470 | 470 | return $number_prefix; |
471 | 471 | } |
472 | 472 | |
473 | 473 | //Convert current time to GMT |
474 | 474 | function convert_to_gmt($date) |
475 | 475 | { |
476 | - return gmdate('Y-m-d H:i:s', strtotime($date) ); |
|
476 | + return gmdate('Y-m-d H:i:s', strtotime($date)); |
|
477 | 477 | } |
478 | 478 | ?> |
@@ -30,15 +30,15 @@ |
||
30 | 30 | $this->config = $lib->config; |
31 | 31 | $this->config['log_path'] = "/var/log/astpp/"; |
32 | 32 | if ($this->config['debug'] == '0') |
33 | - $this->fp = fopen($this->config['log_path'] . 'astpp_' . date('Y-m-d') . '.txt', 'a'); |
|
33 | + $this->fp = fopen($this->config['log_path'].'astpp_'.date('Y-m-d').'.txt', 'a'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | function log($log) { |
37 | 37 | if ($this->config['debug'] == '0') { |
38 | 38 | if (is_array($log)) |
39 | - fwrite($this->fp, "[" . date('Y-m-d H:i:s') . "] " . print_r($log, TRUE)); |
|
39 | + fwrite($this->fp, "[".date('Y-m-d H:i:s')."] ".print_r($log, TRUE)); |
|
40 | 40 | else |
41 | - fwrite($this->fp, "[" . date('Y-m-d H:i:s') . "] " . $log . "\n"); |
|
41 | + fwrite($this->fp, "[".date('Y-m-d H:i:s')."] ".$log."\n"); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 |