@@ -21,19 +21,19 @@ |
||
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | 23 | |
24 | -if (!defined('BASEPATH')) |
|
24 | +if ( ! defined('BASEPATH')) |
|
25 | 25 | exit('No direct script access allowed'); |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Dynamically build forms for display |
29 | 29 | */ |
30 | -class Global_locale{ |
|
30 | +class Global_locale { |
|
31 | 31 | |
32 | 32 | function __construct($library_name = '') { |
33 | 33 | |
34 | 34 | $this->CI = & get_instance(); |
35 | 35 | header("Expires: Tue, 01 Jan 2000 00:00:00 GMT"); |
36 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
36 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
37 | 37 | header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); |
38 | 38 | header("Cache-Control: post-check=0, pre-check=0", false); |
39 | 39 | header("Pragma: no-cache"); |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | if ( ! defined('BASEPATH')) { |
25 | 25 | exit('No direct script access allowed'); |
26 | 26 | } |
27 | -class freeswitch_lib{ |
|
27 | +class freeswitch_lib { |
|
28 | 28 | |
29 | - function event_socket_create($host='127.0.0.1', $port='8021', $password='ClueCon') { |
|
29 | + function event_socket_create($host = '127.0.0.1', $port = '8021', $password = 'ClueCon') { |
|
30 | 30 | $fp = @fsockopen($host, $port, $errno, $errdesc); |
31 | 31 | // or die("Connection to $host failed"); |
32 | 32 | // socket_set_blocking($fp,false); |
33 | 33 | |
34 | 34 | if ($fp) { |
35 | - socket_set_blocking($fp,false); |
|
36 | - while (!feof($fp)) { |
|
35 | + socket_set_blocking($fp, false); |
|
36 | + while ( ! feof($fp)) { |
|
37 | 37 | $buffer = fgets($fp, 1024); |
38 | 38 | usleep(100); //allow time for reponse |
39 | 39 | if (trim($buffer) == "Content-Type: auth/request") { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $response = ""; |
57 | 57 | $i = 0; |
58 | 58 | $contentlength = 0; |
59 | - while (!feof($fp)) { |
|
59 | + while ( ! feof($fp)) { |
|
60 | 60 | $buffer = fgets($fp, 4096); |
61 | 61 | if ($contentlength > 0) { |
62 | 62 | $response .= $buffer; |
@@ -31,7 +31,7 @@ |
||
31 | 31 | if ($xml == "") |
32 | 32 | xml_not_found(); |
33 | 33 | echo $xml; |
34 | -}else { |
|
34 | +} else { |
|
35 | 35 | xml_not_found(); |
36 | 36 | } |
37 | 37 | $logger->log("*************************** Directory Ends **********************************"); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | <div class="col-md-12"> |
16 | 16 | <div class="w-box"> |
17 | 17 | <span style="margin-left:10px; text-align: center;background-color: none;color:#DD191D;"> |
18 | - <? if(isset($error) && !empty($error)) { |
|
18 | + <? if (isset($error) && ! empty($error)) { |
|
19 | 19 | echo $error; |
20 | 20 | }?> |
21 | 21 | </span> |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | <div class="col-md-12 no-padding"> |
32 | 32 | <label class="col-md-3">Rate Group:</label> |
33 | 33 | <div> |
34 | - <? $pricelists = form_dropdown('pricelist_id', $this->db_model->build_dropdown("id,name", "pricelists","where_arr", array("reseller_id" => "0", "status" => "0")), ''); |
|
34 | + <? $pricelists = form_dropdown('pricelist_id', $this->db_model->build_dropdown("id,name", "pricelists", "where_arr", array("reseller_id" => "0", "status" => "0")), ''); |
|
35 | 35 | echo $pricelists; |
36 | 36 | ?> |
37 | 37 | </div> |
38 | 38 | </div> |
39 | 39 | <? |
40 | - $logintype=$this->session->userdata('userlevel_logintype'); |
|
40 | + $logintype = $this->session->userdata('userlevel_logintype'); |
|
41 | 41 | // $trunk=null; |
42 | - if($logintype !=1) { ?> |
|
42 | + if ($logintype != 1) { ?> |
|
43 | 43 | <div class="col-md-12 no-padding"> |
44 | 44 | <label class="col-md-3">Force Trunk:</label> |
45 | 45 | <div> |
46 | - <? $trunklist = form_dropdown_all('trunk_id', $this->db_model->build_dropdown("id,name", "trunks","where_arr", array("status" => "0")), ''); |
|
46 | + <? $trunklist = form_dropdown_all('trunk_id', $this->db_model->build_dropdown("id,name", "trunks", "where_arr", array("status" => "0")), ''); |
|
47 | 47 | echo $trunklist; |
48 | 48 | ?> |
49 | 49 | </div> |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | <?}?> |
101 | 101 | |
102 | 102 | <?php |
103 | - if(isset($csv_tmp_data) && !empty($csv_tmp_data)){ ?> |
|
103 | + if (isset($csv_tmp_data) && ! empty($csv_tmp_data)) { ?> |
|
104 | 104 | |
105 | 105 | <section class="slice color-three"> |
106 | 106 | <div class="w-section inverse no-padding"> |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | <div class="col-md-12 margin-t-10"> |
110 | 110 | <form id="import_form" name="import_form" action="<?=base_url()?>rates/origination_rate_import_file/<?= $pricelistid?>/<?=$trunkid?>/<?=$check_header?>/" method="POST"> |
111 | 111 | <table width="100%" border="1" class="details_table table"> |
112 | - <? $cnt =7; |
|
113 | - foreach($csv_tmp_data as $csv_key => $csv_value){ |
|
114 | - if($csv_key < 15){ |
|
112 | + <? $cnt = 7; |
|
113 | + foreach ($csv_tmp_data as $csv_key => $csv_value) { |
|
114 | + if ($csv_key < 15) { |
|
115 | 115 | echo "<tr>"; |
116 | - foreach($csv_value as $field_name => $field_val){ |
|
117 | - if($csv_key == 0){ |
|
116 | + foreach ($csv_value as $field_name => $field_val) { |
|
117 | + if ($csv_key == 0) { |
|
118 | 118 | echo "<th>".ucfirst($field_name)."</th>"; |
119 | - }else{ |
|
119 | + } else { |
|
120 | 120 | echo "<td class='portlet-content'>".$field_val."</td>"; |
121 | 121 | } |
122 | 122 | } |
@@ -6,19 +6,19 @@ |
||
6 | 6 | <div class="padding-b-10 col-md-12 no-padding"> |
7 | 7 | |
8 | 8 | <?php |
9 | - $str = isset($_SERVER['HTTPS'])&& $_SERVER['HTTPS'] == 'on' ? 'https://' :'http://'; |
|
9 | + $str = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://'; |
|
10 | 10 | $this->db->select('*'); |
11 | - $this->db->where('domain',$_SERVER['HTTP_HOST']); |
|
12 | - $this->db->or_where('domain','http://'.$_SERVER['HTTP_HOST']); |
|
13 | - $this->db->or_where('domain','https://'.$_SERVER['HTTP_HOST']); |
|
14 | - $result=$this->db->get('invoice_conf'); |
|
15 | - if($result->num_rows() > 0){ |
|
16 | - $result=$result->result_array(); |
|
11 | + $this->db->where('domain', $_SERVER['HTTP_HOST']); |
|
12 | + $this->db->or_where('domain', 'http://'.$_SERVER['HTTP_HOST']); |
|
13 | + $this->db->or_where('domain', 'https://'.$_SERVER['HTTP_HOST']); |
|
14 | + $result = $this->db->get('invoice_conf'); |
|
15 | + if ($result->num_rows() > 0) { |
|
16 | + $result = $result->result_array(); |
|
17 | 17 | $footer = $result[0]['website_footer']; |
18 | - }else{ |
|
18 | + } else { |
|
19 | 19 | $footer = ''; |
20 | 20 | } |
21 | - if($footer != ''){ ?> |
|
21 | + if ($footer != '') { ?> |
|
22 | 22 | <div style="margin-left:470px; "><?=$footer ?> |
23 | 23 | |
24 | 24 | <div style="" class="pull-left"> |
@@ -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,7 +65,7 @@ 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 | } |
@@ -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,12 +160,12 @@ 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"; |
167 | 167 | $dataVariable['calltype'] = "STANDARD"; |
168 | - $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
168 | + $dataVariable['effective_destination_number'] = $dataVariable['sip_to_user']; |
|
169 | 169 | unset($termination_rate); |
170 | 170 | unset($provider_cost); |
171 | 171 | } |
@@ -173,17 +173,17 @@ discard block |
||
173 | 173 | |
174 | 174 | |
175 | 175 | //Get call receiver account information |
176 | - $receiver_carddata = get_accounts($dataVariable['receiver_accid'],$logger,$db); |
|
176 | + $receiver_carddata = get_accounts($dataVariable['receiver_accid'], $logger, $db); |
|
177 | 177 | $receiver_parentid = $receiver_carddata['reseller_id']; |
178 | 178 | |
179 | 179 | //For additional cdr entry of receiver |
180 | - 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); |
|
180 | + 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); |
|
181 | 181 | |
182 | 182 | $flag_parent = true; |
183 | 183 | $dataVariable['uuid'] = $dataVariable['uuid'].$dataVariable['calltype']."_".$receiver_parentid; |
184 | 184 | |
185 | 185 | //Insert parent reseller cdr |
186 | - insert_parent_data($dataVariable,$actual_calltype,$receiver_parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
186 | + insert_parent_data($dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
187 | 187 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************"); |
188 | 188 | } |
189 | 189 | //***************************************************************************************** |
@@ -195,16 +195,16 @@ discard block |
||
195 | 195 | * @param string $provider_cost |
196 | 196 | * @param boolean $flag_parent |
197 | 197 | */ |
198 | -function insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points) |
|
198 | +function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points) |
|
199 | 199 | { |
200 | - while($parentid > 0 ) |
|
200 | + while ($parentid > 0) |
|
201 | 201 | { |
202 | 202 | $logger->log("*************** IN PARENT DATA SECTION ********"); |
203 | 203 | $dataVariable['calltype'] = $actual_calltype; |
204 | - $carddata = get_accounts($parentid,$logger,$db); |
|
204 | + $carddata = get_accounts($parentid, $logger, $db); |
|
205 | 205 | $accountid = $carddata['id']; |
206 | 206 | |
207 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
207 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
208 | 208 | |
209 | 209 | //If receiver account id found then explicitly set call direction and call type |
210 | 210 | /*if(isset($dataVariable['receiver_accid'])) |
@@ -214,31 +214,31 @@ discard block |
||
214 | 214 | }*/ |
215 | 215 | |
216 | 216 | //Check if reseller have any package seconds left to use |
217 | - if ($actual_duration > 0) { |
|
218 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
219 | - if(!empty($package_array)) |
|
217 | + if ($actual_duration > 0) { |
|
218 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
219 | + if ( ! empty($package_array)) |
|
220 | 220 | { |
221 | 221 | $dataVariable['calltype'] = "FREE"; |
222 | - $dataVariable['package_id']= $package_array['package_id']; |
|
222 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | 226 | //Get parent id for cost calculation |
227 | 227 | $parentid = $carddata['reseller_id']; |
228 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
228 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
229 | 229 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
230 | 230 | |
231 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
231 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
232 | 232 | { |
233 | 233 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******"); |
234 | 234 | $flag_parent = true; |
235 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points); |
|
235 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points); |
|
236 | 236 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******"); |
237 | 237 | return true; |
238 | 238 | |
239 | - } else{ |
|
239 | + } else { |
|
240 | 240 | |
241 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
241 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
242 | 242 | |
243 | 243 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
244 | 244 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
@@ -259,38 +259,38 @@ discard block |
||
259 | 259 | /** |
260 | 260 | * @param boolean $flag_parent |
261 | 261 | */ |
262 | -function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points) |
|
262 | +function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points) |
|
263 | 263 | { |
264 | 264 | $localVariable = $dataVariable; |
265 | 265 | $localVariable['call_direction'] = "inbound"; |
266 | 266 | $localVariable['uuid'] = $localVariable['uuid'].$dataVariable['calltype']."_".$accountid; |
267 | 267 | |
268 | - if($dataVariable['calltype'] == "LOCAL") |
|
268 | + if ($dataVariable['calltype'] == "LOCAL") |
|
269 | 269 | { |
270 | 270 | $origination_rate[$accountid]['CODE'] = $dataVariable['effective_destination_number']; |
271 | 271 | $origination_rate[$accountid]['DESTINATION'] = $dataVariable['calltype']; |
272 | - if($flag_parent == false){ |
|
273 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,0,0,$logger); |
|
274 | - } else{ |
|
275 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
272 | + if ($flag_parent == false) { |
|
273 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, 0, 0, $logger); |
|
274 | + } else { |
|
275 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
276 | 276 | } |
277 | - } else{ |
|
277 | + } else { |
|
278 | 278 | |
279 | 279 | $origination_rate_did = normalize_origination_rate($dataVariable['origination_rates_did']); |
280 | - $debit = calc_cost($dataVariable,$origination_rate_did[$accountid],$logger,$decimal_points); |
|
280 | + $debit = calc_cost($dataVariable, $origination_rate_did[$accountid], $logger, $decimal_points); |
|
281 | 281 | |
282 | - if($flag_parent == false){ |
|
282 | + if ($flag_parent == false) { |
|
283 | 283 | |
284 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate_did,$provider_cost,$parentid,$debit,0,$logger); |
|
285 | - } else{ |
|
286 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
284 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger); |
|
285 | + } else { |
|
286 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | - if($flag_parent == false) |
|
290 | + if ($flag_parent == false) |
|
291 | 291 | { |
292 | 292 | $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)"; |
293 | - } else{ |
|
293 | + } else { |
|
294 | 294 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
295 | 295 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
296 | 296 | } |
@@ -306,20 +306,20 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | //Generate CDR string for insert query for customer. |
309 | -function get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger) |
|
309 | +function get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger) |
|
310 | 310 | { |
311 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
312 | - $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
|
313 | - 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'])."','".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']."'"; |
|
311 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
312 | + $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && ! empty($dataVariable['effective_caller_id_number']) ? $dataVariable['effective_caller_id_number'] : $dataVariable['caller_id']; |
|
313 | + 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'])."','".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']."'"; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | //Generate CDR string for insert query for reseller |
317 | -function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost) |
|
317 | +function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost) |
|
318 | 318 | { |
319 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
320 | - $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
|
319 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
320 | + $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && ! empty($dataVariable['effective_caller_id_number']) ? $dataVariable['effective_caller_id_number'] : $dataVariable['caller_id']; |
|
321 | 321 | |
322 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($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'])."'"; |
|
322 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($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'])."'"; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | //Update user balance |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | */ |
329 | 329 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
330 | 330 | $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
331 | - $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
332 | - $logger->log("Balance update : " . $query); |
|
331 | + $query = "UPDATE accounts SET balance=balance-".$amount." WHERE id=".$user_id; |
|
332 | + $logger->log("Balance update : ".$query); |
|
333 | 333 | $db->run($query); |
334 | 334 | } |
335 | 335 | |
@@ -388,46 +388,46 @@ discard block |
||
388 | 388 | |
389 | 389 | if ($billseconds > 0) |
390 | 390 | { |
391 | - $call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60); |
|
391 | + $call_cost += (ceil($billseconds / $rates['INC']) * $rates['INC']) * ($rates['COST'] / 60); |
|
392 | 392 | } |
393 | 393 | } |
394 | - $call_cost = number_format($call_cost,$decimal_points); |
|
394 | + $call_cost = number_format($call_cost, $decimal_points); |
|
395 | 395 | $logger->log("Return cost ".$call_cost); |
396 | 396 | return $call_cost; |
397 | 397 | } |
398 | 398 | |
399 | 399 | // get intial package information |
400 | -function package_calculation($destination_number,$pricelist_id,$duration,$call_direction,$accountid,$db,$logger) |
|
400 | +function package_calculation($destination_number, $pricelist_id, $duration, $call_direction, $accountid, $db, $logger) |
|
401 | 401 | { |
402 | 402 | $package_array = array(); |
403 | - $custom_destination = number_loop($destination_number,"patterns",$db); |
|
403 | + $custom_destination = number_loop($destination_number, "patterns", $db); |
|
404 | 404 | |
405 | 405 | $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"; |
406 | 406 | |
407 | 407 | $package_info = $db->run($query); |
408 | - if($package_info){ |
|
408 | + if ($package_info) { |
|
409 | 409 | $package_info = $package_info[0]; |
410 | 410 | |
411 | - if( ($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2") ) { |
|
411 | + if (($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2")) { |
|
412 | 412 | |
413 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
413 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
414 | 414 | |
415 | - if(!$counter_info) { |
|
415 | + if ( ! $counter_info) { |
|
416 | 416 | $Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (".$package_info['package_id'].",".$accountid.")"; |
417 | - $logger->log("Insert Counters : " . $Insert_query); |
|
417 | + $logger->log("Insert Counters : ".$Insert_query); |
|
418 | 418 | $db->run($Insert_Query); |
419 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
419 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | //print_r($counter_info); |
423 | - if ( $package_info['includedseconds'] > ($counter_info['seconds'] )) { |
|
423 | + if ($package_info['includedseconds'] > ($counter_info['seconds'])) { |
|
424 | 424 | $availableseconds = $package_info['includedseconds'] - $counter_info['seconds']; |
425 | 425 | $freeseconds = ($availableseconds >= $duration) ? $duration : $availableseconds; |
426 | 426 | $duration = ($availableseconds >= $duration) ? $duration : $availableseconds; |
427 | - $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds ). " WHERE id = ". $counter_info['id']; |
|
428 | - $logger->log("Update Counters : " . $update_query); |
|
427 | + $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds)." WHERE id = ".$counter_info['id']; |
|
428 | + $logger->log("Update Counters : ".$update_query); |
|
429 | 429 | $db->run($update_query); |
430 | - $package_array['package_id']= $package_info['package_id']; |
|
430 | + $package_array['package_id'] = $package_info['package_id']; |
|
431 | 431 | $package_array['calltype'] = "FREE"; |
432 | 432 | } |
433 | 433 | } |
@@ -436,21 +436,21 @@ discard block |
||
436 | 436 | } |
437 | 437 | |
438 | 438 | // Getting used package minutes in counter table |
439 | -function get_counters($accountid,$package_id,$db,$logger) |
|
439 | +function get_counters($accountid, $package_id, $db, $logger) |
|
440 | 440 | { |
441 | 441 | $query_counter = "SELECT id,seconds FROM counters WHERE accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1"; |
442 | 442 | $counter = $db->run($query_counter); |
443 | - $logger->log("GET Counters : " . $query_counter); |
|
444 | - if($counter) |
|
443 | + $logger->log("GET Counters : ".$query_counter); |
|
444 | + if ($counter) |
|
445 | 445 | return $counter[0]; |
446 | 446 | else |
447 | 447 | return ""; |
448 | 448 | } |
449 | 449 | |
450 | 450 | //Get user info |
451 | -function get_accounts($parent_id,$logger, $db) { |
|
452 | - $query = "SELECT * FROM accounts WHERE id=" . $parent_id; |
|
453 | - $logger->log("GET configuration : " . $query); |
|
451 | +function get_accounts($parent_id, $logger, $db) { |
|
452 | + $query = "SELECT * FROM accounts WHERE id=".$parent_id; |
|
453 | + $logger->log("GET configuration : ".$query); |
|
454 | 454 | $res_user = $db->run($query); |
455 | 455 | return $res_user[0]; |
456 | 456 | } |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | { |
461 | 461 | $query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'"; |
462 | 462 | $config = $db->run($query); |
463 | - $logger->log("GET configuration : " . $query); |
|
463 | + $logger->log("GET configuration : ".$query); |
|
464 | 464 | return $config[0]; |
465 | 465 | } |
466 | 466 | |
@@ -468,16 +468,16 @@ discard block |
||
468 | 468 | /** |
469 | 469 | * @param string $field |
470 | 470 | */ |
471 | -function number_loop($destination,$field,$db) |
|
471 | +function number_loop($destination, $field, $db) |
|
472 | 472 | { |
473 | - $max_len_prefix = strlen($destination); |
|
473 | + $max_len_prefix = strlen($destination); |
|
474 | 474 | $number_prefix = '('; |
475 | - while ($max_len_prefix > 0) |
|
475 | + while ($max_len_prefix > 0) |
|
476 | 476 | { |
477 | - $number_prefix .= "$field='^".substr($destination,0,$max_len_prefix).".*' OR "; |
|
477 | + $number_prefix .= "$field='^".substr($destination, 0, $max_len_prefix).".*' OR "; |
|
478 | 478 | $max_len_prefix--; |
479 | 479 | } |
480 | - $number_prefix .= "$field='^defaultprefix.*')";//echo $number_prefix;exit; |
|
480 | + $number_prefix .= "$field='^defaultprefix.*')"; //echo $number_prefix;exit; |
|
481 | 481 | return $number_prefix; |
482 | 482 | } |
483 | 483 | |
@@ -487,6 +487,6 @@ discard block |
||
487 | 487 | */ |
488 | 488 | function convert_to_gmt($date) |
489 | 489 | { |
490 | - return gmdate('Y-m-d H:i:s', strtotime($date) ); |
|
490 | + return gmdate('Y-m-d H:i:s', strtotime($date)); |
|
491 | 491 | } |
492 | 492 | ?> |
@@ -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,24 +55,24 @@ 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 | - if($data['variables']['calltype']== "CALLINGCARD"){ |
|
70 | - if(isset($data['variables']['originating_leg_uuid'])) |
|
68 | + $logger->log(print_r($data, true)); |
|
69 | + if ($data['variables']['calltype'] == "CALLINGCARD") { |
|
70 | + if (isset($data['variables']['originating_leg_uuid'])) |
|
71 | 71 | { |
72 | - process_cdr($data,$db,$logger,$decimal_points); |
|
72 | + process_cdr($data, $db, $logger, $decimal_points); |
|
73 | 73 | } |
74 | - }else{ |
|
75 | - process_cdr($data,$db,$logger,$decimal_points); |
|
74 | + } else { |
|
75 | + process_cdr($data, $db, $logger, $decimal_points); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 |
@@ -176,35 +176,35 @@ |
||
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> |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | $this->load->library('csvreader'); |
36 | 36 | |
37 | 37 | if ($this->session->userdata('user_login') == FALSE) |
38 | - redirect(base_url() . '/astpp/login'); |
|
38 | + redirect(base_url().'/astpp/login'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | function did_add() { |
42 | 42 | $data['page_title'] = 'Create DID'; |
43 | 43 | $data['form'] = $this->form->build_form($this->did_form->get_dids_form_fields(), ''); |
44 | 44 | $data['country_id'] = $this->common->get_field_name('id', 'countrycode', array('country' => Common_model::$global_config['system_config']['country'])); |
45 | - if (!$data['country_id']) { |
|
45 | + if ( ! $data['country_id']) { |
|
46 | 46 | $data['country_id'] = 1; |
47 | 47 | } |
48 | 48 | $this->load->view('view_did_add_edit', $data); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $data['country_id'] = Common_model::$global_config['system_config']['country']; |
65 | 65 | } |
66 | 66 | /* * ************************************************* */ |
67 | - if (!$data['country_id']) { |
|
67 | + if ( ! $data['country_id']) { |
|
68 | 68 | $data['country_id'] = 1; |
69 | 69 | } |
70 | 70 | $edit_data['setup'] = $this->common_model->to_calculate_currency($edit_data['setup'], '', '', false, false); |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | |
84 | 84 | function did_save() { |
85 | 85 | $add_array = $this->input->post(); |
86 | - $parent_id =isset($add_array['parent_id']) && $add_array['parent_id'] >0 ? $add_array['parent_id'] : ''; |
|
87 | - $accountid =isset($add_array['accountid']) && $add_array['accountid'] > 0 ? $add_array['accountid'] : ''; |
|
88 | - $data['form'] = $this->form->build_form($this->did_form->get_dids_form_fields($add_array['id'],$parent_id,$accountid), $add_array); |
|
86 | + $parent_id = isset($add_array['parent_id']) && $add_array['parent_id'] > 0 ? $add_array['parent_id'] : ''; |
|
87 | + $accountid = isset($add_array['accountid']) && $add_array['accountid'] > 0 ? $add_array['accountid'] : ''; |
|
88 | + $data['form'] = $this->form->build_form($this->did_form->get_dids_form_fields($add_array['id'], $parent_id, $accountid), $add_array); |
|
89 | 89 | if ($add_array['id'] != '') { |
90 | 90 | $data['page_title'] = 'Edit DID'; |
91 | 91 | if ($this->form_validation->run() == FALSE) { |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | } else { |
96 | 96 | $number = $add_array['number']; |
97 | 97 | unset($add_array['number']); |
98 | - $add_array['accountid']=isset($add_array['accountid']) ?$add_array['accountid'] : 0; |
|
98 | + $add_array['accountid'] = isset($add_array['accountid']) ? $add_array['accountid'] : 0; |
|
99 | 99 | $add_array['setup'] = $this->common_model->add_calculate_currency($add_array['setup'], '', '', false, false); |
100 | 100 | $add_array['monthlycost'] = $this->common_model->add_calculate_currency($add_array['monthlycost'], '', '', false, false); |
101 | 101 | $add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
102 | 102 | $add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
103 | 103 | $this->did_model->edit_did($add_array, $add_array['id'], $number); |
104 | - echo json_encode(array("SUCCESS" => $number . " DID Updated Successfully!")); |
|
104 | + echo json_encode(array("SUCCESS" => $number." DID Updated Successfully!")); |
|
105 | 105 | exit; |
106 | 106 | } |
107 | 107 | } else { |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | $add_array['monthlycost'] = $this->common_model->add_calculate_currency($add_array['monthlycost'], '', '', false, false); |
121 | 121 | $add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
122 | 122 | $add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
123 | - $add_array['accountid']=isset($add_array['accountid'])?$add_array['accountid'] : 0; |
|
123 | + $add_array['accountid'] = isset($add_array['accountid']) ? $add_array['accountid'] : 0; |
|
124 | 124 | $this->did_model->add_did($add_array); |
125 | - echo json_encode(array("SUCCESS" => $add_array["number"] . " DID Added Successfully!")); |
|
125 | + echo json_encode(array("SUCCESS" => $add_array["number"]." DID Added Successfully!")); |
|
126 | 126 | exit; |
127 | 127 | exit; |
128 | 128 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | function did_remove($id) { |
133 | 133 | $this->did_model->remove_did($id); |
134 | 134 | $this->session->set_flashdata('astpp_notification', 'DID Removed Successfully!'); |
135 | - redirect(base_url() . 'did/did_list/'); |
|
135 | + redirect(base_url().'did/did_list/'); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /* |
@@ -141,54 +141,54 @@ discard block |
||
141 | 141 | */ |
142 | 142 | |
143 | 143 | function did_list_release($id) { |
144 | - $accountinfo=$this->session->userdata('accountinfo'); |
|
145 | - $this->db->where('id',$id); |
|
144 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
145 | + $this->db->where('id', $id); |
|
146 | 146 | $this->db->select('parent_id,accountid,number'); |
147 | - $did_info=(array)$this->db->get('dids')->first_row(); |
|
148 | - if($did_info['parent_id'] > 0){ |
|
149 | - $str=$this->common->get_parent_info($did_info['parent_id'],$accountinfo['id']); |
|
150 | - $str=rtrim($str,","); |
|
151 | - $account_result=(array)$this->db->get_where('accounts',"id IN (".$str.")")->result_array(); |
|
152 | - foreach($account_result as $key=>$acc_row){ |
|
153 | - $acc_row['did_number']=$did_info['number']; |
|
147 | + $did_info = (array)$this->db->get('dids')->first_row(); |
|
148 | + if ($did_info['parent_id'] > 0) { |
|
149 | + $str = $this->common->get_parent_info($did_info['parent_id'], $accountinfo['id']); |
|
150 | + $str = rtrim($str, ","); |
|
151 | + $account_result = (array)$this->db->get_where('accounts', "id IN (".$str.")")->result_array(); |
|
152 | + foreach ($account_result as $key=>$acc_row) { |
|
153 | + $acc_row['did_number'] = $did_info['number']; |
|
154 | 154 | $this->common->mail_to_users('email_remove_did', $acc_row); |
155 | 155 | } |
156 | 156 | } |
157 | - if($accountinfo['type'] == -1){ |
|
158 | - $update_array = array('parent_id' => 0, 'accountid' => 0, 'assign_date' => '0000-00-00 00:00:00', "charge_upto" => "0000-00-00 00:00:00","last_modified_date"=>gmdate("Y-m-d H:i:s"),'call_type'=>'-1','extensions'=>''); |
|
157 | + if ($accountinfo['type'] == -1) { |
|
158 | + $update_array = array('parent_id' => 0, 'accountid' => 0, 'assign_date' => '0000-00-00 00:00:00', "charge_upto" => "0000-00-00 00:00:00", "last_modified_date"=>gmdate("Y-m-d H:i:s"), 'call_type'=>'-1', 'extensions'=>''); |
|
159 | 159 | $where = array('id' => $id); |
160 | 160 | $this->db->where($where); |
161 | 161 | $this->db->update('dids', $update_array); |
162 | - if($did_info['parent_id'] > 0){ |
|
163 | - $this->db->where('note',$did_info['number']); |
|
162 | + if ($did_info['parent_id'] > 0) { |
|
163 | + $this->db->where('note', $did_info['number']); |
|
164 | 164 | $this->db->delete("reseller_pricing"); |
165 | 165 | } |
166 | - }else{ |
|
167 | - $reseller_ids=$this->common->get_subreseller_info($accountinfo['id']); |
|
168 | - $reseller_ids=rtrim($reseller_ids,","); |
|
169 | - $where="parent_id IN ($reseller_ids)"; |
|
170 | - $this->db->where('note',$did_info['number']); |
|
171 | - $this->db->delete('reseller_pricing',$where); |
|
166 | + } else { |
|
167 | + $reseller_ids = $this->common->get_subreseller_info($accountinfo['id']); |
|
168 | + $reseller_ids = rtrim($reseller_ids, ","); |
|
169 | + $where = "parent_id IN ($reseller_ids)"; |
|
170 | + $this->db->where('note', $did_info['number']); |
|
171 | + $this->db->delete('reseller_pricing', $where); |
|
172 | 172 | } |
173 | - if($accountinfo['type']==1){ |
|
174 | - $update_array = array('parent_id' => $accountinfo['id'], 'accountid' => 0, 'assign_date' => '0000-00-00 00:00:00', "charge_upto" => "0000-00-00 00:00:00","last_modified_date"=>gmdate("Y-m-d H:i:s"),'call_type'=>'-1','extensions'=>''); |
|
175 | - }else{ |
|
176 | - $update_array = array('parent_id' => 0, 'accountid' => 0, 'assign_date' => '0000-00-00 00:00:00', "charge_upto" => "0000-00-00 00:00:00","last_modified_date"=>gmdate("Y-m-d H:i:s"),'call_type'=>'-1','extensions'=>''); |
|
173 | + if ($accountinfo['type'] == 1) { |
|
174 | + $update_array = array('parent_id' => $accountinfo['id'], 'accountid' => 0, 'assign_date' => '0000-00-00 00:00:00', "charge_upto" => "0000-00-00 00:00:00", "last_modified_date"=>gmdate("Y-m-d H:i:s"), 'call_type'=>'-1', 'extensions'=>''); |
|
175 | + } else { |
|
176 | + $update_array = array('parent_id' => 0, 'accountid' => 0, 'assign_date' => '0000-00-00 00:00:00', "charge_upto" => "0000-00-00 00:00:00", "last_modified_date"=>gmdate("Y-m-d H:i:s"), 'call_type'=>'-1', 'extensions'=>''); |
|
177 | 177 | } |
178 | 178 | $where = array('id' => $id); |
179 | 179 | $this->db->where($where); |
180 | 180 | $this->db->update('dids', $update_array); |
181 | - $accountid=$did_info['accountid'] > 0 ? $did_info['accountid']:0; |
|
182 | - if($did_info['accountid'] > 0 ){ |
|
183 | - $email_user_id=$did_info['accountid']; |
|
184 | - }elseif($did_info['parent_id'] > 0){ |
|
185 | - $email_user_id=$did_info['parent_id']; |
|
181 | + $accountid = $did_info['accountid'] > 0 ? $did_info['accountid'] : 0; |
|
182 | + if ($did_info['accountid'] > 0) { |
|
183 | + $email_user_id = $did_info['accountid']; |
|
184 | + }elseif ($did_info['parent_id'] > 0) { |
|
185 | + $email_user_id = $did_info['parent_id']; |
|
186 | 186 | } |
187 | - $accountinfo=(array)$this->db->get_where('accounts',array("id"=>$email_user_id))->first_row(); |
|
187 | + $accountinfo = (array)$this->db->get_where('accounts', array("id"=>$email_user_id))->first_row(); |
|
188 | 188 | $accountinfo['did_number'] = $did_info['number']; |
189 | 189 | $this->common->mail_to_users('email_remove_did', $accountinfo); |
190 | 190 | $this->session->set_flashdata('astpp_errormsg', 'DID Released Successfully!'); |
191 | - redirect(base_url() . 'did/did_list/'); |
|
191 | + redirect(base_url().'did/did_list/'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | function did_list() { |
@@ -204,33 +204,33 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | if ($this->session->userdata['userlevel_logintype'] == '1') { |
207 | - $drp_list=array(); |
|
207 | + $drp_list = array(); |
|
208 | 208 | $accountinfo = $this->session->userdata('accountinfo'); |
209 | - if($accountinfo['reseller_id'] > 0){ |
|
210 | - $dids_array=$this->db->query("SELECT a.id AS id,a.number as number, b.monthlycost, b.setup FROM dids AS a, reseller_pricing AS b WHERE a.number = b.note AND b.reseller_id = ".$accountinfo['reseller_id']." AND a.parent_id =".$accountinfo['reseller_id'])->result_array(); |
|
211 | - }else{ |
|
209 | + if ($accountinfo['reseller_id'] > 0) { |
|
210 | + $dids_array = $this->db->query("SELECT a.id AS id,a.number as number, b.monthlycost, b.setup FROM dids AS a, reseller_pricing AS b WHERE a.number = b.note AND b.reseller_id = ".$accountinfo['reseller_id']." AND a.parent_id =".$accountinfo['reseller_id'])->result_array(); |
|
211 | + } else { |
|
212 | 212 | $this->db->select('id,monthlycost,setup,number'); |
213 | - $this->db->where('accountid',0); |
|
214 | - $this->db->where('parent_id',0); |
|
215 | - $dids_array=$this->db->get('dids')->result_array(); |
|
213 | + $this->db->where('accountid', 0); |
|
214 | + $this->db->where('parent_id', 0); |
|
215 | + $dids_array = $this->db->get('dids')->result_array(); |
|
216 | 216 | } |
217 | - if(!empty($dids_array)){ |
|
217 | + if ( ! empty($dids_array)) { |
|
218 | 218 | foreach ($dids_array as $drp_value) { |
219 | - if (!empty($drp_value['monthlycost']) && $drp_value['monthlycost'] != 0) { |
|
219 | + if ( ! empty($drp_value['monthlycost']) && $drp_value['monthlycost'] != 0) { |
|
220 | 220 | $did_cost = $this->common_model->to_calculate_currency($drp_value['monthlycost'], '', '', true, false); |
221 | 221 | } else { |
222 | 222 | $did_cost = 0; |
223 | 223 | } |
224 | - if (!empty($drp_value['setup']) && $drp_value['setup'] != 0) { |
|
224 | + if ( ! empty($drp_value['setup']) && $drp_value['setup'] != 0) { |
|
225 | 225 | $did_setup = $this->common_model->to_calculate_currency($drp_value['setup'], '', '', true, false); |
226 | 226 | } else { |
227 | 227 | $did_setup = 0; |
228 | 228 | } |
229 | - $drp_list[$drp_value['id']] = $drp_value['number'] . ' ( Setup : ' . $did_setup . ')' . '( Monthly : ' . $did_cost . ' )'; |
|
229 | + $drp_list[$drp_value['id']] = $drp_value['number'].' ( Setup : '.$did_setup.')'.'( Monthly : '.$did_cost.' )'; |
|
230 | 230 | /* * ********************************************************************************************* */ |
231 | 231 | } |
232 | 232 | } |
233 | - $data['didlist'] = form_dropdown_all(array("name"=>"free_did_list","id"=>"free_did_list","class"=>"did_dropdown"), $drp_list, ''); |
|
233 | + $data['didlist'] = form_dropdown_all(array("name"=>"free_did_list", "id"=>"free_did_list", "class"=>"did_dropdown"), $drp_list, ''); |
|
234 | 234 | } |
235 | 235 | if ($this->session->userdata['userlevel_logintype'] == '1') { |
236 | 236 | $data['grid_fields'] = $this->did_form->build_did_list_for_reseller_login(); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | $this->session->set_userdata('did_list_search', $action); |
271 | 271 | } |
272 | 272 | if (@$ajax_search != 1) { |
273 | - redirect(base_url() . 'did/did_list/'); |
|
273 | + redirect(base_url().'did/did_list/'); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -318,10 +318,10 @@ discard block |
||
318 | 318 | */ |
319 | 319 | function customer_did($accountid, $accounttype) { |
320 | 320 | $json_data = array(); |
321 | - $instant_search=$this->session->userdata('left_panel_search_'.$accounttype.'_did'); |
|
322 | - $account_arr=(array)$this->db->get_where('accounts',array("id"=>$accountid))->first_row(); |
|
321 | + $instant_search = $this->session->userdata('left_panel_search_'.$accounttype.'_did'); |
|
322 | + $account_arr = (array)$this->db->get_where('accounts', array("id"=>$accountid))->first_row(); |
|
323 | 323 | $field_name = $accounttype == "reseller" ? "parent_id" : 'accountid'; |
324 | - $like_str=!empty($instant_search) ? |
|
324 | + $like_str = ! empty($instant_search) ? |
|
325 | 325 | "(a.note like '%$instant_search%' |
326 | 326 | OR a.init_inc like '%$instant_search%' |
327 | 327 | OR a.inc like '%$instant_search%' |
@@ -330,32 +330,32 @@ discard block |
||
330 | 330 | OR a.setup like '%$instant_search%' |
331 | 331 | OR a.monthlycost like '%$instant_search%' |
332 | 332 | OR a.connectcost like '%$instant_search%' |
333 | - )" :null; |
|
333 | + )" : null; |
|
334 | 334 | if ($account_arr['reseller_id'] != 0) { |
335 | - if(!empty($like_str)) |
|
335 | + if ( ! empty($like_str)) |
|
336 | 336 | $this->db->where($like_str); |
337 | - if($accounttype=='reseller'){ |
|
338 | - $this->db->where('a.note','b.number',false); |
|
339 | - $this->db->where('a.reseller_id',$account_arr['id']); |
|
340 | - $this->db->where('a.parent_id',$account_arr['reseller_id']); |
|
337 | + if ($accounttype == 'reseller') { |
|
338 | + $this->db->where('a.note', 'b.number', false); |
|
339 | + $this->db->where('a.reseller_id', $account_arr['id']); |
|
340 | + $this->db->where('a.parent_id', $account_arr['reseller_id']); |
|
341 | 341 | $this->db->select('count(a.id) as count'); |
342 | - $count_result=(array)$this->db->get('reseller_pricing as a,dids as b')->first_row(); |
|
342 | + $count_result = (array)$this->db->get('reseller_pricing as a,dids as b')->first_row(); |
|
343 | 343 | $paging_data = $this->form->load_grid_config($count_result['count'], $_GET['rp'], $_GET['page']); |
344 | 344 | $json_data = $paging_data["json_paging"]; |
345 | - $this->db->where('a.note','b.number',false); |
|
346 | - $this->db->where('a.reseller_id',$account_arr['id']); |
|
347 | - $this->db->where('a.parent_id',$account_arr['reseller_id']); |
|
345 | + $this->db->where('a.note', 'b.number', false); |
|
346 | + $this->db->where('a.reseller_id', $account_arr['id']); |
|
347 | + $this->db->where('a.parent_id', $account_arr['reseller_id']); |
|
348 | 348 | $this->db->select('a . * , b.id, a.reseller_id AS accountid,a.note as number,b.country_id as country_id'); |
349 | - $this->db->limit($paging_data["paging"]["page_no"],$paging_data["paging"]["start"]); |
|
350 | - $query=$this->db->get('reseller_pricing as a,dids as b'); |
|
351 | - }else{ |
|
352 | - $count_result=(array)$this->db->query('select count(id) as count from dids where accountid='.$accountid." AND parent_id =".$account_arr['reseller_id'])->first_row(); |
|
349 | + $this->db->limit($paging_data["paging"]["page_no"], $paging_data["paging"]["start"]); |
|
350 | + $query = $this->db->get('reseller_pricing as a,dids as b'); |
|
351 | + } else { |
|
352 | + $count_result = (array)$this->db->query('select count(id) as count from dids where accountid='.$accountid." AND parent_id =".$account_arr['reseller_id'])->first_row(); |
|
353 | 353 | $paging_data = $this->form->load_grid_config($count_result['count'], $_GET['rp'], $_GET['page']); |
354 | 354 | $json_data = $paging_data["json_paging"]; |
355 | - $query=$this->db->query("SELECT a . * ,a.note as number,b.country_id as country_id,b.id FROM reseller_pricing AS a, dids AS b WHERE b.accountid =".$account_arr['id']." AND a.note = b.number AND a.reseller_id =".$account_arr['reseller_id']); |
|
355 | + $query = $this->db->query("SELECT a . * ,a.note as number,b.country_id as country_id,b.id FROM reseller_pricing AS a, dids AS b WHERE b.accountid =".$account_arr['id']." AND a.note = b.number AND a.reseller_id =".$account_arr['reseller_id']); |
|
356 | 356 | } |
357 | - }else{ |
|
358 | - $like_str=!empty($instant_search) ? |
|
357 | + } else { |
|
358 | + $like_str = ! empty($instant_search) ? |
|
359 | 359 | "(dids.number like '%$instant_search%' |
360 | 360 | OR dids.inc like '%$instant_search%' |
361 | 361 | OR dids.cost like '%$instant_search%' |
@@ -363,14 +363,14 @@ discard block |
||
363 | 363 | OR dids.setup like '%$instant_search%' |
364 | 364 | OR dids.monthlycost like '%$instant_search%' |
365 | 365 | OR dids.connectcost like '%$instant_search%' |
366 | - )" :null; |
|
367 | - if(!empty($like_str)) |
|
366 | + )" : null; |
|
367 | + if ( ! empty($like_str)) |
|
368 | 368 | $this->db->where($like_str); |
369 | 369 | $where = array($field_name => $accountid); |
370 | 370 | $count_all = $this->db_model->countQuery("*", "dids", $where); |
371 | 371 | $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
372 | 372 | $json_data = $paging_data["json_paging"]; |
373 | - if(!empty($like_str)) |
|
373 | + if ( ! empty($like_str)) |
|
374 | 374 | $this->db->where($like_str); |
375 | 375 | $query = $this->db_model->select("*", "dids", $where, "id", "ASC", $paging_data["paging"]["page_no"], $paging_data["paging"]["start"]); |
376 | 376 | } |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | $ids = $this->input->post("selected_ids", true); |
383 | 383 | $where = "id IN ($ids)"; |
384 | 384 | $this->db->where($where); |
385 | - $this->db->select("group_concat(concat('''',number,'''')) as number",false); |
|
386 | - $dids_result=(array)$this->db->get('dids')->first_row(); |
|
387 | - $notes_where="note IN (".$dids_result['number'].")"; |
|
385 | + $this->db->select("group_concat(concat('''',number,'''')) as number", false); |
|
386 | + $dids_result = (array)$this->db->get('dids')->first_row(); |
|
387 | + $notes_where = "note IN (".$dids_result['number'].")"; |
|
388 | 388 | $this->db->where($notes_where); |
389 | 389 | $this->db->delete('reseller_pricing'); |
390 | 390 | $this->db->where($where); |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | */ |
399 | 399 | function did_reseller_edit($action = false, $id = false) { |
400 | 400 | $data['page_title'] = 'Edit DID '; |
401 | - $accountinfo=$this->session->userdata('accountinfo'); |
|
401 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
402 | 402 | if ($action == 'edit') { |
403 | 403 | if (($this->input->post())) { |
404 | 404 | $post = $this->input->post(); |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | $accountinfo = $this->did_model->get_account($accountinfo['number']); |
428 | 428 | $reseller_did = $this->db_model->getSelect("*", "reseller_pricing", array('id' => $id)); |
429 | 429 | $reseller_didinfo = (array)$reseller_did->first_row(); |
430 | - if (!empty($reseller_didinfo)) { |
|
430 | + if ( ! empty($reseller_didinfo)) { |
|
431 | 431 | $reseller_didinfo['setup'] = $this->common_model->to_calculate_currency($reseller_didinfo['setup'], '', '', true, false); |
432 | 432 | $reseller_didinfo['monthlycost'] = $this->common_model->to_calculate_currency($reseller_didinfo['monthlycost'], '', '', true, false); |
433 | 433 | $reseller_didinfo['connectcost'] = $this->common_model->to_calculate_currency($reseller_didinfo['connectcost'], '', '', true, false); |
@@ -441,43 +441,43 @@ discard block |
||
441 | 441 | } |
442 | 442 | } |
443 | 443 | if ($action == 'delete') { |
444 | - $this->db->where('id',$id); |
|
444 | + $this->db->where('id', $id); |
|
445 | 445 | $this->db->select('note'); |
446 | - $reseller_pricing=(array)$this->db->get('reseller_pricing')->first_row(); |
|
447 | - $did_number=$reseller_pricing['note']; |
|
448 | - $did_info=(array)$this->db->get_where('dids',array('number'=>$did_number))->first_row(); |
|
449 | - $query="select count(id) as count from reseller_pricing where id >= (select id from reseller_pricing where note =$did_number AND parent_id =".$accountinfo['reseller_id']." AND reseller_id =".$accountinfo['id'].") AND note= $did_number order by id desc"; |
|
450 | - $result=(array)$this->db->query($query)->first_row(); |
|
451 | - if($result['count'] > 0){ |
|
452 | - $str=$this->common->get_parent_info($did_info['parent_id'],$accountinfo['id']); |
|
453 | - $str=rtrim($str,","); |
|
454 | - $account_result=(array)$this->db->get_where('accounts',"id IN (".$str.")")->result_array(); |
|
455 | - foreach($account_result as $key=>$acc_row){ |
|
456 | - $acc_row['did_number']=$did_info['number']; |
|
446 | + $reseller_pricing = (array)$this->db->get('reseller_pricing')->first_row(); |
|
447 | + $did_number = $reseller_pricing['note']; |
|
448 | + $did_info = (array)$this->db->get_where('dids', array('number'=>$did_number))->first_row(); |
|
449 | + $query = "select count(id) as count from reseller_pricing where id >= (select id from reseller_pricing where note =$did_number AND parent_id =".$accountinfo['reseller_id']." AND reseller_id =".$accountinfo['id'].") AND note= $did_number order by id desc"; |
|
450 | + $result = (array)$this->db->query($query)->first_row(); |
|
451 | + if ($result['count'] > 0) { |
|
452 | + $str = $this->common->get_parent_info($did_info['parent_id'], $accountinfo['id']); |
|
453 | + $str = rtrim($str, ","); |
|
454 | + $account_result = (array)$this->db->get_where('accounts', "id IN (".$str.")")->result_array(); |
|
455 | + foreach ($account_result as $key=>$acc_row) { |
|
456 | + $acc_row['did_number'] = $did_info['number']; |
|
457 | 457 | $this->common->mail_to_users('email_remove_did', $acc_row); |
458 | 458 | } |
459 | - $reseller_ids=$this->common->get_subreseller_info($accountinfo['id']); |
|
460 | - $reseller_ids=rtrim($reseller_ids,","); |
|
461 | - $where="parent_id IN ($reseller_ids)"; |
|
462 | - $this->db->where('note',$did_info['number']); |
|
463 | - $this->db->delete('reseller_pricing',$where); |
|
464 | - $this->db->where('reseller_id',$accountinfo['id']); |
|
465 | - $this->db->where('note',$did_info['number']); |
|
459 | + $reseller_ids = $this->common->get_subreseller_info($accountinfo['id']); |
|
460 | + $reseller_ids = rtrim($reseller_ids, ","); |
|
461 | + $where = "parent_id IN ($reseller_ids)"; |
|
462 | + $this->db->where('note', $did_info['number']); |
|
463 | + $this->db->delete('reseller_pricing', $where); |
|
464 | + $this->db->where('reseller_id', $accountinfo['id']); |
|
465 | + $this->db->where('note', $did_info['number']); |
|
466 | 466 | $this->db->delete('reseller_pricing'); |
467 | 467 | } |
468 | - $this->db->where('number',$did_number); |
|
468 | + $this->db->where('number', $did_number); |
|
469 | 469 | $this->db->select('accountid'); |
470 | - $did_array=(array)$this->db->get('dids')->first_row(); |
|
471 | - if($did_array['accountid'] > 0){ |
|
472 | - $customer_info=(array)$this->db->get_where('accounts',array('id'=>$did_array['accountid']))->first_row(); |
|
473 | - $customer_info['did_number']=$did_number; |
|
470 | + $did_array = (array)$this->db->get('dids')->first_row(); |
|
471 | + if ($did_array['accountid'] > 0) { |
|
472 | + $customer_info = (array)$this->db->get_where('accounts', array('id'=>$did_array['accountid']))->first_row(); |
|
473 | + $customer_info['did_number'] = $did_number; |
|
474 | 474 | $this->common->mail_to_users('email_remove_did', $customer_info); |
475 | 475 | } |
476 | - $did_array=array("accountid"=>0,"parent_id"=>$accountinfo['reseller_id'], "assign_date" => "0000-00-00 00:00:00", "charge_upto" => "0000-00-00 00:00:00"); |
|
477 | - $this->db->where('number',$did_number); |
|
478 | - $this->db->update('dids',$did_array); |
|
476 | + $did_array = array("accountid"=>0, "parent_id"=>$accountinfo['reseller_id'], "assign_date" => "0000-00-00 00:00:00", "charge_upto" => "0000-00-00 00:00:00"); |
|
477 | + $this->db->where('number', $did_number); |
|
478 | + $this->db->update('dids', $did_array); |
|
479 | 479 | $this->session->set_flashdata('astpp_notification', 'DID Removed Successfully!'); |
480 | - redirect(base_url() . 'did/did_list/'); |
|
480 | + redirect(base_url().'did/did_list/'); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
@@ -486,37 +486,37 @@ discard block |
||
486 | 486 | $accountinfo = $this->session->userdata('accountinfo'); |
487 | 487 | $where = array('id' => $accountinfo['id']); |
488 | 488 | $account = $this->db_model->getSelect("*", "accounts", $where); |
489 | - $currency_name=$this->common->get_field_name('currency',"currency",array('id'=>$accountinfo['currency_id'])); |
|
490 | - $accountinfo= (array)$account->first_row(); |
|
489 | + $currency_name = $this->common->get_field_name('currency', "currency", array('id'=>$accountinfo['currency_id'])); |
|
490 | + $accountinfo = (array)$account->first_row(); |
|
491 | 491 | if (($this->input->post())) { |
492 | 492 | $post = $this->input->post(); |
493 | 493 | if (isset($post['free_did_list']) && $post['free_did_list'] != '') { |
494 | 494 | // For deduction of admin price to reseller |
495 | 495 | $didinfo = $this->did_model->get_did_by_number($post['free_did_list']); |
496 | - if($accountinfo['reseller_id'] > 0 ){ |
|
497 | - $reseller_pricing_query = $this->db_model->getSelect("call_type,setup,extensions,monthlycost,connectcost,includedseconds,cost,inc", "reseller_pricing", array("note" => $didinfo['number'],'reseller_id'=>$accountinfo['reseller_id'])); |
|
496 | + if ($accountinfo['reseller_id'] > 0) { |
|
497 | + $reseller_pricing_query = $this->db_model->getSelect("call_type,setup,extensions,monthlycost,connectcost,includedseconds,cost,inc", "reseller_pricing", array("note" => $didinfo['number'], 'reseller_id'=>$accountinfo['reseller_id'])); |
|
498 | 498 | $reseller_pricing_result = (array)$reseller_pricing_query->first_row(); |
499 | - $didinfo['call_type']=$reseller_pricing_result['call_type']; |
|
500 | - $didinfo['extensions']=$reseller_pricing_result['extensions']; |
|
501 | - $didinfo['setup']=$reseller_pricing_result['setup']; |
|
502 | - $didinfo['monthlycost']=$reseller_pricing_result['monthlycost']; |
|
503 | - $didinfo['connectcost']=$reseller_pricing_result['connectcost']; |
|
504 | - $didinfo['includedseconds']=$reseller_pricing_result['includedseconds']; |
|
505 | - $didinfo['cost']=$reseller_pricing_result['cost']; |
|
506 | - $didinfo['inc']=$reseller_pricing_result['inc']; |
|
499 | + $didinfo['call_type'] = $reseller_pricing_result['call_type']; |
|
500 | + $didinfo['extensions'] = $reseller_pricing_result['extensions']; |
|
501 | + $didinfo['setup'] = $reseller_pricing_result['setup']; |
|
502 | + $didinfo['monthlycost'] = $reseller_pricing_result['monthlycost']; |
|
503 | + $didinfo['connectcost'] = $reseller_pricing_result['connectcost']; |
|
504 | + $didinfo['includedseconds'] = $reseller_pricing_result['includedseconds']; |
|
505 | + $didinfo['cost'] = $reseller_pricing_result['cost']; |
|
506 | + $didinfo['inc'] = $reseller_pricing_result['inc']; |
|
507 | 507 | } |
508 | 508 | $available_bal = $this->db_model->get_available_bal($accountinfo); |
509 | 509 | $accountinfo['did_number'] = $didinfo['number']; |
510 | 510 | $accountinfo['did_country_id'] = $didinfo['country_id']; |
511 | - $accountinfo['did_setup'] = $this->common_model->calculate_currency($didinfo['setup'],'',$currency_name,true,true); |
|
512 | - $accountinfo['did_monthlycost'] = $this->common_model->calculate_currency($didinfo['monthlycost'],'',$currency_name,true,true); |
|
511 | + $accountinfo['did_setup'] = $this->common_model->calculate_currency($didinfo['setup'], '', $currency_name, true, true); |
|
512 | + $accountinfo['did_monthlycost'] = $this->common_model->calculate_currency($didinfo['monthlycost'], '', $currency_name, true, true); |
|
513 | 513 | $accountinfo['did_maxchannels'] = $didinfo['maxchannels']; |
514 | 514 | if ($available_bal >= $didinfo["setup"]) { |
515 | 515 | $available_bal = $this->db_model->update_balance($didinfo['setup'], $accountinfo['id'], "debit"); |
516 | - $this->db_model->update("dids", array('parent_id' => $accountinfo['id'],"assign_date"=>gmdate("Y-m-d H:i:s")), array("id" => $didinfo['id'])); |
|
516 | + $this->db_model->update("dids", array('parent_id' => $accountinfo['id'], "assign_date"=>gmdate("Y-m-d H:i:s")), array("id" => $didinfo['id'])); |
|
517 | 517 | $this->did_model->insert_reseller_pricing($accountinfo, $didinfo); |
518 | - $this->common->add_invoice_details($accountinfo,"DIDCHRG",$didinfo['setup'],$didinfo['number']); |
|
519 | - $this->common->mail_to_users('email_add_did', $accountinfo,"",$didinfo['number']); |
|
518 | + $this->common->add_invoice_details($accountinfo, "DIDCHRG", $didinfo['setup'], $didinfo['number']); |
|
519 | + $this->common->mail_to_users('email_add_did', $accountinfo, "", $didinfo['number']); |
|
520 | 520 | $this->session->set_flashdata('astpp_errormsg', 'DID Purchased Successfully.'); |
521 | 521 | } else { |
522 | 522 | $this->session->set_flashdata('astpp_notification', 'Insuffiecient fund to purchase this did'); |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | $this->session->set_flashdata('astpp_notification', 'Please Select DID.'); |
526 | 526 | } |
527 | 527 | } |
528 | - redirect(base_url() . 'did/did_list/'); |
|
528 | + redirect(base_url().'did/did_list/'); |
|
529 | 529 | exit; |
530 | 530 | } |
531 | 531 | |
@@ -547,8 +547,8 @@ discard block |
||
547 | 547 | |
548 | 548 | function did_download_sample_file($file_name) { |
549 | 549 | $this->load->helper('download'); |
550 | - $full_path = base_url() . "assets/Rates_File/" . $file_name . ".csv"; |
|
551 | - $arrContextOptions=array( |
|
550 | + $full_path = base_url()."assets/Rates_File/".$file_name.".csv"; |
|
551 | + $arrContextOptions = array( |
|
552 | 552 | "ssl"=>array( |
553 | 553 | "verify_peer"=>false, |
554 | 554 | "verify_peer_name"=>false, |
@@ -567,28 +567,28 @@ discard block |
||
567 | 567 | $this->session->set_userdata('import_did_rate_csv', ""); |
568 | 568 | $error_data = $this->session->userdata('import_did_csv_error'); |
569 | 569 | $full_path = $this->config->item('rates-file-path'); |
570 | - if (file_exists($full_path . $error_data) && $error_data != "") { |
|
571 | - unlink($full_path . $error_data); |
|
570 | + if (file_exists($full_path.$error_data) && $error_data != "") { |
|
571 | + unlink($full_path.$error_data); |
|
572 | 572 | $this->session->set_userdata('import_did_csv_error', ""); |
573 | 573 | } |
574 | - $accountinfo=$this->session->userdata('accountinfo'); |
|
575 | - $this->db->where('id',$accountinfo['currency_id']); |
|
574 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
575 | + $this->db->where('id', $accountinfo['currency_id']); |
|
576 | 576 | $this->db->select('currency'); |
577 | - $currency_info=(array)$this->db->get('currency')->first_row(); |
|
578 | - $data['fields']="DID,Country,Account,Per Minute Cost(".$currency_info['currency']."),Initial Increment,Increment,Setup Fee(".$currency_info['currency']."),Monthly Fee(".$currency_info['currency']."),Call Type,Destination,Status"; |
|
577 | + $currency_info = (array)$this->db->get('currency')->first_row(); |
|
578 | + $data['fields'] = "DID,Country,Account,Per Minute Cost(".$currency_info['currency']."),Initial Increment,Increment,Setup Fee(".$currency_info['currency']."),Monthly Fee(".$currency_info['currency']."),Call Type,Destination,Status"; |
|
579 | 579 | $this->load->view('view_import_did', $data); |
580 | 580 | } |
581 | 581 | |
582 | 582 | function did_preview_file() { |
583 | 583 | $data['page_title'] = 'Import DIDs'; |
584 | 584 | $config_did_array = $this->config->item('DID-rates-field'); |
585 | - $accountinfo=$this->session->userdata('accountinfo'); |
|
586 | - $this->db->where('id',$accountinfo['currency_id']); |
|
585 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
586 | + $this->db->where('id', $accountinfo['currency_id']); |
|
587 | 587 | $this->db->select('currency'); |
588 | - $currency_info=(array)$this->db->get('currency')->first_row(); |
|
589 | - foreach($config_did_array as $key=>$value){ |
|
588 | + $currency_info = (array)$this->db->get('currency')->first_row(); |
|
589 | + foreach ($config_did_array as $key=>$value) { |
|
590 | 590 | $key = str_replace('CURRENCY', $currency_info['currency'], $key); |
591 | - $did_fields_array[$key]=$value; |
|
591 | + $did_fields_array[$key] = $value; |
|
592 | 592 | } |
593 | 593 | $check_header = $this->input->post('check_header', true); |
594 | 594 | $invalid_flag = false; |
@@ -599,10 +599,10 @@ discard block |
||
599 | 599 | if ($error == 0) { |
600 | 600 | $uploadedFile = $_FILES["didimport"]["tmp_name"]; |
601 | 601 | $full_path = $this->config->item('rates-file-path'); |
602 | - $actual_file_name = "ASTPP-DIDs-" . date("Y-m-d H:i:s") . "." . $ext; |
|
603 | - if (move_uploaded_file($uploadedFile, $full_path . $actual_file_name)) { |
|
602 | + $actual_file_name = "ASTPP-DIDs-".date("Y-m-d H:i:s").".".$ext; |
|
603 | + if (move_uploaded_file($uploadedFile, $full_path.$actual_file_name)) { |
|
604 | 604 | $data['page_title'] = 'Import DIDs Preview'; |
605 | - $data['csv_tmp_data'] = $this->csvreader->parse_file($full_path . $actual_file_name, $did_fields_array, $check_header); |
|
605 | + $data['csv_tmp_data'] = $this->csvreader->parse_file($full_path.$actual_file_name, $did_fields_array, $check_header); |
|
606 | 606 | $data['provider_id'] = $_POST['provider_id']; |
607 | 607 | $data['check_header'] = $check_header; |
608 | 608 | $this->session->set_userdata('import_did_rate_csv', $actual_file_name); |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | if ($invalid_flag) { |
620 | 620 | $str = ''; |
621 | 621 | if (empty($_FILES['didimport']['name'])) { |
622 | - $str.= '<br/>Please Select File.'; |
|
622 | + $str .= '<br/>Please Select File.'; |
|
623 | 623 | } |
624 | 624 | $data['error'] = $str; |
625 | 625 | } |
@@ -630,32 +630,32 @@ discard block |
||
630 | 630 | $new_final_arr = array(); |
631 | 631 | $invalid_array = array(); |
632 | 632 | $new_final_arr_key = $this->config->item('DID-rates-field'); |
633 | - $accountinfo=$this->session->userdata('accountinfo'); |
|
634 | - $reseller_id = $accountinfo['type']==1 ? $accountinfo['id']: 0; |
|
633 | + $accountinfo = $this->session->userdata('accountinfo'); |
|
634 | + $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0; |
|
635 | 635 | |
636 | 636 | $full_path = $this->config->item('rates-file-path'); |
637 | 637 | $did_file_name = $this->session->userdata('import_did_rate_csv'); |
638 | - $csv_tmp_data = $this->csvreader->parse_file($full_path . $did_file_name, $new_final_arr_key, $check_header); |
|
638 | + $csv_tmp_data = $this->csvreader->parse_file($full_path.$did_file_name, $new_final_arr_key, $check_header); |
|
639 | 639 | $flag = false; |
640 | 640 | $i = 0; |
641 | 641 | $number_arr = array(); |
642 | - $reseller_array=array(); |
|
643 | - $final_reseller_array=array(); |
|
642 | + $reseller_array = array(); |
|
643 | + $final_reseller_array = array(); |
|
644 | 644 | foreach ($csv_tmp_data as $key => $csv_data) { |
645 | 645 | |
646 | 646 | if (isset($csv_data['number']) && $csv_data['number'] != '' && $i != 0) { |
647 | 647 | $str = null; |
648 | - if(isset($csv_data['call_type'])){ |
|
649 | - if(strtolower($csv_data['call_type']) == 'sip-did'){ |
|
648 | + if (isset($csv_data['call_type'])) { |
|
649 | + if (strtolower($csv_data['call_type']) == 'sip-did') { |
|
650 | 650 | $call_type = '3'; |
651 | - } else if(strtolower($csv_data['call_type']) == 'did-local'){ |
|
651 | + } else if (strtolower($csv_data['call_type']) == 'did-local') { |
|
652 | 652 | $call_type = '1'; |
653 | - } else if(strtolower($csv_data['call_type']) == 'other'){ |
|
653 | + } else if (strtolower($csv_data['call_type']) == 'other') { |
|
654 | 654 | $call_type = '2'; |
655 | 655 | } else { |
656 | 656 | $call_type = '0'; |
657 | 657 | } |
658 | - } else{ |
|
658 | + } else { |
|
659 | 659 | $call_type = '0'; |
660 | 660 | } |
661 | 661 | $csv_data['accountid'] = isset($csv_data['accountid']) ? $csv_data['accountid'] : 0; |
@@ -664,77 +664,77 @@ discard block |
||
664 | 664 | $csv_data['call_type'] = $call_type; |
665 | 665 | $csv_data['extensions'] = isset($csv_data['extensions']) ? $csv_data['extensions'] : ''; |
666 | 666 | $csv_data['includedseconds'] = isset($csv_data['includedseconds']) ? $csv_data['includedseconds'] : 0; |
667 | - $csv_data['cost'] = !empty($csv_data['cost']) && is_numeric($csv_data['cost']) && $csv_data['cost'] ? $csv_data['cost'] : 0; |
|
668 | - $csv_data['setup'] = !empty($csv_data['setup']) && is_numeric($csv_data['setup']) && $csv_data['setup'] > 0 ? $csv_data['setup'] : 0; |
|
669 | - $csv_data['monthlycost'] = !empty($csv_data['monthlycost']) && is_numeric($csv_data['monthlycost']) && $csv_data['monthlycost'] > 0 ? $csv_data['monthlycost'] : 0; |
|
670 | - $csv_data['connectcost'] = !empty($csv_data['connectcost']) && is_numeric($csv_data['connectcost']) && $csv_data['connectcost'] > 0 ? $csv_data['connectcost'] : 0; |
|
667 | + $csv_data['cost'] = ! empty($csv_data['cost']) && is_numeric($csv_data['cost']) && $csv_data['cost'] ? $csv_data['cost'] : 0; |
|
668 | + $csv_data['setup'] = ! empty($csv_data['setup']) && is_numeric($csv_data['setup']) && $csv_data['setup'] > 0 ? $csv_data['setup'] : 0; |
|
669 | + $csv_data['monthlycost'] = ! empty($csv_data['monthlycost']) && is_numeric($csv_data['monthlycost']) && $csv_data['monthlycost'] > 0 ? $csv_data['monthlycost'] : 0; |
|
670 | + $csv_data['connectcost'] = ! empty($csv_data['connectcost']) && is_numeric($csv_data['connectcost']) && $csv_data['connectcost'] > 0 ? $csv_data['connectcost'] : 0; |
|
671 | 671 | $csv_data['inc'] = isset($csv_data['inc']) ? $csv_data['inc'] : 0; |
672 | 672 | $str = $this->data_validate($csv_data); |
673 | 673 | if ($str != "") { |
674 | 674 | $invalid_array[$i] = $csv_data; |
675 | 675 | $invalid_array[$i]['error'] = $str; |
676 | 676 | } else { |
677 | - if (!in_array($csv_data['number'], $number_arr)) { |
|
677 | + if ( ! in_array($csv_data['number'], $number_arr)) { |
|
678 | 678 | $number_count = $this->db_model->countQuery('id', 'dids', array('number' => $csv_data['number'])); |
679 | 679 | if ($number_count > 0) { |
680 | 680 | $invalid_array[$i] = $csv_data; |
681 | 681 | $invalid_array[$i]['error'] = 'Duplicate DID found from database'; |
682 | 682 | } else { |
683 | - if($csv_data['accountid'] > 0 && $csv_data['setup'] > 0){ |
|
683 | + if ($csv_data['accountid'] > 0 && $csv_data['setup'] > 0) { |
|
684 | 684 | $this->db->where('type IN(0,1,3)'); |
685 | - $this->db->where('reseller_id',0); |
|
686 | - $this->db->where('deleted',0); |
|
687 | - $this->db->where('status',0); |
|
688 | - $account_info=(array)$this->db->get_where('accounts',array("number"=>$csv_data['accountid']))->first_row(); |
|
689 | - if($account_info){ |
|
690 | - $account_balance=$this->db_model->get_available_bal($account_info); |
|
685 | + $this->db->where('reseller_id', 0); |
|
686 | + $this->db->where('deleted', 0); |
|
687 | + $this->db->where('status', 0); |
|
688 | + $account_info = (array)$this->db->get_where('accounts', array("number"=>$csv_data['accountid']))->first_row(); |
|
689 | + if ($account_info) { |
|
690 | + $account_balance = $this->db_model->get_available_bal($account_info); |
|
691 | 691 | $setup = $this->common_model->add_calculate_currency($csv_data['setup'], '', '', false, false); |
692 | - if($account_balance >= $setup){ |
|
693 | - $field_name=$account_info['type']==1 ? 'parent_id':'accountid'; |
|
694 | - $currency_name=$this->common->get_field_name('currency',"currency",array('id'=>$account_info['currency_id'])); |
|
692 | + if ($account_balance >= $setup) { |
|
693 | + $field_name = $account_info['type'] == 1 ? 'parent_id' : 'accountid'; |
|
694 | + $currency_name = $this->common->get_field_name('currency', "currency", array('id'=>$account_info['currency_id'])); |
|
695 | 695 | $csv_data['monthlycost'] = $this->common_model->add_calculate_currency($csv_data['monthlycost'], '', '', false, false); |
696 | 696 | $csv_data['cost'] = $this->common_model->add_calculate_currency($csv_data['cost'], '', '', false, false); |
697 | 697 | $csv_data['connectcost'] = $this->common_model->add_calculate_currency($csv_data['connectcost'], '', '', false, false); |
698 | - $csv_data['setup']=$setup; |
|
699 | - $csv_data[$field_name]=$account_info['id']; |
|
700 | - $csv_data['status']=$this->common->get_import_status($csv_data['status']); |
|
701 | - $available_bal = $this->db_model->update_balance($csv_data["setup"],$account_info['id'], "debit"); |
|
698 | + $csv_data['setup'] = $setup; |
|
699 | + $csv_data[$field_name] = $account_info['id']; |
|
700 | + $csv_data['status'] = $this->common->get_import_status($csv_data['status']); |
|
701 | + $available_bal = $this->db_model->update_balance($csv_data["setup"], $account_info['id'], "debit"); |
|
702 | 702 | $account_info['did_number'] = $csv_data['number']; |
703 | 703 | $account_info['did_country_id'] = $csv_data['country_id']; |
704 | - $account_info['did_setup'] = $this->common_model->calculate_currency($csv_data['setup'],'',$currency_name,true,true); |
|
705 | - $account_info['did_monthlycost'] = $this->common_model->calculate_currency($csv_data['monthlycost'],'',$currency_name,true,true); |
|
704 | + $account_info['did_setup'] = $this->common_model->calculate_currency($csv_data['setup'], '', $currency_name, true, true); |
|
705 | + $account_info['did_monthlycost'] = $this->common_model->calculate_currency($csv_data['monthlycost'], '', $currency_name, true, true); |
|
706 | 706 | $account_info['did_maxchannels'] = "0"; |
707 | - $csv_data['country_id']=$this->common->get_field_name('id','countrycode',array("country"=>$csv_data['country_id'])); |
|
708 | - if($account_info['type']==1){ |
|
709 | - $reseller_array=$csv_data; |
|
710 | - $reseller_array['note']=$csv_data['number']; |
|
711 | - $reseller_array['reseller_id']=$account_info['id']; |
|
712 | - $reseller_array['parent_id']=$account_info['reseller_id']; |
|
713 | - $reseller_array['assign_date']=gmdate("Y-m-d H:i:s"); |
|
714 | - unset($reseller_array['number'],$csv_data['accountid'],$reseller_array['accountid'],$reseller_array['country_id'],$reseller_array['init_inc']); |
|
715 | - $csv_data['accountid']=0; |
|
716 | - $final_reseller_array[$i]=$reseller_array; |
|
717 | - }else{ |
|
718 | - $csv_data['parent_id']=0; |
|
707 | + $csv_data['country_id'] = $this->common->get_field_name('id', 'countrycode', array("country"=>$csv_data['country_id'])); |
|
708 | + if ($account_info['type'] == 1) { |
|
709 | + $reseller_array = $csv_data; |
|
710 | + $reseller_array['note'] = $csv_data['number']; |
|
711 | + $reseller_array['reseller_id'] = $account_info['id']; |
|
712 | + $reseller_array['parent_id'] = $account_info['reseller_id']; |
|
713 | + $reseller_array['assign_date'] = gmdate("Y-m-d H:i:s"); |
|
714 | + unset($reseller_array['number'], $csv_data['accountid'], $reseller_array['accountid'], $reseller_array['country_id'], $reseller_array['init_inc']); |
|
715 | + $csv_data['accountid'] = 0; |
|
716 | + $final_reseller_array[$i] = $reseller_array; |
|
717 | + } else { |
|
718 | + $csv_data['parent_id'] = 0; |
|
719 | 719 | } |
720 | - $csv_data['assign_date']=gmdate("Y-m-d H:i:s"); |
|
720 | + $csv_data['assign_date'] = gmdate("Y-m-d H:i:s"); |
|
721 | 721 | $new_final_arr[$i] = $csv_data; |
722 | 722 | $this->common->mail_to_users('email_add_did', $account_info); |
723 | - }else{ |
|
723 | + } else { |
|
724 | 724 | $invalid_array[$i] = $csv_data; |
725 | 725 | $invalid_array[$i]['error'] = 'Account have not sufficient amount to purchase this DID.'; |
726 | 726 | } |
727 | - }else{ |
|
727 | + } else { |
|
728 | 728 | $invalid_array[$i] = $csv_data; |
729 | 729 | $invalid_array[$i]['error'] = 'Account not found or assign to invalid account'; |
730 | 730 | } |
731 | - }else{ |
|
731 | + } else { |
|
732 | 732 | $csv_data['setup'] = $this->common_model->add_calculate_currency($csv_data['setup'], '', '', false, false); |
733 | 733 | $csv_data['monthlycost'] = $this->common_model->add_calculate_currency($csv_data['monthlycost'], '', '', false, false); |
734 | 734 | $csv_data['cost'] = $this->common_model->add_calculate_currency($csv_data['cost'], '', '', false, false); |
735 | 735 | $csv_data['connectcost'] = $this->common_model->add_calculate_currency($csv_data['connectcost'], '', '', false, false); |
736 | - $csv_data['accountid']=0; |
|
737 | - $csv_data['country_id']=$this->common->get_field_name('id','countrycode',array("country"=>$csv_data['country_id'])); |
|
736 | + $csv_data['accountid'] = 0; |
|
737 | + $csv_data['country_id'] = $this->common->get_field_name('id', 'countrycode', array("country"=>$csv_data['country_id'])); |
|
738 | 738 | $new_final_arr[$i] = $csv_data; |
739 | 739 | } |
740 | 740 | } |
@@ -747,17 +747,17 @@ discard block |
||
747 | 747 | } |
748 | 748 | $i++; |
749 | 749 | } |
750 | - if (!empty($new_final_arr)) { |
|
750 | + if ( ! empty($new_final_arr)) { |
|
751 | 751 | $result = $this->did_model->bulk_insert_dids($new_final_arr); |
752 | 752 | } |
753 | - if(!empty($final_reseller_array)){ |
|
753 | + if ( ! empty($final_reseller_array)) { |
|
754 | 754 | $this->db->insert_batch('reseller_pricing', $final_reseller_array); |
755 | 755 | } |
756 | 756 | unlink($full_path.$did_file_name); |
757 | 757 | $count = count($invalid_array); |
758 | 758 | if ($count > 0) { |
759 | 759 | $session_id = "-1"; |
760 | - $fp = fopen($full_path . $session_id . '.csv', 'w'); |
|
760 | + $fp = fopen($full_path.$session_id.'.csv', 'w'); |
|
761 | 761 | foreach ($new_final_arr_key as $key => $value) { |
762 | 762 | $custom_array[0][$key] = ucfirst($key); |
763 | 763 | } |
@@ -767,16 +767,16 @@ discard block |
||
767 | 767 | fputcsv($fp, $err_data); |
768 | 768 | } |
769 | 769 | fclose($fp); |
770 | - $this->session->set_userdata('import_did_csv_error', $session_id . ".csv"); |
|
770 | + $this->session->set_userdata('import_did_csv_error', $session_id.".csv"); |
|
771 | 771 | $data["error"] = $invalid_array; |
772 | 772 | $data['provider_id'] = $provider_id; |
773 | - $data['import_record_count'] = count($new_final_arr)+count($reseller_array); |
|
773 | + $data['import_record_count'] = count($new_final_arr) + count($reseller_array); |
|
774 | 774 | $data['failure_count'] = count($invalid_array) - 1; |
775 | 775 | $data['page_title'] = 'DID Import Error'; |
776 | 776 | $this->load->view('view_import_error', $data); |
777 | 777 | } else { |
778 | - $this->session->set_flashdata('astpp_errormsg', 'Total ' . count($new_final_arr) . ' DIDs Imported Successfully!'); |
|
779 | - redirect(base_url() . "did/did_list/"); |
|
778 | + $this->session->set_flashdata('astpp_errormsg', 'Total '.count($new_final_arr).' DIDs Imported Successfully!'); |
|
779 | + redirect(base_url()."did/did_list/"); |
|
780 | 780 | } |
781 | 781 | } |
782 | 782 | |
@@ -785,17 +785,17 @@ discard block |
||
785 | 785 | $alpha_regex = "/^[a-z ,.'-]+$/i"; |
786 | 786 | $alpha_numeric_regex = "/^[a-z0-9 ,.'-]+$/i"; |
787 | 787 | $email_regex = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/"; |
788 | - $str.= $csvdata['number'] != '' ? null : 'Number,'; |
|
788 | + $str .= $csvdata['number'] != '' ? null : 'Number,'; |
|
789 | 789 | $str = rtrim($str, ','); |
790 | - if (!$str) { |
|
791 | - $str.= is_numeric($csvdata['number']) ? null : 'Number,'; |
|
792 | - $str.=!empty($csvdata['connectcost']) && is_numeric($csvdata['connectcost']) ? null : ( empty($csvdata['connectcost']) ? null : 'Connect Cost,'); |
|
793 | - $str.=!empty($csvdata['includedseconds']) && is_numeric($csvdata['includedseconds']) ? null : ( empty($csvdata['includedseconds']) ? null : 'Included Seconds,'); |
|
790 | + if ( ! $str) { |
|
791 | + $str .= is_numeric($csvdata['number']) ? null : 'Number,'; |
|
792 | + $str .= ! empty($csvdata['connectcost']) && is_numeric($csvdata['connectcost']) ? null : (empty($csvdata['connectcost']) ? null : 'Connect Cost,'); |
|
793 | + $str .= ! empty($csvdata['includedseconds']) && is_numeric($csvdata['includedseconds']) ? null : (empty($csvdata['includedseconds']) ? null : 'Included Seconds,'); |
|
794 | 794 | if ($str) { |
795 | 795 | $str = rtrim($str, ','); |
796 | 796 | $error_field = explode(',', $str); |
797 | 797 | $count = count($error_field); |
798 | - $str.= $count > 1 ? ' are not valid' : ' is not Valid'; |
|
798 | + $str .= $count > 1 ? ' are not valid' : ' is not Valid'; |
|
799 | 799 | return $str; |
800 | 800 | } else { |
801 | 801 | return false; |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | $str = rtrim($str, ','); |
805 | 805 | $error_field = explode(',', $str); |
806 | 806 | $count = count($error_field); |
807 | - $str.= $count > 1 ? ' are required' : ' is Required'; |
|
807 | + $str .= $count > 1 ? ' are required' : ' is Required'; |
|
808 | 808 | return $str; |
809 | 809 | } |
810 | 810 | } |
@@ -813,38 +813,38 @@ discard block |
||
813 | 813 | $this->load->helper('download'); |
814 | 814 | $error_data = $this->session->userdata('import_did_csv_error'); |
815 | 815 | $full_path = $this->config->item('rates-file-path'); |
816 | - $data = file_get_contents($full_path . $error_data); |
|
816 | + $data = file_get_contents($full_path.$error_data); |
|
817 | 817 | force_download("error_did_rates.csv", $data); |
818 | 818 | } |
819 | 819 | |
820 | 820 | function did_export_data_xls() { |
821 | 821 | $account_info = $accountinfo = $this->session->userdata('accountinfo'); |
822 | - $currency_id=$account_info['currency_id']; |
|
823 | - $currency=$this->common->get_field_name('currency', 'currency', $currency_id); |
|
822 | + $currency_id = $account_info['currency_id']; |
|
823 | + $currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
|
824 | 824 | $query = $this->did_model->getdid_list(true, '0', '10000000'); |
825 | 825 | ob_clean(); |
826 | - $outbound_array[] = array("DID", "Country", "Account","Per Minute Cost($currency)","Initial Increment","Increment","Setup Fee($currency)","Monthly Fee($currency)","Call Type","Destination","Status","Modified Date","Is Purchased"); |
|
826 | + $outbound_array[] = array("DID", "Country", "Account", "Per Minute Cost($currency)", "Initial Increment", "Increment", "Setup Fee($currency)", "Monthly Fee($currency)", "Call Type", "Destination", "Status", "Modified Date", "Is Purchased"); |
|
827 | 827 | if ($query->num_rows() > 0) { |
828 | 828 | foreach ($query->result_array() as $row) { |
829 | 829 | $outbound_array[] = array( |
830 | 830 | $row['number'], |
831 | 831 | $this->common->get_field_name("country", "countrycode", $row['country_id']), |
832 | 832 | $this->common->get_field_name("number", "accounts", $row['accountid']), |
833 | - $this->common_model->calculate_currency($row['cost'], '', '',true, false), |
|
833 | + $this->common_model->calculate_currency($row['cost'], '', '', true, false), |
|
834 | 834 | $row['init_inc'], |
835 | 835 | $row['inc'], |
836 | - $this->common_model->calculate_currency($row['setup'], '', '',true, false), |
|
837 | - $this->common_model->calculate_currency($row['monthlycost'], '', '',true, false), |
|
838 | - $this->common->get_call_type("","",$row['call_type']), |
|
836 | + $this->common_model->calculate_currency($row['setup'], '', '', true, false), |
|
837 | + $this->common_model->calculate_currency($row['monthlycost'], '', '', true, false), |
|
838 | + $this->common->get_call_type("", "", $row['call_type']), |
|
839 | 839 | $row['extensions'], |
840 | - $this->common->get_status('export','',$row['status']), |
|
840 | + $this->common->get_status('export', '', $row['status']), |
|
841 | 841 | $row['last_modified_date'], |
842 | 842 | $this->common->check_did_avl_export($row['number']) |
843 | 843 | ); |
844 | 844 | } |
845 | 845 | } |
846 | 846 | $this->load->helper('csv'); |
847 | - array_to_csv($outbound_array, 'DIDs_' . date("Y-m-d") . '.csv'); |
|
847 | + array_to_csv($outbound_array, 'DIDs_'.date("Y-m-d").'.csv'); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | } |