Passed
Branch v3.5 (f0ef26)
by Samir
36:09
created
web_interface/astpp/application/modules/systems/views/view_systemconf.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -176,35 +176,35 @@
 block discarded – undo
176 176
               <fieldset>
177 177
                <legend> <?=ucfirst($group_title)?></legend>
178 178
                   <div style="width:50%;float:left;">
179
-                    <?php $currency = Common_model::$global_config['system_config']['base_currency'];?>
180
-                    <?php $count=ceil(sizeof($details)/2); $i=0; $class="tleft";?>
181
-                    <?php foreach($details as$key=>$val){ ?>
182
-                          <?php if($count==$i){
179
+                    <?php $currency = Common_model::$global_config['system_config']['base_currency']; ?>
180
+                    <?php $count = ceil(sizeof($details) / 2); $i = 0; $class = "tleft"; ?>
181
+                    <?php foreach ($details as$key=>$val) { ?>
182
+                          <?php if ($count == $i) {
183 183
 							  echo '</div><div style="width:50%;float:left;">';
184
-							  $class="tright";
184
+							  $class = "tright";
185 185
 						  } ?>
186 186
                           <div class="col-md-12">
187 187
                             <div class="<?=$class?>" href='#'>
188
-                            <label class="col-md-5 no-padding"><?php echo $val['display_name'];?> * </label>
189
-                            <?php if(method_exists($this->common,$val['field_type'])){
190
-								$option_array =  $this->common->$val['field_type'](); 
188
+                            <label class="col-md-5 no-padding"><?php echo $val['display_name']; ?> * </label>
189
+                            <?php if (method_exists($this->common, $val['field_type'])) {
190
+								$option_array = $this->common->$val['field_type'](); 
191 191
 								$drpstr = '<select name="'.$val['name'].'" class="col-md-5 form-control selectpicker"  data-live-search="true">';
192
-									  foreach($option_array as $option_key=>$option_val){
193
-										$selected = ($val['value'] == $option_key)? "selected='selected'":"";
192
+									  foreach ($option_array as $option_key=>$option_val) {
193
+										$selected = ($val['value'] == $option_key) ? "selected='selected'" : "";
194 194
 										$drpstr .= '<option value="'.$option_key.'"'.$selected.'>'.$option_val.'</option>';
195 195
 									  }
196 196
 								$drpstr .= '</select>';
197 197
 								echo $drpstr;
198 198
 								unset($drpstr);
199
-							} else{ ?>
200
-								<input name="<?php echo $val['name'] ?>" value='<?php echo isset($val['value'])?$val['value']:''; ?>' size="20" maxlength="100" class="col-md-5 form-control" type="text">
199
+							} else { ?>
200
+								<input name="<?php echo $val['name'] ?>" value='<?php echo isset($val['value']) ? $val['value'] : ''; ?>' size="20" maxlength="100" class="col-md-5 form-control" type="text">
201 201
 						<?php }?>
202
-                              <span class="demo"><?php echo str_replace('smtp',"SMTP",$val['comment']);?></span>
202
+                              <span class="demo"><?php echo str_replace('smtp', "SMTP", $val['comment']); ?></span>
203 203
 
204 204
                             </div>
205 205
                           </div>  
206 206
 
207
-                      <?php $i++;?>
207
+                      <?php $i++; ?>
208 208
                     <?php }?>
209 209
                   </div>
210 210
               </fieldset>
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.db.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
 	private $errorCallbackFunction;
28 28
 	private $errorMsgFormat;
29 29
 	public function __construct($dsn = "", $user = "", $passwd = "") {
30
-		$config = parse_ini_file ( "/var/lib/astpp/astpp-config.conf" );
30
+		$config = parse_ini_file("/var/lib/astpp/astpp-config.conf");
31 31
 		
32
-		$options = array (
32
+		$options = array(
33 33
 				PDO::ATTR_PERSISTENT => true,
34 34
 				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION 
35 35
 		);
36 36
 		
37 37
 		try {
38
-			parent::__construct ( "mysql:host=" . $config ['dbhost'] . ";dbname=" . $config ['dbname'] . "", $config ['dbuser'], $config ['dbpass'], $options );
39
-		} catch ( PDOException $e ) {
38
+			parent::__construct("mysql:host=".$config ['dbhost'].";dbname=".$config ['dbname']."", $config ['dbuser'], $config ['dbpass'], $options);
39
+		} catch (PDOException $e) {
40 40
 			
41
-			$this->error = $e->getMessage ();
41
+			$this->error = $e->getMessage();
42 42
 		}
43 43
 		echo $this->error;
44 44
 	}
@@ -48,39 +48,39 @@  discard block
 block discarded – undo
48 48
 	 * @param string $bind        	
49 49
 	 */
50 50
 	public function cleanup($bind) {
51
-		if (! is_array ( $bind )) {
52
-			if (! empty ( $bind ))
53
-				$bind = array (
51
+		if ( ! is_array($bind)) {
52
+			if ( ! empty ($bind))
53
+				$bind = array(
54 54
 						$bind 
55 55
 				);
56 56
 			else
57
-				$bind = array ();
57
+				$bind = array();
58 58
 		}
59 59
 		return $bind;
60 60
 	}
61 61
 	public function run($sql, $bind = "") {
62
-		$this->sql = trim ( $sql );
63
-		$this->bind = $this->cleanup ( $bind );
62
+		$this->sql = trim($sql);
63
+		$this->bind = $this->cleanup($bind);
64 64
 		$this->error = "";
65 65
 		
66 66
 		try {
67
-			$pdostmt = $this->prepare ( $this->sql );
68
-			if ($pdostmt->execute ( $this->bind ) !== false) {
69
-				if (preg_match ( "/^(" . implode ( "|", array (
67
+			$pdostmt = $this->prepare($this->sql);
68
+			if ($pdostmt->execute($this->bind) !== false) {
69
+				if (preg_match("/^(".implode("|", array(
70 70
 						"select",
71 71
 						"describe",
72 72
 						"pragma" 
73
-				) ) . ") /i", $this->sql ))
74
-					return $pdostmt->fetchAll ( PDO::FETCH_ASSOC );
75
-				elseif (preg_match ( "/^(" . implode ( "|", array (
73
+				)).") /i", $this->sql))
74
+					return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
75
+				elseif (preg_match("/^(".implode("|", array(
76 76
 						"delete",
77 77
 						"insert",
78 78
 						"update" 
79
-				) ) . ") /i", $this->sql ))
80
-					return $pdostmt->rowCount ();
79
+				)).") /i", $this->sql))
80
+					return $pdostmt->rowCount();
81 81
 			}
82
-		} catch ( PDOException $e ) {
83
-			$this->error = $e->getMessage ();
82
+		} catch (PDOException $e) {
83
+			$this->error = $e->getMessage();
84 84
 			return $this->error;
85 85
 		}
86 86
 	}
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.xml.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
 // If module/app not found
25 25
 function xml_not_found() {
26
-	header ( 'Content-Type: text/xml' );
26
+	header('Content-Type: text/xml');
27 27
 	
28 28
 	$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
29 29
 	$xml .= "<document type=\"freeswitch/xml\">\n";
@@ -46,28 +46,28 @@  discard block
 block discarded – undo
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 ip_map.status=0 AND accounts.status=0 AND accounts.deleted=0";
49
-	$logger->log ( "ACL Query : " . $query );
50
-	$res_acl = $db->run ( $query );
51
-	$logger->log ( $res_acl );
49
+	$logger->log("ACL Query : ".$query);
50
+	$res_acl = $db->run($query);
51
+	$logger->log($res_acl);
52 52
 	
53
-	foreach ( $res_acl as $res_acl_key => $res_acl_value ) {
54
-		$xml .= "       <node type=\"allow\" cidr=\"" . $res_acl_value ['ip'] . "\"/>\n";
53
+	foreach ($res_acl as $res_acl_key => $res_acl_value) {
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 );
60
-	$sp_gw = $db->run ( $query );
61
-	$logger->log ( $sp_gw );
59
+	$logger->log("Sofia Gateway Query : ".$query);
60
+	$sp_gw = $db->run($query);
61
+	$logger->log($sp_gw);
62 62
 	
63
-	foreach ( $sp_gw as $sp_gw_key => $sp_gw_value ) {
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 );
66
-		foreach ( $sp_gw_settings as $sp_gw_settings_key => $sp_gw_settings_value ) {
65
+		$sp_gw_settings = json_decode($sp_gw_value ['gateway_data'], true);
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
-				$tmp_ip_arr = explode ( ":", $sp_gw_settings_value );
69
-				if (! filter_var ( $tmp_ip_arr [0], FILTER_VALIDATE_IP ) === false) {
70
-					$xml .= "   <node type=\"allow\" cidr=\"" . $tmp_ip_arr [0] . "/32\"/>\n";
68
+				$tmp_ip_arr = explode(":", $sp_gw_settings_value);
69
+				if ( ! filter_var($tmp_ip_arr [0], FILTER_VALIDATE_IP) === false) {
70
+					$xml .= "   <node type=\"allow\" cidr=\"".$tmp_ip_arr [0]."/32\"/>\n";
71 71
 				}
72 72
 			}
73 73
 		}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	
76 76
 	// For opensips
77 77
 	if ($config ['opensips'] == '0') {
78
-		$xml .= "<node type=\"allow\" cidr=\"" . $config ['opensips_domain'] . "/32\"/>\n";
78
+		$xml .= "<node type=\"allow\" cidr=\"".$config ['opensips_domain']."/32\"/>\n";
79 79
 	}
80 80
 	
81 81
 	$xml .= "       </list>\n";
@@ -83,20 +83,20 @@  discard block
 block discarded – undo
83 83
 	// For loopback
84 84
 	if ($config ['opensips'] == '0') {
85 85
 		$xml .= "<list name=\"loopback.auto\" default=\"allow\">\n";
86
-		$xml .= "<node type=\"allow\" cidr=\"" . $config ['opensips_domain'] . "/32\"/>\n";
86
+		$xml .= "<node type=\"allow\" cidr=\"".$config ['opensips_domain']."/32\"/>\n";
87 87
 		$xml .= "</list>\n";
88 88
 	}
89 89
 	
90 90
 	// For event handing
91 91
 	$xml .= "<list name=\"event\" default=\"deny\">\n";
92
-	$xml .= ($config ['opensips'] == "0") ? "<node type=\"allow\" cidr=\"" . $config ['opensips_domain'] . "/32\"/>\n" : "\n";
92
+	$xml .= ($config ['opensips'] == "0") ? "<node type=\"allow\" cidr=\"".$config ['opensips_domain']."/32\"/>\n" : "\n";
93 93
 	$xml .= "<node type=\"allow\" cidr=\"127.0.0.0/8\"/>\n";
94 94
 	$xml .= "</list>\n";
95 95
 	$xml .= "           </network-lists>\n";
96 96
 	$xml .= "       </configuration>\n";
97 97
 	$xml .= "   </section>\n";
98 98
 	$xml .= "</document>\n";
99
-	$logger->log ( $xml );
99
+	$logger->log($xml);
100 100
 	return $xml;
101 101
 }
102 102
 
@@ -109,18 +109,18 @@  discard block
 block discarded – undo
109 109
 	$xml .= "   <profiles>\n";
110 110
 	
111 111
 	$query = "SELECT * FROM sip_profiles WHERE status=0";
112
-	$logger->log ( "Sofia Query : " . $query );
113
-	$res_sp = $db->run ( $query );
112
+	$logger->log("Sofia Query : ".$query);
113
+	$res_sp = $db->run($query);
114 114
 	// $logger->log($res_sp);
115 115
 	
116
-	foreach ( $res_sp as $sp_key => $sp_value ) {
116
+	foreach ($res_sp as $sp_key => $sp_value) {
117 117
 		
118
-		$settings = json_decode ( $sp_value ['profile_data'], true );
118
+		$settings = json_decode($sp_value ['profile_data'], true);
119 119
 		// $logger->log(print_r($settings,true));
120
-		$xml .= "   <profile name=\"" . $sp_value ['name'] . "\">\n";
120
+		$xml .= "   <profile name=\"".$sp_value ['name']."\">\n";
121 121
 		
122 122
 		$xml .= "   <domains>\n";
123
-		$xml .= "       <domain name=\"" . $sp_value ['sip_ip'] . "\" alias=\"true\" parse=\"true\"/>\n";
123
+		$xml .= "       <domain name=\"".$sp_value ['sip_ip']."\" alias=\"true\" parse=\"true\"/>\n";
124 124
 		$xml .= "   </domains>\n";
125 125
 		/*
126 126
 		 * $xml .= " <aliases>\n";
@@ -129,26 +129,26 @@  discard block
 block discarded – undo
129 129
 		 */
130 130
 		
131 131
 		$xml .= "   <settings>\n";
132
-		$xml .= "       <param name=\"sip-ip\" value=\"" . $sp_value ['sip_ip'] . "\"/>\n";
133
-		$xml .= "       <param name=\"sip-port\" value=\"" . $sp_value ['sip_port'] . "\"/>\n";
134
-		foreach ( $settings as $set_key => $set_val ) {
135
-			$xml .= "       <param name=\"" . $set_key . "\" value=\"" . $set_val . "\"/>\n";
132
+		$xml .= "       <param name=\"sip-ip\" value=\"".$sp_value ['sip_ip']."\"/>\n";
133
+		$xml .= "       <param name=\"sip-port\" value=\"".$sp_value ['sip_port']."\"/>\n";
134
+		foreach ($settings as $set_key => $set_val) {
135
+			$xml .= "       <param name=\"".$set_key."\" value=\"".$set_val."\"/>\n";
136 136
 		}
137 137
 		$xml .= "   </settings>\n";
138 138
 		
139 139
 		// Gateway block start
140 140
 		$xml .= "   <gateways>\n";
141
-		$query = "SELECT * FROM gateways WHERE sip_profile_id=" . $sp_value ['id'] . " AND status=0";
142
-		$logger->log ( "Sofia Gateway Query : " . $query );
143
-		$sp_gw = $db->run ( $query );
144
-		$logger->log ( $sp_gw );
145
-		foreach ( $sp_gw as $sp_gw_key => $sp_gw_value ) {
146
-			$xml .= "       <gateway name=\"" . $sp_gw_value ['name'] . "\">\n";
141
+		$query = "SELECT * FROM gateways WHERE sip_profile_id=".$sp_value ['id']." AND status=0";
142
+		$logger->log("Sofia Gateway Query : ".$query);
143
+		$sp_gw = $db->run($query);
144
+		$logger->log($sp_gw);
145
+		foreach ($sp_gw as $sp_gw_key => $sp_gw_value) {
146
+			$xml .= "       <gateway name=\"".$sp_gw_value ['name']."\">\n";
147 147
 			
148
-			$sp_gw_settings = json_decode ( $sp_gw_value ['gateway_data'], true );
149
-			foreach ( $sp_gw_settings as $sp_gw_settings_key => $sp_gw_settings_value ) {
148
+			$sp_gw_settings = json_decode($sp_gw_value ['gateway_data'], true);
149
+			foreach ($sp_gw_settings as $sp_gw_settings_key => $sp_gw_settings_value) {
150 150
 				if ($sp_gw_settings_value != "")
151
-					$xml .= "           <param name=\"" . $sp_gw_settings_key . "\" value=\"" . $sp_gw_settings_value . "\"/>\n";
151
+					$xml .= "           <param name=\"".$sp_gw_settings_key."\" value=\"".$sp_gw_settings_value."\"/>\n";
152 152
 			}
153 153
 			$xml .= "       </gateway>\n";
154 154
 		}
@@ -162,47 +162,47 @@  discard block
 block discarded – undo
162 162
 	$xml .= "   </configuration>\n";
163 163
 	$xml .= "   </section>\n";
164 164
 	$xml .= "</document>\n";
165
-	$logger->log ( $xml );
165
+	$logger->log($xml);
166 166
 	return $xml;
167 167
 }
168 168
 function update_vm_data($logger, $db, $password, $user) {
169
-	$query = "SELECT * FROM sip_devices where username='" . $_REQUEST ['user'] . "' limit 1";
170
-	$logger->log ( "Directory Query : " . $query );
171
-	$res_dir = $db->run ( $query );
172
-	$params = json_decode ( $res_dir [0] ['dir_params'], true );
169
+	$query = "SELECT * FROM sip_devices where username='".$_REQUEST ['user']."' limit 1";
170
+	$logger->log("Directory Query : ".$query);
171
+	$res_dir = $db->run($query);
172
+	$params = json_decode($res_dir [0] ['dir_params'], true);
173 173
 	$params ['vm-password'] = $password;
174 174
 	
175
-	$query = "update sip_devices set dir_params = '" . json_encode ( $params, true ) . "' where username='" . $_REQUEST ['user'] . "' limit 1";
176
-	$res_dir = $db->run ( $query );
175
+	$query = "update sip_devices set dir_params = '".json_encode($params, true)."' where username='".$_REQUEST ['user']."' limit 1";
176
+	$res_dir = $db->run($query);
177 177
 }
178 178
 
179 179
 // Build directory xml
180 180
 function load_directory($logger, $db) {
181 181
 	$xml = "";
182 182
 	
183
-	$query = "SELECT username,dir_params,dir_vars,number as accountcode,accountid FROM sip_devices,accounts WHERE sip_devices.status=0 AND accounts.status=0 AND accounts.deleted=0 AND accounts.id=sip_devices.accountid AND username='" . $_REQUEST ['user'] . "' limit 1";
183
+	$query = "SELECT username,dir_params,dir_vars,number as accountcode,accountid FROM sip_devices,accounts WHERE sip_devices.status=0 AND accounts.status=0 AND accounts.deleted=0 AND accounts.id=sip_devices.accountid AND username='".$_REQUEST ['user']."' limit 1";
184 184
 	
185
-	$logger->log ( "Directory Query : " . $query );
186
-	$res_dir = $db->run ( $query );
187
-	$logger->log ( $res_dir );
185
+	$logger->log("Directory Query : ".$query);
186
+	$res_dir = $db->run($query);
187
+	$logger->log($res_dir);
188 188
 	
189
-	foreach ( $res_dir as $res_dir_key => $res_dir_value ) {
189
+	foreach ($res_dir as $res_dir_key => $res_dir_value) {
190 190
 		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
191 191
 		$xml .= "<document type=\"freeswitch/xml\">\n";
192 192
 		$xml .= "   <section name=\"Directory\" description=\"Directory\">\n";
193
-		$xml .= "       <domain name=\"" . $_REQUEST ['domain'] . "\" alias=\"true\">\n";
194
-		$xml .= "           <user id=\"" . $_REQUEST ['user'] . "\">\n";
193
+		$xml .= "       <domain name=\"".$_REQUEST ['domain']."\" alias=\"true\">\n";
194
+		$xml .= "           <user id=\"".$_REQUEST ['user']."\">\n";
195 195
 		
196
-		$params = json_decode ( $res_dir_value ['dir_params'], true );
196
+		$params = json_decode($res_dir_value ['dir_params'], true);
197 197
 		
198
-		$vars = json_decode ( $res_dir_value ['dir_vars'], true );
198
+		$vars = json_decode($res_dir_value ['dir_vars'], true);
199 199
 		$param_xml = $var_xml = "";
200
-		foreach ( $params as $parms_key => $res_dir_params ) {
201
-			$param_xml .= "<param name=\"" . $parms_key . "\" value=\"" . $res_dir_params . "\"/>\n";
200
+		foreach ($params as $parms_key => $res_dir_params) {
201
+			$param_xml .= "<param name=\"".$parms_key."\" value=\"".$res_dir_params."\"/>\n";
202 202
 		}
203 203
 		
204
-		foreach ( $vars as $var_key => $res_dir_vars ) {
205
-			$var_xml .= "<variable name=\"" . $var_key . "\" value=\"" . $res_dir_vars . "\"/>\n";
204
+		foreach ($vars as $var_key => $res_dir_vars) {
205
+			$var_xml .= "<variable name=\"".$var_key."\" value=\"".$res_dir_vars."\"/>\n";
206 206
 		}
207 207
 		
208 208
 		$xml .= "               <params>\n";
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
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";
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		$xml .= "</document>\n";
225 225
 	}
226 226
 	
227
-	$logger->log ( $xml );
227
+	$logger->log($xml);
228 228
 	return $xml;
229 229
 }
230 230
 
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.logger.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,20 +28,20 @@
 block discarded – undo
28 28
 		// $this->config['log_path'] = "/var/log/astpp/";
29 29
 		if ($this->config ['debug'] == '0') {
30 30
 			// $this->fp = fopen($this->config['log_path'] . 'astpp_' . date('Y-m-d') . '.txt', 'a+');
31
-			$this->fp = fopen ( $this->config ['log_path'] . 'astpp.log', 'a+' );
31
+			$this->fp = fopen($this->config ['log_path'].'astpp.log', 'a+');
32 32
 		}
33 33
 	}
34 34
 	function log($log) {
35 35
 		if ($this->config ['debug'] == '0') {
36
-			if (is_array ( $log ))
37
-				fwrite ( $this->fp, "[" . date ( 'Y-m-d H:i:s' ) . "] " . print_r ( $log, TRUE ) );
36
+			if (is_array($log))
37
+				fwrite($this->fp, "[".date('Y-m-d H:i:s')."] ".print_r($log, TRUE));
38 38
 			else
39
-				fwrite ( $this->fp, "[" . date ( 'Y-m-d H:i:s' ) . "] " . $log . "\n" );
39
+				fwrite($this->fp, "[".date('Y-m-d H:i:s')."] ".$log."\n");
40 40
 		}
41 41
 	}
42 42
 	function close() {
43 43
 		if ($this->config ['debug'] == '0')
44
-			fclose ( $this->fp );
44
+			fclose($this->fp);
45 45
 	}
46 46
 }
47 47
 
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.cdr.php 1 patch
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 	// $logger->log(print_r($data,true));//exit;
27 27
 	
28 28
 	// Initializing variables
29
-	$origination_rate = array ();
30
-	$termination_rate = array ();
29
+	$origination_rate = array();
30
+	$termination_rate = array();
31 31
 	
32 32
 	// FS CDR variables
33 33
 	$dataVariable = $data ['variables'];
@@ -36,21 +36,21 @@  discard block
 block discarded – undo
36 36
 	$dataCallflow = $data ['callflow'];
37 37
 	
38 38
 	// Get account id
39
-	$accountid = isset ( $dataVariable ['account_id'] ) ? $dataVariable ['account_id'] : '0';
39
+	$accountid = isset ($dataVariable ['account_id']) ? $dataVariable ['account_id'] : '0';
40 40
 	
41 41
 	// Get caller id name and number
42
-	$dataVariable ['effective_caller_id_name'] = (isset ( $dataVariable ['effective_caller_id_name'] )) ? $dataVariable ['effective_caller_id_name'] : $dataCallflow ['caller_profile'] ['caller_id_name'];
43
-	$dataVariable ['effective_caller_id_number'] = (isset ( $dataVariable ['effective_caller_id_number'] )) ? $dataVariable ['effective_caller_id_number'] : $dataCallflow ['caller_profile'] ['caller_id_number'];
42
+	$dataVariable ['effective_caller_id_name'] = (isset ($dataVariable ['effective_caller_id_name'])) ? $dataVariable ['effective_caller_id_name'] : $dataCallflow ['caller_profile'] ['caller_id_name'];
43
+	$dataVariable ['effective_caller_id_number'] = (isset ($dataVariable ['effective_caller_id_number'])) ? $dataVariable ['effective_caller_id_number'] : $dataCallflow ['caller_profile'] ['caller_id_number'];
44 44
 	
45 45
 	if ($dataVariable ['billsec'] == 0 && $dataVariable ['hangup_cause'] == 'NORMAL_CLEARING') {
46
-		$hangup_cause = isset ( $dataVariable ['last_bridge_hangup_cause'] ) ? $dataVariable ['last_bridge_hangup_cause'] : $dataVariable ['hangup_cause'];
46
+		$hangup_cause = isset ($dataVariable ['last_bridge_hangup_cause']) ? $dataVariable ['last_bridge_hangup_cause'] : $dataVariable ['hangup_cause'];
47 47
 	} else {
48 48
 		$hangup_cause = $dataVariable ['hangup_cause'];
49 49
 	}
50 50
 	
51 51
 	if ($dataVariable ['error_cdr'] == '1') {
52 52
 		// Get actual hangup cause
53
-		$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']);
53
+		$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']);
54 54
 	}
55 55
 	
56 56
 	/* #### PATCH FOR ONE WAY AUDIO #### */
@@ -72,116 +72,116 @@  discard block
 block discarded – undo
72 72
 	 * }
73 73
 	 */
74 74
 	
75
-	$account_type = (isset ( $dataVariable ['entity_id'] )) ? $dataVariable ['entity_id'] : '0';
76
-	$parentid = isset ( $dataVariable ['parent_id'] ) ? $dataVariable ['parent_id'] : '0';
75
+	$account_type = (isset ($dataVariable ['entity_id'])) ? $dataVariable ['entity_id'] : '0';
76
+	$parentid = isset ($dataVariable ['parent_id']) ? $dataVariable ['parent_id'] : '0';
77 77
 	$parent_cost = 0;
78 78
 	$cost = 0;
79 79
 	$dataVariable ['package_id'] = 0;
80 80
 	$actual_duration = $dataVariable ['billsec'];
81
-	$dataVariable ['calltype'] = isset ( $dataVariable ['calltype'] ) ? $dataVariable ['calltype'] : "STANDARD";
81
+	$dataVariable ['calltype'] = isset ($dataVariable ['calltype']) ? $dataVariable ['calltype'] : "STANDARD";
82 82
 	$actual_calltype = $dataVariable ['calltype'];
83 83
 	
84 84
 	// Normalize origination and termination rates array
85
-	if (isset ( $dataVariable ['origination_rates'] ))
86
-		$origination_rate = normalize_origination_rate ( $dataVariable ['origination_rates'] );
87
-	if (isset ( $dataVariable ['termination_rates'] ))
88
-		$termination_rate = normalize_rate ( $dataVariable ['termination_rates'] );
85
+	if (isset ($dataVariable ['origination_rates']))
86
+		$origination_rate = normalize_origination_rate($dataVariable ['origination_rates']);
87
+	if (isset ($dataVariable ['termination_rates']))
88
+		$termination_rate = normalize_rate($dataVariable ['termination_rates']);
89 89
 		
90 90
 		// If receiver account id found then explicitly set call direction and call type
91
-	if (isset ( $dataVariable ['receiver_accid'] )) {
91
+	if (isset ($dataVariable ['receiver_accid'])) {
92 92
 		$dataVariable ['call_direction'] = "outbound";
93 93
 		$dataVariable ['calltype'] = "STANDARD";
94 94
 	}
95 95
 	
96 96
 	// Check if cusotmer have any package seconds left to use
97 97
 	if ($actual_duration > 0) {
98
-		$package_array = package_calculation ( $dataVariable ['effective_destination_number'], $origination_rate [$accountid] ['RATEGROUP'], $actual_duration, $dataVariable ['call_direction'], $accountid, $db, $logger );
99
-		if (! empty ( $package_array )) {
98
+		$package_array = package_calculation($dataVariable ['effective_destination_number'], $origination_rate [$accountid] ['RATEGROUP'], $actual_duration, $dataVariable ['call_direction'], $accountid, $db, $logger);
99
+		if ( ! empty ($package_array)) {
100 100
 			$dataVariable ['calltype'] = "FREE";
101 101
 			$dataVariable ['package_id'] = $package_array ['package_id'];
102 102
 		}
103 103
 	}
104 104
 	
105 105
 	// Calculate debit of customer call
106
-	$debit = calc_cost ( $dataVariable, $origination_rate [$accountid], $logger, $decimal_points );
106
+	$debit = calc_cost($dataVariable, $origination_rate [$accountid], $logger, $decimal_points);
107 107
 	
108 108
 	// Calculate cost for customer call for provider
109
-	$provider_cost = calc_cost ( $dataVariable, $termination_rate, $logger, $decimal_points );
109
+	$provider_cost = calc_cost($dataVariable, $termination_rate, $logger, $decimal_points);
110 110
 	
111 111
 	// Calculate parent cost if customer have any parent
112
-	$parent_cost = ($parentid > 0) ? calc_cost ( $dataVariable, $origination_rate [$parentid], $logger, $decimal_points ) : $provider_cost;
113
-	$logger->log ( "Debit :" . $debit . " Cost : " . $cost . " Provider Cost : " . $parent_cost );
112
+	$parent_cost = ($parentid > 0) ? calc_cost ($dataVariable, $origination_rate [$parentid], $logger, $decimal_points) : $provider_cost;
113
+	$logger->log("Debit :".$debit." Cost : ".$cost." Provider Cost : ".$parent_cost);
114 114
 	
115 115
 	// Initialize final cost variable to use for billing
116 116
 	$cost = ($parent_cost > 0) ? $parent_cost : $provider_cost;
117 117
 	
118 118
 	// Outbound call entry for all type of calls
119
-	$logger->log ( "*********************** OUTBOUND CALL ENTRY START *************" );
119
+	$logger->log("*********************** OUTBOUND CALL ENTRY START *************");
120 120
 	
121
-	$cdr_string = get_cdr_string ( $dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger );
121
+	$cdr_string = get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger);
122 122
 	
123 123
 	$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)";
124
-	$logger->log ( $query );
125
-	$db->run ( $query );
124
+	$logger->log($query);
125
+	$db->run($query);
126 126
 	
127 127
 	// Update customer balance
128 128
 	if ($debit > 0 && $dataVariable ['calltype'] != "FREE") {
129
-		update_balance ( $accountid, $debit, 0, $logger, $db );
129
+		update_balance($accountid, $debit, 0, $logger, $db);
130 130
 	}
131 131
 	
132 132
 	// Update parent or provider balance
133 133
 	if ($parent_cost > 0) {
134
-		update_balance ( $termination_rate ['PROVIDER'], ($parent_cost * - 1), 3, $logger, $db );
134
+		update_balance($termination_rate ['PROVIDER'], ($parent_cost * - 1), 3, $logger, $db);
135 135
 	}
136 136
 	
137 137
 	// Resellers CDR entry
138 138
 	$flag_parent = false;
139
-	insert_parent_data ( $dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points );
139
+	insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points);
140 140
 	
141
-	$logger->log ( "*********************** OUTBOUND CALL ENTRY END *************" );
141
+	$logger->log("*********************** OUTBOUND CALL ENTRY END *************");
142 142
 	
143 143
 	// ************ ADDING EXTRA ENTRY For local/DID Inbound call ****************************
144 144
 	$receiver_parentid = 0;
145
-	if (isset ( $dataVariable ['receiver_accid'] ) && $dataVariable ['receiver_accid'] != "") {
146
-		$logger->log ( "*********************** EXTRA ENTRY SECTION FOR BILLING START *************" );
145
+	if (isset ($dataVariable ['receiver_accid']) && $dataVariable ['receiver_accid'] != "") {
146
+		$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************");
147 147
 		
148 148
 		// Explicitly set call direction and call type
149 149
 		$dataVariable ['call_direction'] = "inbound";
150 150
 		$dataVariable ['calltype'] = "DID";
151 151
 		// For inbound package calculation
152 152
 		if ($actual_duration > 0) {
153
-			$package_array = package_calculation ( $dataVariable ['effective_destination_number'], $origination_rate [$accountid] ['RATEGROUP'], $actual_duration, $dataVariable ['call_direction'], $accountid, $db, $logger );
154
-			if (! empty ( $package_array )) {
153
+			$package_array = package_calculation($dataVariable ['effective_destination_number'], $origination_rate [$accountid] ['RATEGROUP'], $actual_duration, $dataVariable ['call_direction'], $accountid, $db, $logger);
154
+			if ( ! empty ($package_array)) {
155 155
 				$dataVariable ['calltype'] = "FREE";
156 156
 				$dataVariable ['package_id'] = $package_array ['package_id'];
157 157
 			}
158 158
 		}
159 159
 		// Override variables if call for DID PSTN
160
-		if (isset ( $dataVariable ['caller_did_account_id'] )) {
160
+		if (isset ($dataVariable ['caller_did_account_id'])) {
161 161
 			$dataVariable ['receiver_accid'] = $dataVariable ['caller_did_account_id'];
162 162
 			$dataVariable ['call_direction'] = "outbound";
163 163
 			$dataVariable ['calltype'] = "STANDARD";
164 164
 			$dataVariable ['effective_destination_number'] = $dataVariable ['sip_to_user'];
165
-			unset ( $termination_rate );
166
-			unset ( $provider_cost );
165
+			unset ($termination_rate);
166
+			unset ($provider_cost);
167 167
 		}
168 168
 		
169 169
 		// Get call receiver account information
170
-		$receiver_carddata = get_accounts ( $dataVariable ['receiver_accid'], $logger, $db );
170
+		$receiver_carddata = get_accounts($dataVariable ['receiver_accid'], $logger, $db);
171 171
 		$receiver_parentid = $receiver_carddata ['reseller_id'];
172 172
 		
173 173
 		// For additional cdr entry of receiver
174
-		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 );
174
+		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);
175 175
 		
176 176
 		$flag_parent = true;
177
-		$dataVariable ['uuid'] = $dataVariable ['uuid'] . $dataVariable ['calltype'] . "_" . $receiver_parentid;
177
+		$dataVariable ['uuid'] = $dataVariable ['uuid'].$dataVariable ['calltype']."_".$receiver_parentid;
178 178
 		
179 179
 		// Insert parent reseller cdr
180
-		insert_parent_data ( $dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points );
181
-		$logger->log ( "*********************** EXTRA ENTRY SECTION FOR BILLING END *************" );
180
+		insert_parent_data($dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points);
181
+		$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************");
182 182
 	}
183 183
 	// *****************************************************************************************
184
-	$logger->log ( "*************************** CDR ends ********************************" );
184
+	$logger->log("*************************** CDR ends ********************************");
185 185
 }
186 186
 
187 187
 // Insert parent resellers cdr
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
  * @param boolean $flag_parent        	
192 192
  */
193 193
 function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points) {
194
-	while ( $parentid > 0 ) {
195
-		$logger->log ( "*************** IN PARENT DATA SECTION ********" );
194
+	while ($parentid > 0) {
195
+		$logger->log("*************** IN PARENT DATA SECTION ********");
196 196
 		$dataVariable ['calltype'] = $actual_calltype;
197
-		$carddata = get_accounts ( $parentid, $logger, $db );
197
+		$carddata = get_accounts($parentid, $logger, $db);
198 198
 		$accountid = $carddata ['id'];
199 199
 		
200
-		$debit = calc_cost ( $dataVariable, $origination_rate [$accountid], $logger, $decimal_points );
200
+		$debit = calc_cost($dataVariable, $origination_rate [$accountid], $logger, $decimal_points);
201 201
 		
202 202
 		// If receiver account id found then explicitly set call direction and call type
203 203
 		/*
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 		
211 211
 		// Check if reseller have any package seconds left to use
212 212
 		if ($actual_duration > 0) {
213
-			$package_array = package_calculation ( $dataVariable ['effective_destination_number'], $origination_rate [$accountid] ['RATEGROUP'], $actual_duration, $dataVariable ['call_direction'], $accountid, $db, $logger );
214
-			if (! empty ( $package_array )) {
213
+			$package_array = package_calculation($dataVariable ['effective_destination_number'], $origination_rate [$accountid] ['RATEGROUP'], $actual_duration, $dataVariable ['call_direction'], $accountid, $db, $logger);
214
+			if ( ! empty ($package_array)) {
215 215
 				$dataVariable ['calltype'] = "FREE";
216 216
 				$dataVariable ['package_id'] = $package_array ['package_id'];
217 217
 			}
@@ -219,27 +219,27 @@  discard block
 block discarded – undo
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) {
226
-			$logger->log ( "********* IN RESELLER FOR RECEIVER ENTRY START ******" );
225
+		if (isset ($dataVariable ['receiver_accid']) && $dataVariable ['receiver_accid'] != "" && $flag_parent == true) {
226
+			$logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******");
227 227
 			$flag_parent = true;
228
-			insert_extra_receiver_entry ( $dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points );
229
-			$logger->log ( "********* IN RESELLER FOR RECEIVER ENTRY END ******" );
228
+			insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points);
229
+			$logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******");
230 230
 			return true;
231 231
 		} else {
232 232
 			
233
-			$cdr_string = get_reseller_cdr_string ( $dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost );
233
+			$cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost);
234 234
 			
235 235
 			$query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost,
236 236
 		reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)";
237
-			$logger->log ( $query );
238
-			$db->run ( $query );
237
+			$logger->log($query);
238
+			$db->run($query);
239 239
 			
240 240
 			// Update reseller balance
241 241
 			if ($debit > 0 && $dataVariable ['calltype'] != "FREE") {
242
-				update_balance ( $accountid, $debit, 0, $logger, $db );
242
+				update_balance($accountid, $debit, 0, $logger, $db);
243 243
 			}
244 244
 		}
245 245
 		//return true;
@@ -255,26 +255,26 @@  discard block
 block discarded – undo
255 255
 function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points) {
256 256
 	$localVariable = $dataVariable;
257 257
 	$localVariable ['call_direction'] = "inbound";
258
-	$localVariable ['uuid'] = $localVariable ['uuid'] . $dataVariable ['calltype'] . "_" . $accountid;
258
+	$localVariable ['uuid'] = $localVariable ['uuid'].$dataVariable ['calltype']."_".$accountid;
259 259
 	
260 260
 	if ($dataVariable ['calltype'] == "LOCAL") {
261 261
 		$origination_rate [$accountid] ['CODE'] = $dataVariable ['effective_destination_number'];
262 262
 		$origination_rate [$accountid] ['DESTINATION'] = $dataVariable ['calltype'];
263 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 );
264
+			$cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, 0, 0, $logger);
265 265
 		} else {
266
-			$cdr_string = get_reseller_cdr_string ( $dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost );
266
+			$cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost);
267 267
 		}
268 268
 	} else {
269 269
 		
270
-		$origination_rate_did = normalize_origination_rate ( $dataVariable ['origination_rates_did'] );
271
-		$debit = calc_cost ( $dataVariable, $origination_rate_did [$accountid], $logger, $decimal_points );
270
+		$origination_rate_did = normalize_origination_rate($dataVariable ['origination_rates_did']);
271
+		$debit = calc_cost($dataVariable, $origination_rate_did [$accountid], $logger, $decimal_points);
272 272
 		
273 273
 		if ($flag_parent == false) {
274 274
 			
275
-			$cdr_string = get_cdr_string ( $localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger );
275
+			$cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger);
276 276
 		} else {
277
-			$cdr_string = get_reseller_cdr_string ( $dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost );
277
+			$cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost);
278 278
 		}
279 279
 	}
280 280
 	
@@ -285,11 +285,11 @@  discard block
 block discarded – undo
285 285
 	reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)";
286 286
 	}
287 287
 	
288
-	$logger->log ( $query );
289
-	$db->run ( $query );
288
+	$logger->log($query);
289
+	$db->run($query);
290 290
 	
291 291
 	if ($debit > 0 && ($dataVariable ['calltype'] != "FREE" && $dataVariable ['calltype'] != "LOCAL")) {
292
-		update_balance ( $accountid, $debit, 0, $logger, $db );
292
+		update_balance($accountid, $debit, 0, $logger, $db);
293 293
 	}
294 294
 	return true;
295 295
 }
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 function get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger) {
299 299
 	$dataVariable ['calltype'] = ($dataVariable ['calltype'] == 'DID-LOCAL' || $dataVariable ['calltype'] == 'SIP-DID' || $dataVariable ['calltype'] == 'OTHER') ? "DID" : $dataVariable ['calltype'];
300 300
 	// $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id'];
301
-	$callerIdNumber = ($dataVariable ['calltype'] == "DID") ? $dataVariable ['effective_caller_id_name'] . " <" . $dataVariable ['effective_caller_id_number'] . ">" : $dataVariable ['original_caller_id_name'] . " <" . $dataVariable ['original_caller_id_number'] . ">";
301
+	$callerIdNumber = ($dataVariable ['calltype'] == "DID") ? $dataVariable ['effective_caller_id_name']." <".$dataVariable ['effective_caller_id_number'].">" : $dataVariable ['original_caller_id_name']." <".$dataVariable ['original_caller_id_number'].">";
302 302
 	
303
-	return $cdr_string = "'" . ($dataVariable ['uuid']) . "','" . $accountid . "','" . $account_type . "','" . (urldecode ( $callerIdNumber )) . "','" . ($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' . "'") . ",'" . $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'] . "'" : "'" . '' . "'") . "," . (($termination_rate ['DESTINATION']) ? "'" . $termination_rate ['DESTINATION'] . "'" : "'" . '' . "'") . "," . (($termination_rate ['COST']) ? "'" . $termination_rate ['COST'] . "'" : '0') . ",'" . $provider_cost . "'," . (($dataVariable ['call_direction']) ? "'" . $dataVariable ['call_direction'] . "'" : "'internal'") . ",'" . ($dataVariable ['calltype']) . "','" . urldecode ( $dataVariable ['profile_start_stamp'] ) . "','" . urldecode ( $dataVariable ['answer_stamp'] ) . "','" . urldecode ( $dataVariable ['bridge_stamp'] ) . "','" . urldecode ( @$dataVariable ['progress_stamp'] ) . "','" . urldecode ( @$dataVariable ['progress_media_stamp'] ) . "','" . urldecode ( $dataVariable ['end_stamp'] ) . "'," . $dataVariable ['billmsec'] . ",'" . $dataVariable ['answermsec'] . "','" . $dataVariable ['waitmsec'] . "','" . $dataVariable ['progress_mediamsec'] . "','" . $dataVariable ['flow_billmsec'] . "'";
303
+	return $cdr_string = "'".($dataVariable ['uuid'])."','".$accountid."','".$account_type."','".(urldecode($callerIdNumber))."','".($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'."'").",'".$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']."'" : "'".''."'").",".(($termination_rate ['DESTINATION']) ? "'".$termination_rate ['DESTINATION']."'" : "'".''."'").",".(($termination_rate ['COST']) ? "'".$termination_rate ['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable ['call_direction']) ? "'".$dataVariable ['call_direction']."'" : "'internal'").",'".($dataVariable ['calltype'])."','".urldecode($dataVariable ['profile_start_stamp'])."','".urldecode($dataVariable ['answer_stamp'])."','".urldecode($dataVariable ['bridge_stamp'])."','".urldecode(@$dataVariable ['progress_stamp'])."','".urldecode(@$dataVariable ['progress_media_stamp'])."','".urldecode($dataVariable ['end_stamp'])."',".$dataVariable ['billmsec'].",'".$dataVariable ['answermsec']."','".$dataVariable ['waitmsec']."','".$dataVariable ['progress_mediamsec']."','".$dataVariable ['flow_billmsec']."'";
304 304
 }
305 305
 
306 306
 // Generate CDR string for insert query for reseller
307 307
 function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost) {
308 308
 	$dataVariable ['calltype'] = ($dataVariable ['calltype'] == 'DID-LOCAL' || $dataVariable ['calltype'] == 'SIP-DID' || $dataVariable ['calltype'] == 'OTHER') ? "DID" : $dataVariable ['calltype'];
309 309
 	// $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id'];
310
-	$callerIdNumber = ($dataVariable ['calltype'] == "DID") ? $dataVariable ['effective_caller_id_name'] . " <" . $dataVariable ['effective_caller_id_number'] . ">" : $dataVariable ['original_caller_id_name'] . " <" . $dataVariable ['original_caller_id_number'] . ">";
310
+	$callerIdNumber = ($dataVariable ['calltype'] == "DID") ? $dataVariable ['effective_caller_id_name']." <".$dataVariable ['effective_caller_id_number'].">" : $dataVariable ['original_caller_id_name']." <".$dataVariable ['original_caller_id_number'].">";
311 311
 	
312
-	return $cdr_string = "'" . ($dataVariable ['uuid']) . "','" . $accountid . "','" . (urldecode ( $callerIdNumber )) . "','" . ($dataVariable ['effective_destination_number']) . "','" . $actual_duration . "','" . ($dataVariable ['hangup_cause']) . "','" . 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']) . "'";
312
+	return $cdr_string = "'".($dataVariable ['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable ['effective_destination_number'])."','".$actual_duration."','".($dataVariable ['hangup_cause'])."','".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'])."'";
313 313
 }
314 314
 
315 315
 // Update user balance
@@ -319,20 +319,20 @@  discard block
 block discarded – undo
319 319
  */
320 320
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
321 321
 	$math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
322
-	$query = "UPDATE accounts SET balance=IF(posttoexternal=1,balance+" . $amount . ",balance-" . $amount . ") WHERE id=" . $user_id;
323
-	$logger->log ( "Balance update : " . $query );
324
-	$db->run ( $query );
322
+	$query = "UPDATE accounts SET balance=IF(posttoexternal=1,balance+".$amount.",balance-".$amount.") WHERE id=".$user_id;
323
+	$logger->log("Balance update : ".$query);
324
+	$db->run($query);
325 325
 }
326 326
 
327 327
 // Normalize rate string which we are getting from dialplan
328 328
 function normalize_rate($dataVariable) {
329
-	$rates = urldecode ( $dataVariable );
330
-	$data = explode ( "|", $rates );
329
+	$rates = urldecode($dataVariable);
330
+	$data = explode("|", $rates);
331 331
 	
332
-	$newarray = array ();
333
-	foreach ( $data as $key => $value ) {
334
-		$data1 = explode ( ":", $value );
335
-		foreach ( $data1 as $newkey => $newvalue ) {
332
+	$newarray = array();
333
+	foreach ($data as $key => $value) {
334
+		$data1 = explode(":", $value);
335
+		foreach ($data1 as $newkey => $newvalue) {
336 336
 			$newarray [$data1 [0]] = $data1 [$newkey];
337 337
 		}
338 338
 	}
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
 
342 342
 // Normalize originaion rate string which we are getting from dialplan
343 343
 function normalize_origination_rate($dataVariable) {
344
-	$rates = urldecode ( $dataVariable );
345
-	$data = explode ( "|", $rates );
346
-	$newarray = array ();
347
-	$newarray1 = array ();
348
-	foreach ( $data as $key => $value ) {
349
-		$data1 = explode ( ":", $value );
350
-		foreach ( $data1 as $newkey => $newvalue ) {
344
+	$rates = urldecode($dataVariable);
345
+	$data = explode("|", $rates);
346
+	$newarray = array();
347
+	$newarray1 = array();
348
+	foreach ($data as $key => $value) {
349
+		$data1 = explode(":", $value);
350
+		foreach ($data1 as $newkey => $newvalue) {
351 351
 			$newarray [$data1 [0]] = $data1 [$newkey];
352 352
 			if ($newvalue == "ACCID") {
353 353
 				$newarray1 [$data1 [1]] = $newarray;
@@ -371,43 +371,43 @@  discard block
 block discarded – undo
371 371
 		$billseconds = $duration - $rates ['INITIALBLOCK'];
372 372
 		
373 373
 		if ($billseconds > 0) {
374
-			$call_cost += (ceil ( $billseconds / $rates ['INC'] ) * $rates ['INC']) * ($rates ['COST'] / 60);
374
+			$call_cost += (ceil($billseconds / $rates ['INC']) * $rates ['INC']) * ($rates ['COST'] / 60);
375 375
 		}
376 376
 	}
377
-	$call_cost = number_format ( $call_cost, $decimal_points );
378
-	$logger->log ( "Return cost " . $call_cost );
377
+	$call_cost = number_format($call_cost, $decimal_points);
378
+	$logger->log("Return cost ".$call_cost);
379 379
 	return $call_cost;
380 380
 }
381 381
 
382 382
 // get intial package information
383 383
 function package_calculation($destination_number, $pricelist_id, $duration, $call_direction, $accountid, $db, $logger) {
384
-	$package_array = array ();
385
-	$custom_destination = number_loop ( $destination_number, "patterns", $db );
384
+	$package_array = array();
385
+	$custom_destination = number_loop($destination_number, "patterns", $db);
386 386
 	
387
-	$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";
387
+	$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";
388 388
 	
389
-	$package_info = $db->run ( $query );
389
+	$package_info = $db->run($query);
390 390
 	if ($package_info) {
391 391
 		$package_info = $package_info [0];
392 392
 		
393 393
 		if (($package_info ['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info ['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info ['applicable_for'] == "2")) {
394 394
 			
395
-			$counter_info = get_counters ( $accountid, $package_info ['package_id'], $db, $logger );
395
+			$counter_info = get_counters($accountid, $package_info ['package_id'], $db, $logger);
396 396
 			
397
-			if (! $counter_info) {
398
-				$Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (" . $package_info ['package_id'] . "," . $accountid . ")";
399
-				$logger->log ( "Insert Counters  : " . $Insert_query );
400
-				$db->run ( $Insert_Query );
401
-				$counter_info = get_counters ( $accountid, $package_info ['package_id'], $db, $logger );
397
+			if ( ! $counter_info) {
398
+				$Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (".$package_info ['package_id'].",".$accountid.")";
399
+				$logger->log("Insert Counters  : ".$Insert_query);
400
+				$db->run($Insert_Query);
401
+				$counter_info = get_counters($accountid, $package_info ['package_id'], $db, $logger);
402 402
 			}
403 403
 			// print_r($counter_info);
404 404
 			if ($package_info ['includedseconds'] > ($counter_info ['seconds'])) {
405 405
 				$availableseconds = $package_info ['includedseconds'] - $counter_info ['seconds'];
406 406
 				$freeseconds = ($availableseconds >= $duration) ? $duration : $availableseconds;
407 407
 				$duration = ($availableseconds >= $duration) ? $duration : $availableseconds;
408
-				$update_query = "UPDATE counters SET seconds = " . ($counter_info ['seconds'] + $freeseconds) . " WHERE id = " . $counter_info ['id'];
409
-				$logger->log ( "Update Counters  : " . $update_query );
410
-				$db->run ( $update_query );
408
+				$update_query = "UPDATE counters SET seconds = ".($counter_info ['seconds'] + $freeseconds)." WHERE id = ".$counter_info ['id'];
409
+				$logger->log("Update Counters  : ".$update_query);
410
+				$db->run($update_query);
411 411
 				$package_array ['package_id'] = $package_info ['package_id'];
412 412
 				$package_array ['calltype'] = "FREE";
413 413
 			}
@@ -418,9 +418,9 @@  discard block
 block discarded – undo
418 418
 
419 419
 // Getting used package minutes in counter table
420 420
 function get_counters($accountid, $package_id, $db, $logger) {
421
-	$query_counter = "SELECT id,seconds FROM counters  WHERE  accountid = " . $accountid . " AND package_id = " . $package_id . " AND status=1 LIMIT 1";
422
-	$counter = $db->run ( $query_counter );
423
-	$logger->log ( "GET Counters  : " . $query_counter );
421
+	$query_counter = "SELECT id,seconds FROM counters  WHERE  accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1";
422
+	$counter = $db->run($query_counter);
423
+	$logger->log("GET Counters  : ".$query_counter);
424 424
 	if ($counter)
425 425
 		return $counter [0];
426 426
 	else
@@ -429,17 +429,17 @@  discard block
 block discarded – undo
429 429
 
430 430
 // Get user info
431 431
 function get_accounts($parent_id, $logger, $db) {
432
-	$query = "SELECT * FROM accounts WHERE id=" . $parent_id;
433
-	$logger->log ( "GET configuration  : " . $query );
434
-	$res_user = $db->run ( $query );
432
+	$query = "SELECT * FROM accounts WHERE id=".$parent_id;
433
+	$logger->log("GET configuration  : ".$query);
434
+	$res_user = $db->run($query);
435 435
 	return $res_user [0];
436 436
 }
437 437
 
438 438
 // Get configuration
439 439
 function load_configuration($logger) {
440 440
 	$query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'";
441
-	$config = $db->run ( $query );
442
-	$logger->log ( "GET configuration  : " . $query );
441
+	$config = $db->run($query);
442
+	$logger->log("GET configuration  : ".$query);
443 443
 	return $config [0];
444 444
 }
445 445
 
@@ -449,11 +449,11 @@  discard block
 block discarded – undo
449 449
  * @param string $field        	
450 450
  */
451 451
 function number_loop($destination, $field, $db) {
452
-	$max_len_prefix = strlen ( $destination );
452
+	$max_len_prefix = strlen($destination);
453 453
 	$number_prefix = '(';
454
-	while ( $max_len_prefix > 0 ) {
455
-		$number_prefix .= "$field='^" . substr ( $destination, 0, $max_len_prefix ) . ".*' OR ";
456
-		$max_len_prefix --;
454
+	while ($max_len_prefix > 0) {
455
+		$number_prefix .= "$field='^".substr($destination, 0, $max_len_prefix).".*' OR ";
456
+		$max_len_prefix--;
457 457
 	}
458 458
 	$number_prefix .= "$field='^defaultprefix.*')"; // echo $number_prefix;exit;
459 459
 	return $number_prefix;
@@ -465,6 +465,6 @@  discard block
 block discarded – undo
465 465
  * @param string $date        	
466 466
  */
467 467
 function convert_to_gmt($date) {
468
-	return gmdate ( 'Y-m-d H:i:s', strtotime ( $date ) );
468
+	return gmdate('Y-m-d H:i:s', strtotime($date));
469 469
 }
470 470
 ?>
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.constants.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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',
@@ -47,5 +47,5 @@  discard block
 block discarded – undo
47 47
 		'CBB' => 'billing_block' 
48 48
 );
49 49
 
50
-define ( "tbl_configuration", "system" );
50
+define("tbl_configuration", "system");
51 51
 ?>
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.lib.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@
 block discarded – undo
24 24
 	var $config;
25 25
 	function get_configurations($db) {
26 26
 		$query = "SELECT * FROM system WHERE group_title IN ('global','opensips')";
27
-		$res_conf = $db->run ( $query );
28
-		foreach ( $res_conf as $res_conf_key => $res_conf_value )
27
+		$res_conf = $db->run($query);
28
+		foreach ($res_conf as $res_conf_key => $res_conf_value)
29 29
 			$this->config [$res_conf_value ['name']] = $res_conf_value ['value'];
30 30
 		
31 31
 		return $this->config;
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.functions.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -23,20 +23,20 @@  discard block
 block discarded – undo
23 23
 
24 24
 // Parse user and rates array which we got in cdr xml
25 25
 function parse_rates_array($xml_rate, $constant_array, $logger) {
26
-	$rates_array = array ();
26
+	$rates_array = array();
27 27
 	
28 28
 	// decode string using urldecode
29
-	$xml_rate = urldecode ( $xml_rate );
30
-	$xml_rate_array = explode ( "||", $xml_rate );
29
+	$xml_rate = urldecode($xml_rate);
30
+	$xml_rate_array = explode("||", $xml_rate);
31 31
 	
32
-	foreach ( $xml_rate_array as $rate_key => $rate_value ) {
33
-		$rates_array = explode ( "|", $rate_value );
32
+	foreach ($xml_rate_array as $rate_key => $rate_value) {
33
+		$rates_array = explode("|", $rate_value);
34 34
 		
35
-		$user_id_param = $rates_array [count ( $rates_array ) - 1];
36
-		$user_id = (substr ( $user_id_param, 0, 3 ) == 'UID') ? substr ( $user_id_param, 3 ) : 0;
35
+		$user_id_param = $rates_array [count($rates_array) - 1];
36
+		$user_id = (substr($user_id_param, 0, 3) == 'UID') ? substr ($user_id_param, 3) : 0;
37 37
 		
38
-		foreach ( $rates_array as $key => $value ) {
39
-			$rates_array_info [$user_id] [$constant_array [substr ( $value, 0, 3 )]] = substr ( $value, 3 );
38
+		foreach ($rates_array as $key => $value) {
39
+			$rates_array_info [$user_id] [$constant_array [substr($value, 0, 3)]] = substr($value, 3);
40 40
 		}
41 41
 	}
42 42
 	return $rates_array_info;
@@ -50,50 +50,50 @@  discard block
 block discarded – undo
50 50
 	if ($duration > 0 && $xml_cdr->variables->call_direction == 'outbound') {
51 51
 		$destination_number = $xml_cdr->variables->effective_destination_number;
52 52
 		
53
-		$number_len = strlen ( $destination_number );
53
+		$number_len = strlen($destination_number);
54 54
 		$number_loop_str = '(';
55
-		while ( $number_len > 0 ) {
56
-			$number_loop_str .= " code='" . substr ( $destination_number, 0, $number_len ) . "' OR ";
55
+		while ($number_len > 0) {
56
+			$number_loop_str .= " code='".substr($destination_number, 0, $number_len)."' OR ";
57 57
 			$number_len -= 1;
58 58
 		}
59 59
 		$number_loop_str .= " code='--')";
60 60
 		
61
-		$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";
62
-		$logger->log ( "Package Query : " . $query );
63
-		$res_package = $db->run ( $query );
61
+		$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";
62
+		$logger->log("Package Query : ".$query);
63
+		$res_package = $db->run($query);
64 64
 		
65
-		foreach ( $res_package as $res_package_key => $package_info ) {
66
-			if (isset ( $package_info ['package_id'] )) {
67
-				$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;
68
-				$logger->log ( "Package usage Query : " . $query );
69
-				$res_pkg_usg = $db->run ( $query );
65
+		foreach ($res_package as $res_package_key => $package_info) {
66
+			if (isset ($package_info ['package_id'])) {
67
+				$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;
68
+				$logger->log("Package usage Query : ".$query);
69
+				$res_pkg_usg = $db->run($query);
70 70
 				$package_usage_info = $res_pkg_usg [0];
71 71
 				
72
-				$used_seconds = (isset ( $package_usage_info ['used_seconds'] )) ? $package_usage_info ['used_seconds'] : 0;
72
+				$used_seconds = (isset ($package_usage_info ['used_seconds'])) ? $package_usage_info ['used_seconds'] : 0;
73 73
 				
74
-				$logger->log ( "Included seconds : " . $package_info ['includedseconds'] . ", Used seconds : " . $used_seconds );
74
+				$logger->log("Included seconds : ".$package_info ['includedseconds'].", Used seconds : ".$used_seconds);
75 75
 				if ($package_info ['includedseconds'] > $used_seconds) {
76 76
 					$remaining_seconds = $package_info ['includedseconds'] - ($duration + $used_seconds);
77 77
 					if ($remaining_seconds > 0) {
78 78
 						$dud_sec = $duration;
79 79
 						$duration = 0;
80 80
 					} else {
81
-						$dud_sec = $duration - abs ( $remaining_seconds );
82
-						$duration = abs ( $remaining_seconds );
81
+						$dud_sec = $duration - abs($remaining_seconds);
82
+						$duration = abs($remaining_seconds);
83 83
 					}
84 84
 					$flag = true;
85 85
 					$xml_cdr->variables->package_id = $package_info ['package_id'];
86 86
 					
87
-					$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;
88
-					$logger->log ( "Package Usage Query : " . $query );
89
-					$db->run ( $query );
87
+					$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;
88
+					$logger->log("Package Usage Query : ".$query);
89
+					$db->run($query);
90 90
 					
91 91
 					break;
92 92
 				}
93 93
 			}
94 94
 		}
95 95
 	}
96
-	return array (
96
+	return array(
97 97
 			$duration,
98 98
 			$flag 
99 99
 	);
@@ -101,22 +101,22 @@  discard block
 block discarded – undo
101 101
 
102 102
 // Process user/vendor cdr
103 103
 function do_cdr_process($xml_cdr, $debit, $cost, $vendor_cost, $rates_array, $parent_id = 0, $parent_rates, $carrier_rates_array, $logger, $db) {
104
-	$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;
104
+	$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;
105 105
 	
106 106
 	$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)";
107 107
 	
108
-	$logger->log ( "CDR Query : " . $query );
109
-	$db->run ( $query );
108
+	$logger->log("CDR Query : ".$query);
109
+	$db->run($query);
110 110
 }
111 111
 
112 112
 // Process reseller cdr
113 113
 function do_reseller_cdr_process($xml_cdr, $debit, $cost, $rates_array, $parent_id = 0, $parent_rates, $logger, $db) {
114
-	$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 . "'";
114
+	$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."'";
115 115
 	
116 116
 	$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)";
117 117
 	
118
-	$logger->log ( "CDR Query : " . $query );
119
-	$db->run ( $query );
118
+	$logger->log("CDR Query : ".$query);
119
+	$db->run($query);
120 120
 }
121 121
 
122 122
 // Update user balance
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
128 128
 	if ($amount > 0) {
129 129
 		$math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
130
-		$query = "UPDATE tbl_users SET credit=credit$math_sign" . $amount . " WHERE id=" . $user_id;
131
-		$logger->log ( "Balance update : " . $query );
132
-		$db->run ( $query );
130
+		$query = "UPDATE tbl_users SET credit=credit$math_sign".$amount." WHERE id=".$user_id;
131
+		$logger->log("Balance update : ".$query);
132
+		$db->run($query);
133 133
 	}
134 134
 }
135 135
 
136 136
 // Get user info
137 137
 function get_user_info($parent_id, $db) {
138
-	$query = "SELECT * FROM tbl_users WHERE id=" . $parent_id;
139
-	$res_user = $db->run ( $query );
138
+	$query = "SELECT * FROM tbl_users WHERE id=".$parent_id;
139
+	$res_user = $db->run($query);
140 140
 	return $res_user [0];
141 141
 }
142 142
 
Please login to merge, or discard this patch.
freeswitch/fs/cdr.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,21 +20,21 @@  discard block
 block discarded – undo
20 20
 // You should have received a copy of the GNU Affero General Public License
21 21
 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 22
 // ##############################################################################
23
-define ( 'ENVIRONMENT', 'production' );
24
-if (defined ( 'ENVIRONMENT' )) {
23
+define('ENVIRONMENT', 'production');
24
+if (defined('ENVIRONMENT')) {
25 25
 	switch (ENVIRONMENT) {
26 26
 		case 'development' :
27 27
 			// error_reporting(E_ALL);
28
-			error_reporting ( E_ERROR | E_WARNING | E_PARSE );
28
+			error_reporting(E_ERROR | E_WARNING | E_PARSE);
29 29
 			break;
30 30
 		
31 31
 		case 'testing' :
32 32
 		case 'production' :
33
-			error_reporting ( 0 );
33
+			error_reporting(0);
34 34
 			break;
35 35
 		
36 36
 		default :
37
-			exit ( 'The application environment is not set correctly.' );
37
+			exit ('The application environment is not set correctly.');
38 38
 	}
39 39
 }
40 40
 
@@ -45,35 +45,35 @@  discard block
 block discarded – undo
45 45
 include ("lib/astpp.cdr.php");
46 46
 
47 47
 // Define db object
48
-$db = new db ();
48
+$db = new db();
49 49
 
50 50
 // Get default configuration
51
-$lib = new lib ();
52
-$config = $lib->get_configurations ( $db );
51
+$lib = new lib();
52
+$config = $lib->get_configurations($db);
53 53
 
54 54
 // Set default decimal points
55 55
 $decimal_points = ($config ['decimal_points'] <= 0) ? 4 : $config ['decimal_points'];
56 56
 
57 57
 // Define logger object
58
-$logger = new logger ( $lib );
58
+$logger = new logger($lib);
59 59
 
60
-if (isset ( $_SERVER ["CONTENT_TYPE"] ) && $_SERVER ["CONTENT_TYPE"] == "application/json") {
60
+if (isset ($_SERVER ["CONTENT_TYPE"]) && $_SERVER ["CONTENT_TYPE"] == "application/json") {
61 61
 	
62
-	$db->run ( "SET NAMES utf8" );
62
+	$db->run("SET NAMES utf8");
63 63
 	//$data = json_decode ( file_get_contents ( "php://input" ), true );
64 64
 	$data = file_get_contents("php://input");
65 65
         $data = utf8_encode($data);
66
-	$data = json_decode($data,true);
66
+	$data = json_decode($data, true);
67 67
 
68 68
 	// error_log(print_r($data,true));
69
-	$logger->log ( print_r ( $data, true ) );
69
+	$logger->log(print_r($data, true));
70 70
 	// process_cdr($data,$db,$logger,$decimal_points);
71 71
 	if ($data ['variables'] ['calltype'] == "CALLINGCARD") {
72
-		if (isset ( $data ['variables'] ['originating_leg_uuid'] )) {
73
-			process_cdr ( $data, $db, $logger, $decimal_points );
72
+		if (isset ($data ['variables'] ['originating_leg_uuid'])) {
73
+			process_cdr($data, $db, $logger, $decimal_points);
74 74
 		}
75 75
 	} else {
76
-		process_cdr ( $data, $db, $logger, $decimal_points );
76
+		process_cdr($data, $db, $logger, $decimal_points);
77 77
 	}
78 78
 }
79 79
 
Please login to merge, or discard this patch.