Completed
Pull Request — v3.0 (#136)
by
unknown
25:07
created
freeswitch/fs/lib/astpp.cdr.php 4 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -189,6 +189,10 @@  discard block
 block discarded – undo
189 189
 }
190 190
 
191 191
 //Insert parent resellers cdr
192
+/**
193
+ * @param string $provider_cost
194
+ * @param boolean $flag_parent
195
+ */
192 196
 function insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points)
193 197
 {
194 198
 	while($parentid > 0 )
@@ -250,6 +254,9 @@  discard block
 block discarded – undo
250 254
 }
251 255
 
252 256
 //Insert callee cdr entry for DID calls
257
+/**
258
+ * @param boolean $flag_parent
259
+ */
253 260
 function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points)
254 261
 {
255 262
 		$localVariable = $dataVariable;
@@ -318,6 +325,9 @@  discard block
 block discarded – undo
318 325
 }
319 326
 
320 327
 //Update user balance
328
+/**
329
+ * @param integer $entity_id
330
+ */
321 331
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
322 332
     $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
323 333
     $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id;
@@ -457,6 +467,9 @@  discard block
 block discarded – undo
457 467
 }
458 468
 
459 469
 // String append prefix for checking rates
470
+/**
471
+ * @param string $field
472
+ */
460 473
 function number_loop($destination,$field,$db)
461 474
 {
462 475
 	$max_len_prefix  = strlen($destination);
@@ -471,6 +484,9 @@  discard block
 block discarded – undo
471 484
 }
472 485
 
473 486
 //Convert current time to GMT
487
+/**
488
+ * @param string $date
489
+ */
474 490
 function convert_to_gmt($date)
475 491
 {
476 492
 	return gmdate('Y-m-d H:i:s', strtotime($date) );
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -26,36 +26,36 @@  discard block
 block discarded – undo
26 26
 {
27 27
 	//$logger->log(print_r($data,true));//exit;
28 28
 
29
-    //Initializing variables 
29
+	//Initializing variables 
30 30
 	$origination_rate = array();
31 31
 	$termination_rate = array();
32 32
 
33
-    //FS CDR variables 
33
+	//FS CDR variables 
34 34
 	$dataVariable = $data['variables'];
35 35
 
36
-    //FS CDR Call flow variables 
36
+	//FS CDR Call flow variables 
37 37
 	$dataCallflow = $data['callflow'];
38 38
 
39
-    //Get account id
39
+	//Get account id
40 40
 	$accountid = isset($dataVariable['account_id']) ? $dataVariable['account_id'] : '0';
41 41
 
42
-    //Get caller id name and number 
42
+	//Get caller id name and number 
43 43
 	$dataVariable['effective_caller_id_name'] = (isset($dataVariable['effective_caller_id_name'])) ? $dataVariable['effective_caller_id_name'] : $dataCallflow['caller_profile']['caller_id_name'];
44 44
 	$dataVariable['effective_caller_id_number'] = (isset($dataVariable['effective_caller_id_number'])) ? $dataVariable['effective_caller_id_number'] : $dataCallflow['caller_profile']['caller_id_number'];
45 45
 
46 46
 
47
-    if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING')
48
-    {
49
-        $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause'];
50
-    }else{
51
-        $hangup_cause = $dataVariable['hangup_cause'];
52
-    }   
47
+	if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING')
48
+	{
49
+		$hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause'];
50
+	}else{
51
+		$hangup_cause = $dataVariable['hangup_cause'];
52
+	}   
53 53
 
54
-    if ($dataVariable['error_cdr'] == '1')
55
-    {
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']); 
58
-    }
54
+	if ($dataVariable['error_cdr'] == '1')
55
+	{
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']); 
58
+	}
59 59
 
60 60
 	/*#### PATCH FOR ONE WAY AUDIO ####*/
61 61
 	if ($hangup_cause == "NORMAL_UNSPECIFIED" && $dataVariable['billsec'] > 0)
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 	}
65 65
 	/*#### ************* END *************####*/
66 66
 
67
-    //Don't thing this will be useful anytime. Need to remove it after testing. 
67
+	//Don't thing this will be useful anytime. Need to remove it after testing. 
68 68
 	if($hangup_cause == "NONE")
69 69
 	{
70 70
 		$hangup_cause = $dataVariable['current_application_data'];
71 71
 	}
72 72
 
73
-    $dataVariable['hangup_cause'] = $hangup_cause;
73
+	$dataVariable['hangup_cause'] = $hangup_cause;
74 74
 
75 75
 	if ( ($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) {
76 76
 	  	$dataVariable['billsec'] = 0;
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	$dataVariable['calltype'] = isset($dataVariable['calltype']) ? $dataVariable['calltype'] : "STANDARD";
86 86
 	$actual_calltype = $dataVariable['calltype'];
87 87
 	
88
-    //Normalize origination and termination rates array 		   
88
+	//Normalize origination and termination rates array 		   
89 89
 	if(isset($dataVariable['origination_rates']))
90 90
 	   $origination_rate = normalize_origination_rate($dataVariable['origination_rates']);
91 91
 	if(isset($dataVariable['termination_rates']))
92 92
 	   $termination_rate = normalize_rate($dataVariable['termination_rates']);
93 93
 
94
-    //If receiver account id found then explicitly set call direction and call type 
94
+	//If receiver account id found then explicitly set call direction and call type 
95 95
 	if(isset($dataVariable['receiver_accid']))
96 96
 	{
97 97
 		$dataVariable['call_direction'] = "outbound";
98
-        $dataVariable['calltype'] = "STANDARD";
98
+		$dataVariable['calltype'] = "STANDARD";
99 99
 	}
100 100
 
101
-    //Check if cusotmer have any package seconds left to use
101
+	//Check if cusotmer have any package seconds left to use
102 102
 	if ($actual_duration > 0)			
103
-    {
103
+	{
104 104
 			$package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger);
105 105
 			if(!empty($package_array))
106 106
 			{
@@ -109,20 +109,20 @@  discard block
 block discarded – undo
109 109
 			}
110 110
 	}
111 111
 	
112
-    //Calculate debit of customer call 			
112
+	//Calculate debit of customer call 			
113 113
 	$debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points);
114 114
 
115
-    //Calculate cost for customer call for provider
115
+	//Calculate cost for customer call for provider
116 116
 	$provider_cost = calc_cost($dataVariable,$termination_rate,$logger,$decimal_points);
117 117
 
118
-    //Calculate parent cost if customer have any parent 
118
+	//Calculate parent cost if customer have any parent 
119 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);
120
+	$logger->log("Debit :".$debit ." Cost : ".$cost ." Provider Cost : ".$parent_cost);
121 121
     
122
-    //Initialize final cost variable to use for billing
122
+	//Initialize final cost variable to use for billing
123 123
 	$cost = ($parent_cost > 0) ? $parent_cost : $provider_cost;    
124 124
 	
125
-    //Outbound call entry for all type of calls 
125
+	//Outbound call entry for all type of calls 
126 126
 	$logger->log("*********************** OUTBOUND CALL ENTRY START *************");
127 127
 
128 128
 	$cdr_string = get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger);
@@ -131,60 +131,60 @@  discard block
 block discarded – undo
131 131
 	$logger->log($query);
132 132
 	$db->run($query);
133 133
 	
134
-    //Update customer balance
134
+	//Update customer balance
135 135
 	if($debit > 0 && $dataVariable['calltype'] != "FREE")
136 136
 	{
137 137
 		update_balance($accountid, $debit, 0, $logger, $db);
138 138
 	}
139 139
 
140
-    //Update parent or provider balance
140
+	//Update parent or provider balance
141 141
 	if($parent_cost > 0){
142 142
 		update_balance($termination_rate['PROVIDER'], ($parent_cost * -1), 3, $logger, $db);
143 143
 	}
144 144
 
145
-    //Resellers CDR entry
146
-    $flag_parent = false;
147
-    insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points);
145
+	//Resellers CDR entry
146
+	$flag_parent = false;
147
+	insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points);
148 148
 
149
-    $logger->log("*********************** OUTBOUND CALL ENTRY END *************");
149
+	$logger->log("*********************** OUTBOUND CALL ENTRY END *************");
150 150
 
151 151
    
152
-    //************ ADDING EXTRA ENTRY For local/DID Inbound call ****************************
152
+	//************ ADDING EXTRA ENTRY For local/DID Inbound call ****************************
153 153
 	$receiver_parentid=0;
154 154
 	if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "")
155 155
 	{
156
-    	$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************");            
156
+		$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************");            
157 157
 
158
-        //Explicitly set call direction and call type 
158
+		//Explicitly set call direction and call type 
159 159
 		$dataVariable['call_direction'] = "inbound";
160
-        $dataVariable['calltype'] = "DID";
160
+		$dataVariable['calltype'] = "DID";
161 161
 
162
-        //Override variables if call for DID PSTN
163
-        if(isset($dataVariable['caller_did_account_id']))
164
-        {
165
-            $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id'];
166
-    		$dataVariable['call_direction'] = "outbound";
167
-            $dataVariable['calltype'] = "STANDARD";
168
-            unset($termination_rate);
169
-            unset($provider_cost);
170
-        }
162
+		//Override variables if call for DID PSTN
163
+		if(isset($dataVariable['caller_did_account_id']))
164
+		{
165
+			$dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id'];
166
+			$dataVariable['call_direction'] = "outbound";
167
+			$dataVariable['calltype'] = "STANDARD";
168
+			unset($termination_rate);
169
+			unset($provider_cost);
170
+		}
171 171
         
172 172
 
173
-        //Get call receiver account information 
173
+		//Get call receiver account information 
174 174
 		$receiver_carddata = get_accounts($dataVariable['receiver_accid'],$logger,$db);
175 175
 		$receiver_parentid = $receiver_carddata['reseller_id'];
176 176
 
177
-        //For additional cdr entry of receiver
177
+		//For additional cdr entry of receiver
178 178
 		insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$receiver_parentid,$flag_parent,$dataVariable['receiver_accid'],$logger,$db,$decimal_points);
179 179
 
180 180
 		$flag_parent = true;
181 181
 		$dataVariable['uuid'] = $dataVariable['uuid'].$dataVariable['calltype']."_".$receiver_parentid;
182 182
 
183
-        //Insert parent reseller cdr
183
+		//Insert parent reseller cdr
184 184
 		insert_parent_data($dataVariable,$actual_calltype,$receiver_parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points);
185
-    	$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************");            
185
+		$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************");            
186 186
 	}
187
-    //*****************************************************************************************
187
+	//*****************************************************************************************
188 188
 	$logger->log("*************************** CDR ends ********************************");
189 189
 }
190 190
 
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 
201 201
 		$debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points);
202 202
 
203
-        //If receiver account id found then explicitly set call direction and call type
204
-        /*if(isset($dataVariable['receiver_accid']))
203
+		//If receiver account id found then explicitly set call direction and call type
204
+		/*if(isset($dataVariable['receiver_accid']))
205 205
         {
206 206
             $dataVariable['call_direction'] = "outbound";
207 207
             $dataVariable['calltype'] = "STANDARD";
208 208
         }*/
209 209
 
210
-        //Check if reseller have any package seconds left to use        
210
+		//Check if reseller have any package seconds left to use        
211 211
 		if ($actual_duration > 0)		{
212 212
 			$package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger);
213 213
 			if(!empty($package_array))
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 			}
218 218
 		}	
219 219
 
220
-        //Get parent id for cost calculation 
220
+		//Get parent id for cost calculation 
221 221
 		$parentid = $carddata['reseller_id'];
222 222
 		$parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost;
223 223
 		$cost = ($parent_cost > 0) ? $parent_cost : $provider_cost;
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 			$logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******");
228 228
 			$flag_parent = true;
229 229
 			insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points);
230
-    		$logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******");
230
+			$logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******");
231 231
 			return true;	
232 232
 
233 233
 		}else{
234 234
 
235
-		    $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);	
235
+			$cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);	
236 236
 
237 237
  			$query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost,
238 238
 		reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)";
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 function get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger)
303 303
 {
304 304
 
305
-        $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype'];
305
+		$dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype'];
306 306
 
307 307
 		return  $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'],ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",
308 308
 '".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ?  "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ?  "'".$origination_rate[$parentid]['COST']."'" :  '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'" ).",
@@ -313,33 +313,33 @@  discard block
 block discarded – undo
313 313
 //Generate CDR string for insert query for reseller
314 314
 function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost)
315 315
 {
316
-        $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype'];
316
+		$dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype'];
317 317
 	return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ?  "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ?  "'".$origination_rate[$parentid]['COST']."'" :  '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'";
318 318
 }
319 319
 
320 320
 //Update user balance
321 321
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
322
-    $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
323
-    $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id;
324
-    $logger->log("Balance update : " . $query);
325
-    $db->run($query);
322
+	$math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
323
+	$query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id;
324
+	$logger->log("Balance update : " . $query);
325
+	$db->run($query);
326 326
 }
327 327
 
328 328
 //Normalize rate string which we are getting from dialplan
329 329
 function normalize_rate($dataVariable)
330 330
 {
331 331
 	$rates = urldecode($dataVariable);
332
-    $data = explode("|",$rates);
332
+	$data = explode("|",$rates);
333 333
 
334 334
 	$newarray = array();
335
-    foreach($data as $key => $value)
336
-    {
337
-            $data1 = explode(":",$value);
338
-            foreach($data1 as $newkey => $newvalue)
339
-            {
340
-                    $newarray[$data1[0]] = $data1[$newkey];
341
-            }
342
-    }
335
+	foreach($data as $key => $value)
336
+	{
337
+			$data1 = explode(":",$value);
338
+			foreach($data1 as $newkey => $newvalue)
339
+			{
340
+					$newarray[$data1[0]] = $data1[$newkey];
341
+			}
342
+	}
343 343
 	return $newarray;
344 344
 }
345 345
 
@@ -373,19 +373,19 @@  discard block
 block discarded – undo
373 373
 	$duration -= $rates['INCLUDEDSECONDS'];
374 374
 	if ($duration > 0 && ($dataVariable['hangup_cause'] == 'NORMAL_CLEARING' || $dataVariable['hangup_cause']  == 'ALLOTTED_TIMEOUT')) {
375 375
 
376
-    		$rates['INC'] = ($rates['INC'] == 0) ? 1 : $rates['INC'];
377
-            $call_cost = $rates['CONNECTIONCOST'];
378
-	    	$call_cost += ($rates['INITIALBLOCK'] * $rates['COST']) / 60;
379
-            $billseconds = $duration - $rates['INITIALBLOCK'];
376
+			$rates['INC'] = ($rates['INC'] == 0) ? 1 : $rates['INC'];
377
+			$call_cost = $rates['CONNECTIONCOST'];
378
+			$call_cost += ($rates['INITIALBLOCK'] * $rates['COST']) / 60;
379
+			$billseconds = $duration - $rates['INITIALBLOCK'];
380 380
     
381
-            if ($billseconds > 0)
382
-            {
383
-                $call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60);
384
-            }
385
-    }
386
-    $call_cost = number_format($call_cost,$decimal_points);
387
-    $logger->log("Return cost ".$call_cost);
388
-    return $call_cost;
381
+			if ($billseconds > 0)
382
+			{
383
+				$call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60);
384
+			}
385
+	}
386
+	$call_cost = number_format($call_cost,$decimal_points);
387
+	$logger->log("Return cost ".$call_cost);
388
+	return $call_cost;
389 389
 }
390 390
 
391 391
 // get intial package information
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 	$counter = $db->run($query_counter);
435 435
 	$logger->log("GET Counters  : " . $query_counter);
436 436
 	if($counter)
437
-	    return $counter[0];	
437
+		return $counter[0];	
438 438
 	else
439
-	    return "";
439
+		return "";
440 440
 }
441 441
 
442 442
 //Get user info
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 ###############################################################################
23 23
 
24 24
 //Process CDR 
25
-function process_cdr($data,$db,$logger,$decimal_points)
25
+function process_cdr($data, $db, $logger, $decimal_points)
26 26
 {
27 27
 	//$logger->log(print_r($data,true));//exit;
28 28
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 
47 47
     if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING')
48 48
     {
49
-        $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause'];
50
-    }else{
49
+        $hangup_cause = isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause'];
50
+    } else {
51 51
         $hangup_cause = $dataVariable['hangup_cause'];
52 52
     }   
53 53
 
54 54
     if ($dataVariable['error_cdr'] == '1')
55 55
     {
56 56
         //Get actual hangup cause 
57
-        $hangup_cause= (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']); 
57
+        $hangup_cause = (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']); 
58 58
     }
59 59
 
60 60
 	/*#### PATCH FOR ONE WAY AUDIO ####*/
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 	/*#### ************* END *************####*/
66 66
 
67 67
     //Don't thing this will be useful anytime. Need to remove it after testing. 
68
-	if($hangup_cause == "NONE")
68
+	if ($hangup_cause == "NONE")
69 69
 	{
70 70
 		$hangup_cause = $dataVariable['current_application_data'];
71 71
 	}
72 72
 
73 73
     $dataVariable['hangup_cause'] = $hangup_cause;
74 74
 
75
-	if ( ($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) {
75
+	if (($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) {
76 76
 	  	$dataVariable['billsec'] = 0;
77 77
 	}
78 78
 
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
125 125
     //Outbound call entry for all type of calls 
126 126
 	$logger->log("*********************** OUTBOUND CALL ENTRY START *************");
127 127
 
128
-	$cdr_string = get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger);
128
+	$cdr_string = get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger);
129 129
 
130 130
 	$query = "INSERT INTO cdrs (uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec)  values ($cdr_string)";
131 131
 	$logger->log($query);
132 132
 	$db->run($query);
133 133
 	
134 134
     //Update customer balance
135
-	if($debit > 0 && $dataVariable['calltype'] != "FREE")
135
+	if ($debit > 0 && $dataVariable['calltype'] != "FREE")
136 136
 	{
137 137
 		update_balance($accountid, $debit, 0, $logger, $db);
138 138
 	}
139 139
 
140 140
     //Update parent or provider balance
141
-	if($parent_cost > 0){
141
+	if ($parent_cost > 0) {
142 142
 		update_balance($termination_rate['PROVIDER'], ($parent_cost * -1), 3, $logger, $db);
143 143
 	}
144 144
 
145 145
     //Resellers CDR entry
146 146
     $flag_parent = false;
147
-    insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points);
147
+    insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points);
148 148
 
149 149
     $logger->log("*********************** OUTBOUND CALL ENTRY END *************");
150 150
 
151 151
    
152 152
     //************ ADDING EXTRA ENTRY For local/DID Inbound call ****************************
153
-	$receiver_parentid=0;
154
-	if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "")
153
+	$receiver_parentid = 0;
154
+	if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "")
155 155
 	{
156 156
     	$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************");            
157 157
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         $dataVariable['calltype'] = "DID";
161 161
 
162 162
         //Override variables if call for DID PSTN
163
-        if(isset($dataVariable['caller_did_account_id']))
163
+        if (isset($dataVariable['caller_did_account_id']))
164 164
         {
165 165
             $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id'];
166 166
     		$dataVariable['call_direction'] = "outbound";
@@ -171,17 +171,17 @@  discard block
 block discarded – undo
171 171
         
172 172
 
173 173
         //Get call receiver account information 
174
-		$receiver_carddata = get_accounts($dataVariable['receiver_accid'],$logger,$db);
174
+		$receiver_carddata = get_accounts($dataVariable['receiver_accid'], $logger, $db);
175 175
 		$receiver_parentid = $receiver_carddata['reseller_id'];
176 176
 
177 177
         //For additional cdr entry of receiver
178
-		insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$receiver_parentid,$flag_parent,$dataVariable['receiver_accid'],$logger,$db,$decimal_points);
178
+		insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $receiver_parentid, $flag_parent, $dataVariable['receiver_accid'], $logger, $db, $decimal_points);
179 179
 
180 180
 		$flag_parent = true;
181 181
 		$dataVariable['uuid'] = $dataVariable['uuid'].$dataVariable['calltype']."_".$receiver_parentid;
182 182
 
183 183
         //Insert parent reseller cdr
184
-		insert_parent_data($dataVariable,$actual_calltype,$receiver_parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points);
184
+		insert_parent_data($dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points);
185 185
     	$logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************");            
186 186
 	}
187 187
     //*****************************************************************************************
@@ -189,16 +189,16 @@  discard block
 block discarded – undo
189 189
 }
190 190
 
191 191
 //Insert parent resellers cdr
192
-function insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points)
192
+function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points)
193 193
 {
194
-	while($parentid > 0 )
194
+	while ($parentid > 0)
195 195
 	{
196 196
 		$logger->log("*************** IN PARENT DATA SECTION ********");
197 197
 		$dataVariable['calltype'] = $actual_calltype;
198
-		$carddata = get_accounts($parentid,$logger,$db);
198
+		$carddata = get_accounts($parentid, $logger, $db);
199 199
 		$accountid = $carddata['id'];
200 200
 
201
-		$debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points);
201
+		$debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points);
202 202
 
203 203
         //If receiver account id found then explicitly set call direction and call type
204 204
         /*if(isset($dataVariable['receiver_accid']))
@@ -208,31 +208,31 @@  discard block
 block discarded – undo
208 208
         }*/
209 209
 
210 210
         //Check if reseller have any package seconds left to use        
211
-		if ($actual_duration > 0)		{
212
-			$package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger);
213
-			if(!empty($package_array))
211
+		if ($actual_duration > 0) {
212
+			$package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger);
213
+			if ( ! empty($package_array))
214 214
 			{
215 215
 				$dataVariable['calltype'] = "FREE";
216
-				$dataVariable['package_id']= $package_array['package_id'];
216
+				$dataVariable['package_id'] = $package_array['package_id'];
217 217
 			}
218 218
 		}	
219 219
 
220 220
         //Get parent id for cost calculation 
221 221
 		$parentid = $carddata['reseller_id'];
222
-		$parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost;
222
+		$parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost;
223 223
 		$cost = ($parent_cost > 0) ? $parent_cost : $provider_cost;
224 224
 	
225
-		if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true)
225
+		if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true)
226 226
 		{
227 227
 			$logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******");
228 228
 			$flag_parent = true;
229
-			insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points);
229
+			insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points);
230 230
     		$logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******");
231 231
 			return true;	
232 232
 
233
-		}else{
233
+		} else {
234 234
 
235
-		    $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);	
235
+		    $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost);	
236 236
 
237 237
  			$query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost,
238 238
 		reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)";
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			$db->run($query);
241 241
 
242 242
 			//Update reseller balance
243
-			if( $debit > 0 && $dataVariable['calltype'] != "FREE"){
243
+			if ($debit > 0 && $dataVariable['calltype'] != "FREE") {
244 244
 				update_balance($accountid, $debit, 0, $logger, $db);
245 245
 			}
246 246
 		}
@@ -250,40 +250,40 @@  discard block
 block discarded – undo
250 250
 }
251 251
 
252 252
 //Insert callee cdr entry for DID calls
253
-function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points)
253
+function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points)
254 254
 {
255 255
 		$localVariable = $dataVariable;
256 256
 		$localVariable['call_direction'] = "inbound";
257 257
 		$localVariable['uuid'] = $localVariable['uuid'].$dataVariable['calltype']."_".$accountid;
258 258
 		
259
-		if($dataVariable['calltype'] == "LOCAL")
259
+		if ($dataVariable['calltype'] == "LOCAL")
260 260
 		{
261 261
 			$origination_rate[$accountid]['CODE'] = $dataVariable['effective_destination_number'];
262 262
 			$origination_rate[$accountid]['DESTINATION'] = $dataVariable['calltype'];
263
-			if($flag_parent == false){
264
-				$cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,0,0,$logger);
263
+			if ($flag_parent == false) {
264
+				$cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, 0, 0, $logger);
265 265
 			}
266
-			else{
267
-				$cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);
266
+			else {
267
+				$cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost);
268 268
 			}
269
-		}else{
269
+		} else {
270 270
 
271 271
 			$origination_rate_did = normalize_origination_rate($dataVariable['origination_rates_did']);
272
-			$debit = calc_cost($dataVariable,$origination_rate_did[$accountid],$logger,$decimal_points);
272
+			$debit = calc_cost($dataVariable, $origination_rate_did[$accountid], $logger, $decimal_points);
273 273
 
274
-			if($flag_parent == false){
274
+			if ($flag_parent == false) {
275 275
 				
276
-				$cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate_did,$provider_cost,$parentid,$debit,0,$logger);
276
+				$cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger);
277 277
 			}
278
-			else{
279
-				$cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);
278
+			else {
279
+				$cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost);
280 280
 			}
281 281
 		}
282 282
 	  
283
-		if($flag_parent == false)
283
+		if ($flag_parent == false)
284 284
 		{
285 285
 			$query = "INSERT INTO cdrs(uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)";
286
-		}else{
286
+		} else {
287 287
 			$query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost,
288 288
 	reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)";
289 289
 		}
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		$logger->log($query);
292 292
 		$db->run($query);	
293 293
 
294
-		if($debit > 0 && ($dataVariable['calltype'] != "FREE" && $dataVariable['calltype'] != "LOCAL"))
294
+		if ($debit > 0 && ($dataVariable['calltype'] != "FREE" && $dataVariable['calltype'] != "LOCAL"))
295 295
 		{
296 296
 			update_balance($accountid, $debit, 0, $logger, $db);
297 297
 		}
@@ -299,29 +299,29 @@  discard block
 block discarded – undo
299 299
 }
300 300
 
301 301
 //Generate CDR string for insert query for customer.
302
-function get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger)
302
+function get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger)
303 303
 {
304 304
 
305
-        $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype'];
305
+        $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype'];
306 306
 
307
-		return  $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'],ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",
308
-'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ?  "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ?  "'".$origination_rate[$parentid]['COST']."'" :  '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'" ).",
307
+		return  $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'], ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",
308
+'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'").",
309 309
 ".(($termination_rate['DESTINATION']) ? "'".$termination_rate['DESTINATION']."'" : "'".''."'").",".(($termination_rate['COST']) ? "'".$termination_rate['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."','".convert_to_gmt(urldecode($dataVariable['profile_start_stamp']))."','".convert_to_gmt(urldecode($dataVariable['answer_stamp']))."','".convert_to_gmt(urldecode($dataVariable['bridge_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_media_stamp']))."','".convert_to_gmt(urldecode($dataVariable['end_stamp']))."',".$dataVariable['billmsec'].",'".$dataVariable['answermsec']."','".$dataVariable['waitmsec']."','".$dataVariable['progress_mediamsec']."','".$dataVariable['flow_billmsec']."'";
310 310
 
311 311
 }
312 312
 
313 313
 //Generate CDR string for insert query for reseller
314
-function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost)
314
+function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost)
315 315
 {
316
-        $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype'];
317
-	return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ?  "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ?  "'".$origination_rate[$parentid]['COST']."'" :  '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'";
316
+        $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype'];
317
+	return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($dataVariable['caller_id']))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'";
318 318
 }
319 319
 
320 320
 //Update user balance
321 321
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
322 322
     $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
323
-    $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id;
324
-    $logger->log("Balance update : " . $query);
323
+    $query = "UPDATE accounts SET balance=balance-".$amount." WHERE id=".$user_id;
324
+    $logger->log("Balance update : ".$query);
325 325
     $db->run($query);
326 326
 }
327 327
 
@@ -329,13 +329,13 @@  discard block
 block discarded – undo
329 329
 function normalize_rate($dataVariable)
330 330
 {
331 331
 	$rates = urldecode($dataVariable);
332
-    $data = explode("|",$rates);
332
+    $data = explode("|", $rates);
333 333
 
334 334
 	$newarray = array();
335
-    foreach($data as $key => $value)
335
+    foreach ($data as $key => $value)
336 336
     {
337
-            $data1 = explode(":",$value);
338
-            foreach($data1 as $newkey => $newvalue)
337
+            $data1 = explode(":", $value);
338
+            foreach ($data1 as $newkey => $newvalue)
339 339
             {
340 340
                     $newarray[$data1[0]] = $data1[$newkey];
341 341
             }
@@ -347,16 +347,16 @@  discard block
 block discarded – undo
347 347
 function normalize_origination_rate($dataVariable)
348 348
 {
349 349
 	$rates = urldecode($dataVariable);
350
-	$data = explode("|",$rates);
350
+	$data = explode("|", $rates);
351 351
 	$newarray = array();
352 352
 	$newarray1 = array();	
353
-	foreach($data as $key => $value)
353
+	foreach ($data as $key => $value)
354 354
 	{
355
-		$data1 = explode(":",$value);
356
-		foreach($data1 as $newkey => $newvalue)
355
+		$data1 = explode(":", $value);
356
+		foreach ($data1 as $newkey => $newvalue)
357 357
 		{
358 358
 			$newarray[$data1[0]] = $data1[$newkey];
359
-			if($newvalue == "ACCID" ){
359
+			if ($newvalue == "ACCID") {
360 360
 				$newarray1[$data1[1]] = $newarray;
361 361
 			}
362 362
 		}
@@ -365,13 +365,13 @@  discard block
 block discarded – undo
365 365
 }
366 366
 
367 367
 // Calculate cost for billing 
368
-function calc_cost($dataVariable, $rates, $logger,$decimal_points)
368
+function calc_cost($dataVariable, $rates, $logger, $decimal_points)
369 369
 {
370 370
 	//$logger->log(print_r($rates,true));
371 371
 	$duration = $dataVariable['billsec'];
372
-	$call_cost=0;  
372
+	$call_cost = 0;  
373 373
 	$duration -= $rates['INCLUDEDSECONDS'];
374
-	if ($duration > 0 && ($dataVariable['hangup_cause'] == 'NORMAL_CLEARING' || $dataVariable['hangup_cause']  == 'ALLOTTED_TIMEOUT')) {
374
+	if ($duration > 0 && ($dataVariable['hangup_cause'] == 'NORMAL_CLEARING' || $dataVariable['hangup_cause'] == 'ALLOTTED_TIMEOUT')) {
375 375
 
376 376
     		$rates['INC'] = ($rates['INC'] == 0) ? 1 : $rates['INC'];
377 377
             $call_cost = $rates['CONNECTIONCOST'];
@@ -380,46 +380,46 @@  discard block
 block discarded – undo
380 380
     
381 381
             if ($billseconds > 0)
382 382
             {
383
-                $call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60);
383
+                $call_cost += (ceil($billseconds / $rates['INC']) * $rates['INC']) * ($rates['COST'] / 60);
384 384
             }
385 385
     }
386
-    $call_cost = number_format($call_cost,$decimal_points);
386
+    $call_cost = number_format($call_cost, $decimal_points);
387 387
     $logger->log("Return cost ".$call_cost);
388 388
     return $call_cost;
389 389
 }
390 390
 
391 391
 // get intial package information
392
-function package_calculation($destination_number,$pricelist_id,$duration,$call_direction,$accountid,$db,$logger)
392
+function package_calculation($destination_number, $pricelist_id, $duration, $call_direction, $accountid, $db, $logger)
393 393
 {
394 394
 	$package_array = array();
395
-	$custom_destination = number_loop($destination_number,"patterns",$db);
395
+	$custom_destination = number_loop($destination_number, "patterns", $db);
396 396
 
397 397
 	$query = "SELECT * FROM packages  as P inner join package_patterns as PKGPTR on P.id = PKGPTR.package_id WHERE ".$custom_destination." AND status = 0 AND pricelist_id = ".$pricelist_id." ORDER BY LENGTH(PKGPTR.patterns) DESC LIMIT 1";
398 398
 
399 399
 	$package_info = $db->run($query);
400
-	if($package_info){
400
+	if ($package_info) {
401 401
 		$package_info = $package_info[0];
402 402
 
403
-		if( ($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2") ) {
403
+		if (($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2")) {
404 404
 	
405
-			$counter_info =  get_counters($accountid,$package_info['package_id'],$db,$logger);
405
+			$counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger);
406 406
 
407
-			if(!$counter_info) {
407
+			if ( ! $counter_info) {
408 408
 				$Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (".$package_info['package_id'].",".$accountid.")";		
409
-				$logger->log("Insert Counters  : " . $Insert_query);
409
+				$logger->log("Insert Counters  : ".$Insert_query);
410 410
 				$db->run($Insert_Query);
411
-				$counter_info =  get_counters($accountid,$package_info['package_id'],$db,$logger);
411
+				$counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger);
412 412
 				
413 413
 			}	
414 414
 			//print_r($counter_info);
415
-			if ( $package_info['includedseconds'] > ($counter_info['seconds'] )) {
415
+			if ($package_info['includedseconds'] > ($counter_info['seconds'])) {
416 416
 				$availableseconds = $package_info['includedseconds'] - $counter_info['seconds'];
417 417
 				$freeseconds = ($availableseconds >= $duration) ? $duration : $availableseconds;
418 418
 				$duration = ($availableseconds >= $duration) ? $duration : $availableseconds;
419
-				$update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds ). " WHERE id = ". $counter_info['id'];
420
-				$logger->log("Update Counters  : " . $update_query);
419
+				$update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds)." WHERE id = ".$counter_info['id'];
420
+				$logger->log("Update Counters  : ".$update_query);
421 421
 				$db->run($update_query);
422
-				$package_array['package_id']= $package_info['package_id'];
422
+				$package_array['package_id'] = $package_info['package_id'];
423 423
 				$package_array['calltype'] = "FREE";
424 424
 			}						
425 425
 		} 
@@ -428,21 +428,21 @@  discard block
 block discarded – undo
428 428
 } 
429 429
 
430 430
 // Getting used package minutes in counter table
431
-function get_counters($accountid,$package_id,$db,$logger)
431
+function get_counters($accountid, $package_id, $db, $logger)
432 432
 {
433 433
 	$query_counter = "SELECT id,seconds FROM counters  WHERE  accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1";
434 434
 	$counter = $db->run($query_counter);
435
-	$logger->log("GET Counters  : " . $query_counter);
436
-	if($counter)
435
+	$logger->log("GET Counters  : ".$query_counter);
436
+	if ($counter)
437 437
 	    return $counter[0];	
438 438
 	else
439 439
 	    return "";
440 440
 }
441 441
 
442 442
 //Get user info
443
-function get_accounts($parent_id,$logger, $db) {
444
-	$query = "SELECT * FROM accounts WHERE id=" . $parent_id;
445
-	$logger->log("GET configuration  : " . $query);
443
+function get_accounts($parent_id, $logger, $db) {
444
+	$query = "SELECT * FROM accounts WHERE id=".$parent_id;
445
+	$logger->log("GET configuration  : ".$query);
446 446
 	$res_user = $db->run($query);
447 447
 	return $res_user[0];
448 448
 }
@@ -452,27 +452,27 @@  discard block
 block discarded – undo
452 452
 {
453 453
 	$query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'";
454 454
 	$config = $db->run($query);
455
-	$logger->log("GET configuration  : " . $query);
455
+	$logger->log("GET configuration  : ".$query);
456 456
 	return $config[0];
457 457
 }
458 458
 
459 459
 // String append prefix for checking rates
460
-function number_loop($destination,$field,$db)
460
+function number_loop($destination, $field, $db)
461 461
 {
462
-	$max_len_prefix  = strlen($destination);
462
+	$max_len_prefix = strlen($destination);
463 463
 	$number_prefix = '(';
464
-	while ($max_len_prefix  > 0)
464
+	while ($max_len_prefix > 0)
465 465
 	{
466
-		$number_prefix .= "$field='^".substr($destination,0,$max_len_prefix).".*' OR ";
466
+		$number_prefix .= "$field='^".substr($destination, 0, $max_len_prefix).".*' OR ";
467 467
 		$max_len_prefix--;
468 468
 	}
469
-	$number_prefix .= "$field='^defaultprefix.*')";//echo $number_prefix;exit;
469
+	$number_prefix .= "$field='^defaultprefix.*')"; //echo $number_prefix;exit;
470 470
 	return $number_prefix;
471 471
 }
472 472
 
473 473
 //Convert current time to GMT
474 474
 function convert_to_gmt($date)
475 475
 {
476
-	return gmdate('Y-m-d H:i:s', strtotime($date) );
476
+	return gmdate('Y-m-d H:i:s', strtotime($date));
477 477
 }
478 478
 ?>
Please login to merge, or discard this patch.
Braces   +18 added lines, -17 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING')
48 48
     {
49 49
         $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause'];
50
-    }else{
50
+    } else{
51 51
         $hangup_cause = $dataVariable['hangup_cause'];
52 52
     }   
53 53
 
@@ -86,10 +86,12 @@  discard block
 block discarded – undo
86 86
 	$actual_calltype = $dataVariable['calltype'];
87 87
 	
88 88
     //Normalize origination and termination rates array 		   
89
-	if(isset($dataVariable['origination_rates']))
90
-	   $origination_rate = normalize_origination_rate($dataVariable['origination_rates']);
91
-	if(isset($dataVariable['termination_rates']))
92
-	   $termination_rate = normalize_rate($dataVariable['termination_rates']);
89
+	if(isset($dataVariable['origination_rates'])) {
90
+		   $origination_rate = normalize_origination_rate($dataVariable['origination_rates']);
91
+	}
92
+	if(isset($dataVariable['termination_rates'])) {
93
+		   $termination_rate = normalize_rate($dataVariable['termination_rates']);
94
+	}
93 95
 
94 96
     //If receiver account id found then explicitly set call direction and call type 
95 97
 	if(isset($dataVariable['receiver_accid']))
@@ -230,7 +232,7 @@  discard block
 block discarded – undo
230 232
     		$logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******");
231 233
 			return true;	
232 234
 
233
-		}else{
235
+		} else{
234 236
 
235 237
 		    $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);	
236 238
 
@@ -262,11 +264,10 @@  discard block
 block discarded – undo
262 264
 			$origination_rate[$accountid]['DESTINATION'] = $dataVariable['calltype'];
263 265
 			if($flag_parent == false){
264 266
 				$cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,0,0,$logger);
265
-			}
266
-			else{
267
+			} else{
267 268
 				$cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);
268 269
 			}
269
-		}else{
270
+		} else{
270 271
 
271 272
 			$origination_rate_did = normalize_origination_rate($dataVariable['origination_rates_did']);
272 273
 			$debit = calc_cost($dataVariable,$origination_rate_did[$accountid],$logger,$decimal_points);
@@ -274,8 +275,7 @@  discard block
 block discarded – undo
274 275
 			if($flag_parent == false){
275 276
 				
276 277
 				$cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate_did,$provider_cost,$parentid,$debit,0,$logger);
277
-			}
278
-			else{
278
+			} else{
279 279
 				$cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost);
280 280
 			}
281 281
 		}
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 		if($flag_parent == false)
284 284
 		{
285 285
 			$query = "INSERT INTO cdrs(uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)";
286
-		}else{
286
+		} else{
287 287
 			$query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost,
288 288
 	reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)";
289 289
 		}
@@ -433,11 +433,12 @@  discard block
 block discarded – undo
433 433
 	$query_counter = "SELECT id,seconds FROM counters  WHERE  accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1";
434 434
 	$counter = $db->run($query_counter);
435 435
 	$logger->log("GET Counters  : " . $query_counter);
436
-	if($counter)
437
-	    return $counter[0];	
438
-	else
439
-	    return "";
440
-}
436
+	if($counter) {
437
+		    return $counter[0];
438
+	} else {
439
+		    return "";
440
+	}
441
+	}
441 442
 
442 443
 //Get user info
443 444
 function get_accounts($parent_id,$logger, $db) {
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.db.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -47,6 +47,9 @@
 block discarded – undo
47 47
         echo $this->error;
48 48
     }
49 49
 
50
+    /**
51
+     * @param string $bind
52
+     */
50 53
     public function cleanup($bind) {
51 54
         if (!is_array($bind)) {
52 55
             if (!empty($bind))
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -23,58 +23,58 @@
 block discarded – undo
23 23
 
24 24
 class db extends PDO {
25 25
 
26
-    private $error;
27
-    private $sql;
28
-    private $bind;
29
-    private $errorCallbackFunction;
30
-    private $errorMsgFormat;
26
+	private $error;
27
+	private $sql;
28
+	private $bind;
29
+	private $errorCallbackFunction;
30
+	private $errorMsgFormat;
31 31
 
32
-    public function __construct($dsn = "", $user = "", $passwd = "") {
32
+	public function __construct($dsn = "", $user = "", $passwd = "") {
33 33
 
34
-        $config = parse_ini_file("/var/lib/astpp/astpp-config.conf");
34
+		$config = parse_ini_file("/var/lib/astpp/astpp-config.conf");
35 35
 
36
-        $options = array(
37
-            PDO::ATTR_PERSISTENT => true,
38
-            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
39
-        );
36
+		$options = array(
37
+			PDO::ATTR_PERSISTENT => true,
38
+			PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
39
+		);
40 40
 
41
-        try {
42
-            parent::__construct("mysql:host=".$config['dbhost'].";dbname=".$config['dbname']."", $config['dbuser'], $config['dbpass'], $options);
43
-        } catch (PDOException $e) {
41
+		try {
42
+			parent::__construct("mysql:host=".$config['dbhost'].";dbname=".$config['dbname']."", $config['dbuser'], $config['dbpass'], $options);
43
+		} catch (PDOException $e) {
44 44
 
45
-            $this->error = $e->getMessage();
46
-        }
47
-        echo $this->error;
48
-    }
45
+			$this->error = $e->getMessage();
46
+		}
47
+		echo $this->error;
48
+	}
49 49
 
50
-    public function cleanup($bind) {
51
-        if (!is_array($bind)) {
52
-            if (!empty($bind))
53
-                $bind = array($bind);
54
-            else
55
-                $bind = array();
56
-        }
57
-        return $bind;
58
-    }
50
+	public function cleanup($bind) {
51
+		if (!is_array($bind)) {
52
+			if (!empty($bind))
53
+				$bind = array($bind);
54
+			else
55
+				$bind = array();
56
+		}
57
+		return $bind;
58
+	}
59 59
 
60
-    public function run($sql, $bind = "") {
61
-        $this->sql = trim($sql);
62
-        $this->bind = $this->cleanup($bind);
63
-        $this->error = "";
60
+	public function run($sql, $bind = "") {
61
+		$this->sql = trim($sql);
62
+		$this->bind = $this->cleanup($bind);
63
+		$this->error = "";
64 64
 
65
-        try {
66
-            $pdostmt = $this->prepare($this->sql);
67
-            if ($pdostmt->execute($this->bind) !== false) {
68
-                if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
69
-                    return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
70
-                elseif (preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql))
71
-                    return $pdostmt->rowCount();
72
-            }
73
-        } catch (PDOException $e) {
74
-            $this->error = $e->getMessage();
75
-            return $this->error;
76
-        }
77
-    }
65
+		try {
66
+			$pdostmt = $this->prepare($this->sql);
67
+			if ($pdostmt->execute($this->bind) !== false) {
68
+				if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
69
+					return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
70
+				elseif (preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql))
71
+					return $pdostmt->rowCount();
72
+			}
73
+		} catch (PDOException $e) {
74
+			$this->error = $e->getMessage();
75
+			return $this->error;
76
+		}
77
+	}
78 78
 
79 79
 }
80 80
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
     }
49 49
 
50 50
     public function cleanup($bind) {
51
-        if (!is_array($bind)) {
52
-            if (!empty($bind))
51
+        if ( ! is_array($bind)) {
52
+            if ( ! empty($bind))
53 53
                 $bind = array($bind);
54 54
             else
55 55
                 $bind = array();
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         try {
66 66
             $pdostmt = $this->prepare($this->sql);
67 67
             if ($pdostmt->execute($this->bind) !== false) {
68
-                if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
68
+                if (preg_match("/^(".implode("|", array("select", "describe", "pragma")).") /i", $this->sql))
69 69
                     return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
70
-                elseif (preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql))
70
+                elseif (preg_match("/^(".implode("|", array("delete", "insert", "update")).") /i", $this->sql))
71 71
                     return $pdostmt->rowCount();
72 72
             }
73 73
         } catch (PDOException $e) {
Please login to merge, or discard this patch.
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -49,10 +49,11 @@  discard block
 block discarded – undo
49 49
 
50 50
     public function cleanup($bind) {
51 51
         if (!is_array($bind)) {
52
-            if (!empty($bind))
53
-                $bind = array($bind);
54
-            else
55
-                $bind = array();
52
+            if (!empty($bind)) {
53
+                            $bind = array($bind);
54
+            } else {
55
+                            $bind = array();
56
+            }
56 57
         }
57 58
         return $bind;
58 59
     }
@@ -65,10 +66,11 @@  discard block
 block discarded – undo
65 66
         try {
66 67
             $pdostmt = $this->prepare($this->sql);
67 68
             if ($pdostmt->execute($this->bind) !== false) {
68
-                if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
69
-                    return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
70
-                elseif (preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql))
71
-                    return $pdostmt->rowCount();
69
+                if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql)) {
70
+                                    return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
71
+                } elseif (preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql)) {
72
+                                    return $pdostmt->rowCount();
73
+                }
72 74
             }
73 75
         } catch (PDOException $e) {
74 76
             $this->error = $e->getMessage();
Please login to merge, or discard this patch.
freeswitch/fs/lib/astpp.functions.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -118,6 +118,9 @@
 block discarded – undo
118 118
 }
119 119
 
120 120
 //Update user balance
121
+/**
122
+ * @param integer $entity_id
123
+ */
121 124
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
122 125
     if ($amount > 0) {
123 126
         $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
Please login to merge, or discard this patch.
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -24,114 +24,114 @@
 block discarded – undo
24 24
 
25 25
 //Parse user and rates array which we got in cdr xml
26 26
 function parse_rates_array($xml_rate, $constant_array, $logger) {
27
-    $rates_array = array();
27
+	$rates_array = array();
28 28
 
29
-    //decode string using urldecode
30
-    $xml_rate = urldecode($xml_rate);
31
-    $xml_rate_array = explode("||", $xml_rate);
29
+	//decode string using urldecode
30
+	$xml_rate = urldecode($xml_rate);
31
+	$xml_rate_array = explode("||", $xml_rate);
32 32
 
33
-    foreach ($xml_rate_array as $rate_key => $rate_value) {
34
-        $rates_array = explode("|", $rate_value);
33
+	foreach ($xml_rate_array as $rate_key => $rate_value) {
34
+		$rates_array = explode("|", $rate_value);
35 35
 
36
-        $user_id_param = $rates_array[count($rates_array) - 1];
37
-        $user_id = (substr($user_id_param, 0, 3) == 'UID') ? substr($user_id_param, 3) : 0;
36
+		$user_id_param = $rates_array[count($rates_array) - 1];
37
+		$user_id = (substr($user_id_param, 0, 3) == 'UID') ? substr($user_id_param, 3) : 0;
38 38
 
39
-        foreach ($rates_array as $key => $value) {
40
-            $rates_array_info[$user_id][$constant_array[substr($value, 0, 3)]] = substr($value, 3);
41
-        }
42
-    }
43
-    return $rates_array_info;
39
+		foreach ($rates_array as $key => $value) {
40
+			$rates_array_info[$user_id][$constant_array[substr($value, 0, 3)]] = substr($value, 3);
41
+		}
42
+	}
43
+	return $rates_array_info;
44 44
 }
45 45
 
46 46
 //Process package 
47 47
 function process_package($xml_cdr, $user_id, $rates_array, $logger, $db) {
48
-    $duration = $xml_cdr->variables->duration;
49
-    $xml_cdr->variables->package_id = 0;
50
-    $flag = false;
51
-    if ($duration > 0 && $xml_cdr->variables->call_direction == 'outbound') {
52
-        $destination_number = $xml_cdr->variables->effective_destination_number;
53
-
54
-        $number_len = strlen($destination_number);
55
-        $number_loop_str = '(';
56
-        while ($number_len > 0) {
57
-            $number_loop_str .= " code='" . substr($destination_number, 0, $number_len) . "' OR ";
58
-            $number_len -= 1;
59
-        }
60
-        $number_loop_str .= " code='--')";
61
-
62
-        $query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE " . $number_loop_str . " AND B.package_id = A.id AND A.ratecard_id=" . $rates_array['ratecard_id'] . " AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC";
63
-        $logger->log("Package Query : " . $query);
64
-        $res_package = $db->run($query);
65
-
66
-        foreach ($res_package as $res_package_key => $package_info) {
67
-            if (isset($package_info['package_id'])) {
68
-                $query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=" . $package_info['code'] . " AND package_id=" . $package_info['package_id'] . " AND user_id=" . $user_id;
69
-                $logger->log("Package usage Query : " . $query);
70
-                $res_pkg_usg = $db->run($query);
71
-                $package_usage_info = $res_pkg_usg[0];
72
-
73
-                $used_seconds = (isset($package_usage_info['used_seconds'])) ? $package_usage_info['used_seconds'] : 0;
74
-
75
-                $logger->log("Included seconds : " . $package_info['includedseconds'] . ", Used seconds : " . $used_seconds);
76
-                if ($package_info['includedseconds'] > $used_seconds) {
77
-                    $remaining_seconds = $package_info['includedseconds'] - ($duration + $used_seconds);
78
-                    if ($remaining_seconds > 0) {
79
-                        $dud_sec = $duration;
80
-                        $duration = 0;
81
-                    } else {
82
-                        $dud_sec = $duration - abs($remaining_seconds);
83
-                        $duration = abs($remaining_seconds);
84
-                    }
85
-                    $flag = true;
86
-                    $xml_cdr->variables->package_id = $package_info['package_id'];
87
-
88
-                    $query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (" . $package_info['package_id'] . "," . $user_id . ",'" . $package_info['code'] . "'," . $dud_sec . ") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+" . $dud_sec;
89
-                    $logger->log("Package Usage Query : " . $query);
90
-                    $db->run($query);
91
-
92
-                    break;
93
-                }
94
-            }
95
-        }
96
-    }
97
-    return array($duration, $flag);
48
+	$duration = $xml_cdr->variables->duration;
49
+	$xml_cdr->variables->package_id = 0;
50
+	$flag = false;
51
+	if ($duration > 0 && $xml_cdr->variables->call_direction == 'outbound') {
52
+		$destination_number = $xml_cdr->variables->effective_destination_number;
53
+
54
+		$number_len = strlen($destination_number);
55
+		$number_loop_str = '(';
56
+		while ($number_len > 0) {
57
+			$number_loop_str .= " code='" . substr($destination_number, 0, $number_len) . "' OR ";
58
+			$number_len -= 1;
59
+		}
60
+		$number_loop_str .= " code='--')";
61
+
62
+		$query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE " . $number_loop_str . " AND B.package_id = A.id AND A.ratecard_id=" . $rates_array['ratecard_id'] . " AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC";
63
+		$logger->log("Package Query : " . $query);
64
+		$res_package = $db->run($query);
65
+
66
+		foreach ($res_package as $res_package_key => $package_info) {
67
+			if (isset($package_info['package_id'])) {
68
+				$query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=" . $package_info['code'] . " AND package_id=" . $package_info['package_id'] . " AND user_id=" . $user_id;
69
+				$logger->log("Package usage Query : " . $query);
70
+				$res_pkg_usg = $db->run($query);
71
+				$package_usage_info = $res_pkg_usg[0];
72
+
73
+				$used_seconds = (isset($package_usage_info['used_seconds'])) ? $package_usage_info['used_seconds'] : 0;
74
+
75
+				$logger->log("Included seconds : " . $package_info['includedseconds'] . ", Used seconds : " . $used_seconds);
76
+				if ($package_info['includedseconds'] > $used_seconds) {
77
+					$remaining_seconds = $package_info['includedseconds'] - ($duration + $used_seconds);
78
+					if ($remaining_seconds > 0) {
79
+						$dud_sec = $duration;
80
+						$duration = 0;
81
+					} else {
82
+						$dud_sec = $duration - abs($remaining_seconds);
83
+						$duration = abs($remaining_seconds);
84
+					}
85
+					$flag = true;
86
+					$xml_cdr->variables->package_id = $package_info['package_id'];
87
+
88
+					$query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (" . $package_info['package_id'] . "," . $user_id . ",'" . $package_info['code'] . "'," . $dud_sec . ") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+" . $dud_sec;
89
+					$logger->log("Package Usage Query : " . $query);
90
+					$db->run($query);
91
+
92
+					break;
93
+				}
94
+			}
95
+		}
96
+	}
97
+	return array($duration, $flag);
98 98
 }
99 99
 
100 100
 //Process user/vendor cdr
101 101
 function do_cdr_process($xml_cdr, $debit, $cost, $vendor_cost, $rates_array, $parent_id = 0, $parent_rates, $carrier_rates_array, $logger, $db) {
102
-    $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . $xml_cdr->variables->entity_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->carrier_id . "','" . $xml_cdr->callflow[0]->caller_profile->originatee->originatee_caller_profile->network_addr . "','" . $xml_cdr->variables->sip_contact_host . "','" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . ",'" . $xml_cdr->variables->vendor_id . "'," . $vendor_cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . @$carrier_rates_array['code'] . "','" . @$carrier_rates_array['destination'] . "','" . @$carrier_rates_array['cost'] . "','" . $xml_cdr->variables->call_direction . "','" . urldecode($xml_cdr->variables->profile_start_stamp) . "','" . urldecode($xml_cdr->variables->answer_stamp) . "','" . urldecode($xml_cdr->variables->bridge_stamp) . "','" . urldecode($xml_cdr->variables->progress_stamp) . "','" . urldecode($xml_cdr->variables->progress_media_stamp) . "','" . urldecode($xml_cdr->variables->end_stamp) . "'," . $xml_cdr->variables->billmsec . "," . $xml_cdr->variables->answermsec . "," . $xml_cdr->variables->waitmsec . "," . $xml_cdr->variables->progress_mediamsec . "," . $xml_cdr->variables->flow_billmsec;
102
+	$query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . $xml_cdr->variables->entity_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->carrier_id . "','" . $xml_cdr->callflow[0]->caller_profile->originatee->originatee_caller_profile->network_addr . "','" . $xml_cdr->variables->sip_contact_host . "','" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . ",'" . $xml_cdr->variables->vendor_id . "'," . $vendor_cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . @$carrier_rates_array['code'] . "','" . @$carrier_rates_array['destination'] . "','" . @$carrier_rates_array['cost'] . "','" . $xml_cdr->variables->call_direction . "','" . urldecode($xml_cdr->variables->profile_start_stamp) . "','" . urldecode($xml_cdr->variables->answer_stamp) . "','" . urldecode($xml_cdr->variables->bridge_stamp) . "','" . urldecode($xml_cdr->variables->progress_stamp) . "','" . urldecode($xml_cdr->variables->progress_media_stamp) . "','" . urldecode($xml_cdr->variables->end_stamp) . "'," . $xml_cdr->variables->billmsec . "," . $xml_cdr->variables->answermsec . "," . $xml_cdr->variables->waitmsec . "," . $xml_cdr->variables->progress_mediamsec . "," . $xml_cdr->variables->flow_billmsec;
103 103
 
104
-    $query = "INSERT INTO tbl_cdrs (uniqueid,user_id,entity_id,callerid_name,callerid_number,dstnum,duration,carrier_id,carrierip,callerip,disposition,start_stamp,debit,cost,vendor_id,vendor_cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,carrier_code,carrier_code_destination ,carrier_cost,call_direction,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($query_string)";
104
+	$query = "INSERT INTO tbl_cdrs (uniqueid,user_id,entity_id,callerid_name,callerid_number,dstnum,duration,carrier_id,carrierip,callerip,disposition,start_stamp,debit,cost,vendor_id,vendor_cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,carrier_code,carrier_code_destination ,carrier_cost,call_direction,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($query_string)";
105 105
 
106
-    $logger->log("CDR Query : " . $query);
107
-    $db->run($query);
106
+	$logger->log("CDR Query : " . $query);
107
+	$db->run($query);
108 108
 }
109 109
 
110 110
 //Process reseller cdr
111 111
 function do_reseller_cdr_process($xml_cdr, $debit, $cost, $rates_array, $parent_id = 0, $parent_rates, $logger, $db) {
112
-    $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . $xml_cdr->variables->call_direction . "'";
112
+	$query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . $xml_cdr->variables->call_direction . "'";
113 113
 
114
-    $query = "INSERT INTO tbl_cdrs_reseller (uniqueid,reseller_id,callerid_name,callerid_number,dstnum,duration,disposition,start_stamp,debit,cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,call_direction) values ($query_string)";
114
+	$query = "INSERT INTO tbl_cdrs_reseller (uniqueid,reseller_id,callerid_name,callerid_number,dstnum,duration,disposition,start_stamp,debit,cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,call_direction) values ($query_string)";
115 115
 
116
-    $logger->log("CDR Query : " . $query);
117
-    $db->run($query);
116
+	$logger->log("CDR Query : " . $query);
117
+	$db->run($query);
118 118
 }
119 119
 
120 120
 //Update user balance
121 121
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
122
-    if ($amount > 0) {
123
-        $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
124
-        $query = "UPDATE tbl_users SET credit=credit$math_sign" . $amount . " WHERE id=" . $user_id;
125
-        $logger->log("Balance update : " . $query);
126
-        $db->run($query);
127
-    }
122
+	if ($amount > 0) {
123
+		$math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
124
+		$query = "UPDATE tbl_users SET credit=credit$math_sign" . $amount . " WHERE id=" . $user_id;
125
+		$logger->log("Balance update : " . $query);
126
+		$db->run($query);
127
+	}
128 128
 }
129 129
 
130 130
 //Get user info
131 131
 function get_user_info($parent_id, $db) {
132
-    $query = "SELECT * FROM tbl_users WHERE id=" . $parent_id;
133
-    $res_user = $db->run($query);
134
-    return $res_user[0];
132
+	$query = "SELECT * FROM tbl_users WHERE id=" . $parent_id;
133
+	$res_user = $db->run($query);
134
+	return $res_user[0];
135 135
 }
136 136
 
137 137
 ?>
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -54,25 +54,25 @@  discard block
 block discarded – undo
54 54
         $number_len = strlen($destination_number);
55 55
         $number_loop_str = '(';
56 56
         while ($number_len > 0) {
57
-            $number_loop_str .= " code='" . substr($destination_number, 0, $number_len) . "' OR ";
57
+            $number_loop_str .= " code='".substr($destination_number, 0, $number_len)."' OR ";
58 58
             $number_len -= 1;
59 59
         }
60 60
         $number_loop_str .= " code='--')";
61 61
 
62
-        $query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE " . $number_loop_str . " AND B.package_id = A.id AND A.ratecard_id=" . $rates_array['ratecard_id'] . " AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC";
63
-        $logger->log("Package Query : " . $query);
62
+        $query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE ".$number_loop_str." AND B.package_id = A.id AND A.ratecard_id=".$rates_array['ratecard_id']." AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC";
63
+        $logger->log("Package Query : ".$query);
64 64
         $res_package = $db->run($query);
65 65
 
66 66
         foreach ($res_package as $res_package_key => $package_info) {
67 67
             if (isset($package_info['package_id'])) {
68
-                $query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=" . $package_info['code'] . " AND package_id=" . $package_info['package_id'] . " AND user_id=" . $user_id;
69
-                $logger->log("Package usage Query : " . $query);
68
+                $query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=".$package_info['code']." AND package_id=".$package_info['package_id']." AND user_id=".$user_id;
69
+                $logger->log("Package usage Query : ".$query);
70 70
                 $res_pkg_usg = $db->run($query);
71 71
                 $package_usage_info = $res_pkg_usg[0];
72 72
 
73 73
                 $used_seconds = (isset($package_usage_info['used_seconds'])) ? $package_usage_info['used_seconds'] : 0;
74 74
 
75
-                $logger->log("Included seconds : " . $package_info['includedseconds'] . ", Used seconds : " . $used_seconds);
75
+                $logger->log("Included seconds : ".$package_info['includedseconds'].", Used seconds : ".$used_seconds);
76 76
                 if ($package_info['includedseconds'] > $used_seconds) {
77 77
                     $remaining_seconds = $package_info['includedseconds'] - ($duration + $used_seconds);
78 78
                     if ($remaining_seconds > 0) {
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
                     $flag = true;
86 86
                     $xml_cdr->variables->package_id = $package_info['package_id'];
87 87
 
88
-                    $query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (" . $package_info['package_id'] . "," . $user_id . ",'" . $package_info['code'] . "'," . $dud_sec . ") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+" . $dud_sec;
89
-                    $logger->log("Package Usage Query : " . $query);
88
+                    $query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (".$package_info['package_id'].",".$user_id.",'".$package_info['code']."',".$dud_sec.") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+".$dud_sec;
89
+                    $logger->log("Package Usage Query : ".$query);
90 90
                     $db->run($query);
91 91
 
92 92
                     break;
@@ -99,21 +99,21 @@  discard block
 block discarded – undo
99 99
 
100 100
 //Process user/vendor cdr
101 101
 function do_cdr_process($xml_cdr, $debit, $cost, $vendor_cost, $rates_array, $parent_id = 0, $parent_rates, $carrier_rates_array, $logger, $db) {
102
-    $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . $xml_cdr->variables->entity_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->carrier_id . "','" . $xml_cdr->callflow[0]->caller_profile->originatee->originatee_caller_profile->network_addr . "','" . $xml_cdr->variables->sip_contact_host . "','" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . ",'" . $xml_cdr->variables->vendor_id . "'," . $vendor_cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . @$carrier_rates_array['code'] . "','" . @$carrier_rates_array['destination'] . "','" . @$carrier_rates_array['cost'] . "','" . $xml_cdr->variables->call_direction . "','" . urldecode($xml_cdr->variables->profile_start_stamp) . "','" . urldecode($xml_cdr->variables->answer_stamp) . "','" . urldecode($xml_cdr->variables->bridge_stamp) . "','" . urldecode($xml_cdr->variables->progress_stamp) . "','" . urldecode($xml_cdr->variables->progress_media_stamp) . "','" . urldecode($xml_cdr->variables->end_stamp) . "'," . $xml_cdr->variables->billmsec . "," . $xml_cdr->variables->answermsec . "," . $xml_cdr->variables->waitmsec . "," . $xml_cdr->variables->progress_mediamsec . "," . $xml_cdr->variables->flow_billmsec;
102
+    $query_string = "'".$xml_cdr->variables->uuid."','".$xml_cdr->variables->user_id."','".$xml_cdr->variables->entity_id."','".urldecode($xml_cdr->variables->effective_caller_id_name)."','".$xml_cdr->variables->effective_caller_id_number."','".$xml_cdr->variables->effective_destination_number."',".$xml_cdr->variables->duration.",'".$xml_cdr->variables->carrier_id."','".$xml_cdr->callflow[0]->caller_profile->originatee->originatee_caller_profile->network_addr."','".$xml_cdr->variables->sip_contact_host."','".$xml_cdr->variables->hangup_cause."','".urldecode($xml_cdr->variables->start_stamp)."',".$debit.",".$cost.",'".$xml_cdr->variables->vendor_id."',".$vendor_cost.",".$rates_array['ratecard_id'].",".$xml_cdr->variables->package_id.",'".$rates_array['code']."','".$rates_array['destination']."','".$rates_array['cost']."','".$parent_id."','".@$parent_rates['code']."','".@$parent_rates['destination']."','".@$parent_rates['cost']."','".@$carrier_rates_array['code']."','".@$carrier_rates_array['destination']."','".@$carrier_rates_array['cost']."','".$xml_cdr->variables->call_direction."','".urldecode($xml_cdr->variables->profile_start_stamp)."','".urldecode($xml_cdr->variables->answer_stamp)."','".urldecode($xml_cdr->variables->bridge_stamp)."','".urldecode($xml_cdr->variables->progress_stamp)."','".urldecode($xml_cdr->variables->progress_media_stamp)."','".urldecode($xml_cdr->variables->end_stamp)."',".$xml_cdr->variables->billmsec.",".$xml_cdr->variables->answermsec.",".$xml_cdr->variables->waitmsec.",".$xml_cdr->variables->progress_mediamsec.",".$xml_cdr->variables->flow_billmsec;
103 103
 
104 104
     $query = "INSERT INTO tbl_cdrs (uniqueid,user_id,entity_id,callerid_name,callerid_number,dstnum,duration,carrier_id,carrierip,callerip,disposition,start_stamp,debit,cost,vendor_id,vendor_cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,carrier_code,carrier_code_destination ,carrier_cost,call_direction,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($query_string)";
105 105
 
106
-    $logger->log("CDR Query : " . $query);
106
+    $logger->log("CDR Query : ".$query);
107 107
     $db->run($query);
108 108
 }
109 109
 
110 110
 //Process reseller cdr
111 111
 function do_reseller_cdr_process($xml_cdr, $debit, $cost, $rates_array, $parent_id = 0, $parent_rates, $logger, $db) {
112
-    $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . urldecode($xml_cdr->variables->effective_caller_id_name) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->hangup_cause . "','" . urldecode($xml_cdr->variables->start_stamp) . "'," . $debit . "," . $cost . "," . $rates_array['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array['code'] . "','" . $rates_array['destination'] . "','" . $rates_array['cost'] . "','" . $parent_id . "','" . @$parent_rates['code'] . "','" . @$parent_rates['destination'] . "','" . @$parent_rates['cost'] . "','" . $xml_cdr->variables->call_direction . "'";
112
+    $query_string = "'".$xml_cdr->variables->uuid."','".$xml_cdr->variables->user_id."','".urldecode($xml_cdr->variables->effective_caller_id_name)."','".$xml_cdr->variables->effective_caller_id_number."','".$xml_cdr->variables->effective_destination_number."',".$xml_cdr->variables->duration.",'".$xml_cdr->variables->hangup_cause."','".urldecode($xml_cdr->variables->start_stamp)."',".$debit.",".$cost.",".$rates_array['ratecard_id'].",".$xml_cdr->variables->package_id.",'".$rates_array['code']."','".$rates_array['destination']."','".$rates_array['cost']."','".$parent_id."','".@$parent_rates['code']."','".@$parent_rates['destination']."','".@$parent_rates['cost']."','".$xml_cdr->variables->call_direction."'";
113 113
 
114 114
     $query = "INSERT INTO tbl_cdrs_reseller (uniqueid,reseller_id,callerid_name,callerid_number,dstnum,duration,disposition,start_stamp,debit,cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,call_direction) values ($query_string)";
115 115
 
116
-    $logger->log("CDR Query : " . $query);
116
+    $logger->log("CDR Query : ".$query);
117 117
     $db->run($query);
118 118
 }
119 119
 
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 function update_balance($user_id, $amount, $entity_id, $logger, $db) {
122 122
     if ($amount > 0) {
123 123
         $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
124
-        $query = "UPDATE tbl_users SET credit=credit$math_sign" . $amount . " WHERE id=" . $user_id;
125
-        $logger->log("Balance update : " . $query);
124
+        $query = "UPDATE tbl_users SET credit=credit$math_sign".$amount." WHERE id=".$user_id;
125
+        $logger->log("Balance update : ".$query);
126 126
         $db->run($query);
127 127
     }
128 128
 }
129 129
 
130 130
 //Get user info
131 131
 function get_user_info($parent_id, $db) {
132
-    $query = "SELECT * FROM tbl_users WHERE id=" . $parent_id;
132
+    $query = "SELECT * FROM tbl_users WHERE id=".$parent_id;
133 133
     $res_user = $db->run($query);
134 134
     return $res_user[0];
135 135
 }
Please login to merge, or discard this patch.
web_interface/astpp/application/controllers/currencyupdate.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -64,6 +64,10 @@
 block discarded – undo
64 64
 	      redirect(base_url()."/systems/currency_list/");
65 65
 	      exit;
66 66
 	}
67
+
68
+	/**
69
+	 * @param string $url
70
+	 */
67 71
 	function curl_response($url)
68 72
 	{
69 73
 		    $ch = curl_init();  // Initialising cURL
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -21,60 +21,60 @@
 block discarded – undo
21 21
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 22
 ###############################################################################
23 23
 class Currencyupdate extends CI_Controller {
24
-    function __construct()
25
-    {
26
-        parent::__construct();
27
-     //   if(!defined( 'CRON' ) )
28
-       //   exit();
29
-        $this->load->model("db_model");
30
-        $this->load->library("astpp/common");
31
-    }
32
-    function update_currency(){
33
-        $where = array("currency <>"=> Common_model::$global_config['system_config']['base_currency']);
34
-        $query = $this->db_model->getSelect("*", "currency", $where);
24
+	function __construct()
25
+	{
26
+		parent::__construct();
27
+	 //   if(!defined( 'CRON' ) )
28
+	   //   exit();
29
+		$this->load->model("db_model");
30
+		$this->load->library("astpp/common");
31
+	}
32
+	function update_currency(){
33
+		$where = array("currency <>"=> Common_model::$global_config['system_config']['base_currency']);
34
+		$query = $this->db_model->getSelect("*", "currency", $where);
35 35
 
36
-        if($query->num_rows >0){
37
-            $currency_data =$query->result_array();
38
-    		$url = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=";
39
-	    	foreach ($currency_data as $currency_value) {
40
-	    	    $url .= Common_model::$global_config['system_config']['base_currency'].$currency_value['currency'].'=X+';
41
-	    	}
42
-	    	$url .= '&f=l1';
36
+		if($query->num_rows >0){
37
+			$currency_data =$query->result_array();
38
+			$url = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=";
39
+			foreach ($currency_data as $currency_value) {
40
+				$url .= Common_model::$global_config['system_config']['base_currency'].$currency_value['currency'].'=X+';
41
+			}
42
+			$url .= '&f=l1';
43 43
 
44
-	    	$sql='';
45
-	    	$response = $this->curl_response($url);
46
-	    	$content_data = explode(' ',$response);
44
+			$sql='';
45
+			$response = $this->curl_response($url);
46
+			$content_data = explode(' ',$response);
47 47
 
48
-	    	foreach ($content_data as $content_data1){
49
-	    	   $currency_arr= explode("\n", $content_data1);
50
-	    	    foreach($currency_arr as $final_val)
51
-	    	    {
52
-	    	        $currency_final = array();
53
-	    		    $currency_final= explode(',', $final_val);
54
-	    		    if(isset($currency_final[1]) && $currency_final[1] != "" && $currency_final[0]!='' && $currency_final[1] != 'N/A'){
55
-			      $sql = "UPDATE currency SET currencyRate = ".$currency_final[1]." WHERE currency = '".substr($currency_final[0],4,3)."'";
56
-			      $this->db->query($sql);
57
-	    		    }
58
-	    	    }
59
-	    	}
60
-	    	$sql = "UPDATE currency SET currencyRate = '1' WHERE currency = '".Common_model::$global_config['system_config']['base_currency']."'";
61
-                $this->db->query($sql);
62
-      }
63
-	      $this->session->set_flashdata("astpp_errormsg", "Currency exchange rates successfully updated.");
64
-	      redirect(base_url()."/systems/currency_list/");
65
-	      exit;
48
+			foreach ($content_data as $content_data1){
49
+			   $currency_arr= explode("\n", $content_data1);
50
+				foreach($currency_arr as $final_val)
51
+				{
52
+					$currency_final = array();
53
+					$currency_final= explode(',', $final_val);
54
+					if(isset($currency_final[1]) && $currency_final[1] != "" && $currency_final[0]!='' && $currency_final[1] != 'N/A'){
55
+				  $sql = "UPDATE currency SET currencyRate = ".$currency_final[1]." WHERE currency = '".substr($currency_final[0],4,3)."'";
56
+				  $this->db->query($sql);
57
+					}
58
+				}
59
+			}
60
+			$sql = "UPDATE currency SET currencyRate = '1' WHERE currency = '".Common_model::$global_config['system_config']['base_currency']."'";
61
+				$this->db->query($sql);
62
+	  }
63
+		  $this->session->set_flashdata("astpp_errormsg", "Currency exchange rates successfully updated.");
64
+		  redirect(base_url()."/systems/currency_list/");
65
+		  exit;
66 66
 	}
67 67
 	function curl_response($url)
68 68
 	{
69
-		    $ch = curl_init();  // Initialising cURL
70
-		    curl_setopt ( $ch, CURLOPT_URL, $url );
71
-		    curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
72
-		    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
73
-		    curl_setopt ( $ch, CURLOPT_ENCODING, "" );
74
-		    curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
75
-		    $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
76
-		    curl_close($ch);        // Closing cURL
77
-		    return $data;
69
+			$ch = curl_init();  // Initialising cURL
70
+			curl_setopt ( $ch, CURLOPT_URL, $url );
71
+			curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
72
+			curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
73
+			curl_setopt ( $ch, CURLOPT_ENCODING, "" );
74
+			curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
75
+			$data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
76
+			curl_close($ch);        // Closing cURL
77
+			return $data;
78 78
 	}
79 79
 }
80 80
 ?>
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -29,30 +29,30 @@  discard block
 block discarded – undo
29 29
         $this->load->model("db_model");
30 30
         $this->load->library("astpp/common");
31 31
     }
32
-    function update_currency(){
32
+    function update_currency() {
33 33
         $where = array("currency <>"=> Common_model::$global_config['system_config']['base_currency']);
34 34
         $query = $this->db_model->getSelect("*", "currency", $where);
35 35
 
36
-        if($query->num_rows >0){
37
-            $currency_data =$query->result_array();
36
+        if ($query->num_rows > 0) {
37
+            $currency_data = $query->result_array();
38 38
     		$url = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=";
39 39
 	    	foreach ($currency_data as $currency_value) {
40 40
 	    	    $url .= Common_model::$global_config['system_config']['base_currency'].$currency_value['currency'].'=X+';
41 41
 	    	}
42 42
 	    	$url .= '&f=l1';
43 43
 
44
-	    	$sql='';
44
+	    	$sql = '';
45 45
 	    	$response = $this->curl_response($url);
46
-	    	$content_data = explode(' ',$response);
46
+	    	$content_data = explode(' ', $response);
47 47
 
48
-	    	foreach ($content_data as $content_data1){
49
-	    	   $currency_arr= explode("\n", $content_data1);
50
-	    	    foreach($currency_arr as $final_val)
48
+	    	foreach ($content_data as $content_data1) {
49
+	    	   $currency_arr = explode("\n", $content_data1);
50
+	    	    foreach ($currency_arr as $final_val)
51 51
 	    	    {
52 52
 	    	        $currency_final = array();
53
-	    		    $currency_final= explode(',', $final_val);
54
-	    		    if(isset($currency_final[1]) && $currency_final[1] != "" && $currency_final[0]!='' && $currency_final[1] != 'N/A'){
55
-			      $sql = "UPDATE currency SET currencyRate = ".$currency_final[1]." WHERE currency = '".substr($currency_final[0],4,3)."'";
53
+	    		    $currency_final = explode(',', $final_val);
54
+	    		    if (isset($currency_final[1]) && $currency_final[1] != "" && $currency_final[0] != '' && $currency_final[1] != 'N/A') {
55
+			      $sql = "UPDATE currency SET currencyRate = ".$currency_final[1]." WHERE currency = '".substr($currency_final[0], 4, 3)."'";
56 56
 			      $this->db->query($sql);
57 57
 	    		    }
58 58
 	    	    }
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	}
67 67
 	function curl_response($url)
68 68
 	{
69
-		    $ch = curl_init();  // Initialising cURL
70
-		    curl_setopt ( $ch, CURLOPT_URL, $url );
71
-		    curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
72
-		    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
73
-		    curl_setopt ( $ch, CURLOPT_ENCODING, "" );
74
-		    curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
69
+		    $ch = curl_init(); // Initialising cURL
70
+		    curl_setopt($ch, CURLOPT_URL, $url);
71
+		    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
72
+		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
73
+		    curl_setopt($ch, CURLOPT_ENCODING, "");
74
+		    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
75 75
 		    $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
76
-		    curl_close($ch);        // Closing cURL
76
+		    curl_close($ch); // Closing cURL
77 77
 		    return $data;
78 78
 	}
79 79
 }
Please login to merge, or discard this patch.
web_interface/astpp/application/controllers/generateInvoice.php 4 patches
Doc Comments   +15 added lines patch added patch discarded remove patch
@@ -89,6 +89,10 @@  discard block
 block discarded – undo
89 89
         return $last_invoice_date;
90 90
     }
91 91
 
92
+    /**
93
+     * @param string $start_date
94
+     * @param string $end_date
95
+     */
92 96
     function Generate_Daily_invoice($account_value, $start_date, $end_date) {
93 97
         //  echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date;
94 98
 
@@ -99,6 +103,10 @@  discard block
 block discarded – undo
99 103
         $this->process_invoice($account_value, $start_date, $end_date);
100 104
     }
101 105
 
106
+    /**
107
+     * @param string $start_date
108
+     * @param string $end_date
109
+     */
102 110
     function Generate_Monthly_invoice($account_value, $start_date, $end_date) {
103 111
         require_once('updateBalance.php');
104 112
         $updateBalance = new updateBalance();
@@ -181,6 +189,9 @@  discard block
 block discarded – undo
181 189
         return true;
182 190
     }
183 191
 
192
+    /**
193
+     * @param string $last_invoice_ID
194
+     */
184 195
     function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) {
185 196
         //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days"));
186 197
         if ($invoiceconf['interval'] > 0) {
@@ -234,6 +245,10 @@  discard block
 block discarded – undo
234 245
         }
235 246
     }
236 247
 
248
+    /**
249
+     * @param string $FilePath
250
+     * @param string $Filenm
251
+     */
237 252
     function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) {
238 253
         $TemplateData = array();
239 254
         $where = array('name' => 'email_new_invoice');
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -24,249 +24,249 @@
 block discarded – undo
24 24
 
25 25
 class GenerateInvoice extends MX_Controller {
26 26
 
27
-    public static $global_config;
27
+	public static $global_config;
28 28
 
29
-    function __construct() {
30
-        parent::__construct();
31
-        $this->load->model("db_model");
32
-        $this->load->library("astpp/common");
33
-        $this->load->library('html2pdf');
34
-        ini_set("memory_limit", "2048M");
35
-        ini_set("max_execution_time", "259200");
36
-        $this->get_system_config();
37
-    }
29
+	function __construct() {
30
+		parent::__construct();
31
+		$this->load->model("db_model");
32
+		$this->load->library("astpp/common");
33
+		$this->load->library('html2pdf');
34
+		ini_set("memory_limit", "2048M");
35
+		ini_set("max_execution_time", "259200");
36
+		$this->get_system_config();
37
+	}
38 38
 
39
-    function get_system_config() {
40
-        $query = $this->db->get("system");
41
-        $config = array();
42
-        $result = $query->result_array();
43
-        foreach ($result as $row) {
44
-            $config[$row['name']] = $row['value'];
45
-        }
46
-        self::$global_config['system_config'] = $config;
47
-    }
39
+	function get_system_config() {
40
+		$query = $this->db->get("system");
41
+		$config = array();
42
+		$result = $query->result_array();
43
+		foreach ($result as $row) {
44
+			$config[$row['name']] = $row['value'];
45
+		}
46
+		self::$global_config['system_config'] = $config;
47
+	}
48 48
 
49
-    function getInvoiceData() {
50
-        $where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0");
51
-        $query = $this->db_model->getSelect("*", "accounts", $where);
52
-        if ($query->num_rows > 0) {
53
-            $account_data = $query->result_array();
54
-            foreach ($account_data as $data_key => $account_value) {
55
-                $end_date = gmdate("Y-m-d") . " 23:59:59";
56
-                $account_value['sweep_id'] = (int) $account_value['sweep_id'];
57
-                switch ($account_value['sweep_id']) {
58
-                    case 0:
59
-                        $start_date = $this->validate_invoice_date($account_value);
60
-                        if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
61
-                            $start_date = gmdate("Y-m-d H:i:s");
62
-                        }
63
-                        $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date . " + 1 days"));
64
-                        $this->Generate_Daily_invoice($account_value, $start_date, $end_date);
65
-                        break;
66
-                    case 2:
67
-                        if (date("d") == $account_value['invoice_day']) {
68
-                            $start_date = $this->validate_invoice_date($account_value);
69
-                            if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
70
-                                $start_date = gmdate("Y-m-d H:i:s");
71
-                            }
72
-                            $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date . " + 1 month"));
73
-                            $this->Generate_Monthly_invoice($account_value, $start_date, $end_date);
74
-                        }
75
-                        break;
76
-                }
77
-            }
78
-            $screen_path = getcwd() . "/cron";
79
-            $screen_filename = "Email_Broadcast_" . strtotime('now');
80
-            $command = "cd " . $screen_path . " && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
81
-            exec($command);
82
-        }
83
-    }
49
+	function getInvoiceData() {
50
+		$where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0");
51
+		$query = $this->db_model->getSelect("*", "accounts", $where);
52
+		if ($query->num_rows > 0) {
53
+			$account_data = $query->result_array();
54
+			foreach ($account_data as $data_key => $account_value) {
55
+				$end_date = gmdate("Y-m-d") . " 23:59:59";
56
+				$account_value['sweep_id'] = (int) $account_value['sweep_id'];
57
+				switch ($account_value['sweep_id']) {
58
+					case 0:
59
+						$start_date = $this->validate_invoice_date($account_value);
60
+						if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
61
+							$start_date = gmdate("Y-m-d H:i:s");
62
+						}
63
+						$end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date . " + 1 days"));
64
+						$this->Generate_Daily_invoice($account_value, $start_date, $end_date);
65
+						break;
66
+					case 2:
67
+						if (date("d") == $account_value['invoice_day']) {
68
+							$start_date = $this->validate_invoice_date($account_value);
69
+							if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
70
+								$start_date = gmdate("Y-m-d H:i:s");
71
+							}
72
+							$end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date . " + 1 month"));
73
+							$this->Generate_Monthly_invoice($account_value, $start_date, $end_date);
74
+						}
75
+						break;
76
+				}
77
+			}
78
+			$screen_path = getcwd() . "/cron";
79
+			$screen_filename = "Email_Broadcast_" . strtotime('now');
80
+			$command = "cd " . $screen_path . " && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
81
+			exec($command);
82
+		}
83
+	}
84 84
 
85
-    function validate_invoice_date($account_value) {
86
-        $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"],$account_value['reseller_id'],"to_date");
87
-        $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation'];
88
-        $last_invoice_date = gmdate("Y-m-d H:i:s",strtotime("+1 Second",strtotime($last_invoice_date)));
89
-        return $last_invoice_date;
90
-    }
85
+	function validate_invoice_date($account_value) {
86
+		$last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"],$account_value['reseller_id'],"to_date");
87
+		$last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation'];
88
+		$last_invoice_date = gmdate("Y-m-d H:i:s",strtotime("+1 Second",strtotime($last_invoice_date)));
89
+		return $last_invoice_date;
90
+	}
91 91
 
92
-    function Generate_Daily_invoice($account_value, $start_date, $end_date) {
93
-        //  echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date;
92
+	function Generate_Daily_invoice($account_value, $start_date, $end_date) {
93
+		//  echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date;
94 94
 
95
-        require_once('updateBalance.php');
96
-        $updateBalance = new updateBalance();
97
-        $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
98
-        $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE);
99
-        $this->process_invoice($account_value, $start_date, $end_date);
100
-    }
95
+		require_once('updateBalance.php');
96
+		$updateBalance = new updateBalance();
97
+		$updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
98
+		$updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE);
99
+		$this->process_invoice($account_value, $start_date, $end_date);
100
+	}
101 101
 
102
-    function Generate_Monthly_invoice($account_value, $start_date, $end_date) {
103
-        require_once('updateBalance.php');
104
-        $updateBalance = new updateBalance();
105
-        $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
106
-        $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); 
107
-        $this->process_invoice($account_value, $start_date, $end_date);
108
-    }
102
+	function Generate_Monthly_invoice($account_value, $start_date, $end_date) {
103
+		require_once('updateBalance.php');
104
+		$updateBalance = new updateBalance();
105
+		$updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
106
+		$updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); 
107
+		$this->process_invoice($account_value, $start_date, $end_date);
108
+	}
109 109
 
110
-    function process_invoice($accountdata, $start_date, $end_date) {
111
-        //Get Invoice configuration using single query instead of multiple queries.
112
-        $invoice_conf = array();
113
-        $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id'];
114
-        $where = "accountid IN ('" . $reseller_id . "','1')";
115
-        $this->db->select('*');
116
-        $this->db->where($where);
117
-        $this->db->order_by('accountid', 'desc');
118
-        $this->db->limit(1);
119
-        $invoice_conf = $this->db->get('invoice_conf');
120
-        $invoice_conf = (array)$invoice_conf->first_row();
121
-        /*******************************************************/
122
-        $last_invoice_ID = $this->common->get_invoice_date("invoiceid","", $accountdata['reseller_id']);
123
-        if ($last_invoice_ID && $last_invoice_ID > 0) {
124
-            $last_invoice_ID = ($last_invoice_ID + 1);
125
-        } else {
126
-            $last_invoice_ID = $invoice_conf['invoice_start_from'];
127
-        }
128
-        $last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT);
129
-        $invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date);
130
-        if ($invoice_sub_total > 0) {
131
-            $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
132
-            $this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date);
133
-            $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
134
-            $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
135
-            $this->download_invoice($invoiceid, $accountdata, $invoice_conf);
136
-        } else {
137
-            $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
138
-            $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
139
-            $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
140
-        }
141
-    }
110
+	function process_invoice($accountdata, $start_date, $end_date) {
111
+		//Get Invoice configuration using single query instead of multiple queries.
112
+		$invoice_conf = array();
113
+		$reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id'];
114
+		$where = "accountid IN ('" . $reseller_id . "','1')";
115
+		$this->db->select('*');
116
+		$this->db->where($where);
117
+		$this->db->order_by('accountid', 'desc');
118
+		$this->db->limit(1);
119
+		$invoice_conf = $this->db->get('invoice_conf');
120
+		$invoice_conf = (array)$invoice_conf->first_row();
121
+		/*******************************************************/
122
+		$last_invoice_ID = $this->common->get_invoice_date("invoiceid","", $accountdata['reseller_id']);
123
+		if ($last_invoice_ID && $last_invoice_ID > 0) {
124
+			$last_invoice_ID = ($last_invoice_ID + 1);
125
+		} else {
126
+			$last_invoice_ID = $invoice_conf['invoice_start_from'];
127
+		}
128
+		$last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT);
129
+		$invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date);
130
+		if ($invoice_sub_total > 0) {
131
+			$invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
132
+			$this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date);
133
+			$sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
134
+			$invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
135
+			$this->download_invoice($invoiceid, $accountdata, $invoice_conf);
136
+		} else {
137
+			$invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
138
+			$sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
139
+			$invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
140
+		}
141
+	}
142 142
 
143
-    function count_invoice_data($account, $start_date = "", $end_date = "") {
144
-        $cdr_query = "";
145
-        $inv_data_query = "";
146
-        $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = " . $account['id'];
147
-        $cdr_query .= " AND callstart >='" . $start_date . "' AND callstart <= '" . $end_date . "' AND invoiceid=0 group by calltype";
143
+	function count_invoice_data($account, $start_date = "", $end_date = "") {
144
+		$cdr_query = "";
145
+		$inv_data_query = "";
146
+		$cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = " . $account['id'];
147
+		$cdr_query .= " AND callstart >='" . $start_date . "' AND callstart <= '" . $end_date . "' AND invoiceid=0 group by calltype";
148 148
 //echo $cdr_query; 
149
-        $cdr_data = $this->db->query($cdr_query);
150
-        if ($cdr_data->num_rows > 0) {
151
-            $cdr_data = $cdr_data->result_array();
152
-            //echo '<pre>'; print_r($cdr_data); exit;
153
-            foreach ($cdr_data as $cdrvalue) {
154
-                $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']);
155
-                $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0",
156
-                    "description" => $cdrvalue['calltype'] . " CALLS for the period (" . $start_date . " to " . $end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date);
157
-                $this->db->insert("invoice_details", $tempArr);
158
-            }
159
-        }
160
-        $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=" . $account['id'] . " AND created_date >='" . $start_date . "' AND created_date <= '" . $end_date . "'  AND invoiceid=0 AND item_type != 'FREECALL'";
149
+		$cdr_data = $this->db->query($cdr_query);
150
+		if ($cdr_data->num_rows > 0) {
151
+			$cdr_data = $cdr_data->result_array();
152
+			//echo '<pre>'; print_r($cdr_data); exit;
153
+			foreach ($cdr_data as $cdrvalue) {
154
+				$cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']);
155
+				$tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0",
156
+					"description" => $cdrvalue['calltype'] . " CALLS for the period (" . $start_date . " to " . $end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date);
157
+				$this->db->insert("invoice_details", $tempArr);
158
+			}
159
+		}
160
+		$inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=" . $account['id'] . " AND created_date >='" . $start_date . "' AND created_date <= '" . $end_date . "'  AND invoiceid=0 AND item_type != 'FREECALL'";
161 161
 //echo $inv_data_query;         
162
-        $invoice_data = $this->db->query($inv_data_query);
163
-        if ($invoice_data->num_rows > 0) {
164
-            $invoice_data = $invoice_data->result_array();
165
-            foreach ($invoice_data as $data_value) {
166
-                if ($data_value['count'] > 0) {
167
-                    $sub_total = ($data_value['debit'] - $data_value['credit']);
168
-                    $sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']);
169
-                    return $sub_total;
170
-                }
171
-            }
172
-        }
173
-        return "0";
174
-    }
162
+		$invoice_data = $this->db->query($inv_data_query);
163
+		if ($invoice_data->num_rows > 0) {
164
+			$invoice_data = $invoice_data->result_array();
165
+			foreach ($invoice_data as $data_value) {
166
+				if ($data_value['count'] > 0) {
167
+					$sub_total = ($data_value['debit'] - $data_value['credit']);
168
+					$sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']);
169
+					return $sub_total;
170
+				}
171
+			}
172
+		}
173
+		return "0";
174
+	}
175 175
 
176
-    //Change Order of arguements
177
-    function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") {
178
-        $inv_data_query = "update invoice_details SET invoiceid = '" . $invoiceid . "' where accountid=" . $accountid;
179
-        $inv_data_query .= " AND created_date >='" . $start_date . "' AND created_date <= '" . $end_date . "'  AND invoiceid=0 AND item_type !='PAYMENT'";
180
-        $this->db->query($inv_data_query);
181
-        return true;
182
-    }
176
+	//Change Order of arguements
177
+	function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") {
178
+		$inv_data_query = "update invoice_details SET invoiceid = '" . $invoiceid . "' where accountid=" . $accountid;
179
+		$inv_data_query .= " AND created_date >='" . $start_date . "' AND created_date <= '" . $end_date . "'  AND invoiceid=0 AND item_type !='PAYMENT'";
180
+		$this->db->query($inv_data_query);
181
+		return true;
182
+	}
183 183
 
184
-    function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) {
185
-        //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days"));
186
-        if ($invoiceconf['interval'] > 0) {
187
-            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoiceconf['interval'] . " days"));
188
-        } else {
189
-            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +7 days"));
190
-        }
191
-        // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; 
192
-        $balance = ($account['credit_limit'] - $account['balance']);
193
-        $automatic_flag = self::$global_config['system_config']['automatic_invoice'];
184
+	function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) {
185
+		//$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days"));
186
+		if ($invoiceconf['interval'] > 0) {
187
+			$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoiceconf['interval'] . " days"));
188
+		} else {
189
+			$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +7 days"));
190
+		}
191
+		// echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; 
192
+		$balance = ($account['credit_limit'] - $account['balance']);
193
+		$automatic_flag = self::$global_config['system_config']['automatic_invoice'];
194 194
 	if($automatic_flag == 1){
195
-	        $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
196
-            $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance);
195
+			$invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
196
+			$account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance);
197 197
 	}else{
198
-	        $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
199
-            $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1);
198
+			$invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
199
+			$account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1);
200 200
 	}
201
-        // echo "<pre>"; print_r($invoice_data); exit;
202
-        $this->db->insert("invoices", $invoice_data);
203
-        $invoiceid = $this->db->insert_id();
201
+		// echo "<pre>"; print_r($invoice_data); exit;
202
+		$this->db->insert("invoices", $invoice_data);
203
+		$invoiceid = $this->db->insert_id();
204 204
 	if($automatic_flag == 0){
205
-            $this->download_invoice($invoiceid, $account, $invoiceconf);
205
+			$this->download_invoice($invoiceid, $account, $invoiceconf);
206
+	}
207
+		return $invoiceid;
206 208
 	}
207
-        return $invoiceid;
208
-    }
209 209
 
210
-    function set_invoice_total($invoiceid, $accountid) {
211
-        $query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL"));
212
-        $query = $query->result_array();
213
-        $sub_total = $query["0"]["total"];
214
-        $updateArr = array("amount" => $sub_total);
215
-        $this->db->where(array("id" => $invoiceid));
216
-        $this->db->update("invoices", $updateArr);
210
+	function set_invoice_total($invoiceid, $accountid) {
211
+		$query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL"));
212
+		$query = $query->result_array();
213
+		$sub_total = $query["0"]["total"];
214
+		$updateArr = array("amount" => $sub_total);
215
+		$this->db->where(array("id" => $invoiceid));
216
+		$this->db->update("invoices", $updateArr);
217 217
 
218
-        $updateArr = array("balance" => "0.00");
219
-        $this->db->where(array("id" => $accountid));
220
-        $this->db->update("accounts", $updateArr);
218
+		$updateArr = array("balance" => "0.00");
219
+		$this->db->where(array("id" => $accountid));
220
+		$this->db->update("accounts", $updateArr);
221 221
 
222
-        return true;
223
-    }
222
+		return true;
223
+	}
224 224
 
225
-    function download_invoice($invoiceid, $accountdata, $invoice_conf) {
226
-        $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid));
227
-        $invoicedata = $invoicedata->result_array();
228
-        $invoicedata = $invoicedata[0];
229
-        $FilePath = FCPATH . "invoices/" . $accountdata["id"] . '/' . $invoicedata['invoice_prefix']."".$invoicedata['invoiceid'] . "_invoice.pdf";
230
-        $Filenm = $invoicedata['invoice_prefix'] ."_". $invoicedata['invoiceid'] . "_invoice.pdf";
231
-        $this->common->get_invoice_template($invoicedata, $accountdata, false);
232
-        if ($invoice_conf['invoice_notification']) {
233
-            $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata);
234
-        }
235
-    }
225
+	function download_invoice($invoiceid, $accountdata, $invoice_conf) {
226
+		$invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid));
227
+		$invoicedata = $invoicedata->result_array();
228
+		$invoicedata = $invoicedata[0];
229
+		$FilePath = FCPATH . "invoices/" . $accountdata["id"] . '/' . $invoicedata['invoice_prefix']."".$invoicedata['invoiceid'] . "_invoice.pdf";
230
+		$Filenm = $invoicedata['invoice_prefix'] ."_". $invoicedata['invoiceid'] . "_invoice.pdf";
231
+		$this->common->get_invoice_template($invoicedata, $accountdata, false);
232
+		if ($invoice_conf['invoice_notification']) {
233
+			$this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata);
234
+		}
235
+	}
236 236
 
237
-    function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) {
238
-        $TemplateData = array();
239
-        $where = array('name' => 'email_new_invoice');
240
-        $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where);
241
-        foreach ($EmailTemplate->result_array() as $TemplateVal) {
242
-            $TemplateData = $TemplateVal;
243
-            $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name'] . " " . $AccountData['last_name'], $TemplateData['subject']);
244
-            $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'] . $invData['invoiceid'], $TemplateData['subject']);
245
-            $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name'] . " " . $AccountData['last_name'], $TemplateData['template']);
246
-            $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'] . $invData['invoiceid'], $TemplateData['template']);
247
-            $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']);
237
+	function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) {
238
+		$TemplateData = array();
239
+		$where = array('name' => 'email_new_invoice');
240
+		$EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where);
241
+		foreach ($EmailTemplate->result_array() as $TemplateVal) {
242
+			$TemplateData = $TemplateVal;
243
+			$TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name'] . " " . $AccountData['last_name'], $TemplateData['subject']);
244
+			$TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'] . $invData['invoiceid'], $TemplateData['subject']);
245
+			$TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name'] . " " . $AccountData['last_name'], $TemplateData['template']);
246
+			$TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'] . $invData['invoiceid'], $TemplateData['template']);
247
+			$TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']);
248 248
 
249
-            $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']);
250
-            $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']);
251
-            $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']);
252
-            $TemplateData['template'] = str_replace("#INVOICE_DATE#",$invData['invoice_date'], $TemplateData['template']);
253
-            $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']);
254
-        }
255
-        $dir_path = getcwd() . "/attachments/";
256
-        $path = $dir_path . $Filenm;
257
-        $command = "cp " . $FilePath . " " . $path;
258
-        exec($command);
259
-        $email_array = array('accountid' => $AccountData['id'],
260
-            'subject' => $TemplateData['subject'],
261
-            'body' => $TemplateData['template'],
262
-            'from' => $invoice_conf['emailaddress'],
263
-            'to' => $AccountData['email'],
264
-            'status' => "1",
265
-            'attachment' => $Filenm,
266
-            'template' => '');
267
-        //echo "<pre>"; print_r($TemplateData); exit;
268
-        $this->db->insert("mail_details", $email_array);
269
-    }
249
+			$TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']);
250
+			$TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']);
251
+			$TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']);
252
+			$TemplateData['template'] = str_replace("#INVOICE_DATE#",$invData['invoice_date'], $TemplateData['template']);
253
+			$TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']);
254
+		}
255
+		$dir_path = getcwd() . "/attachments/";
256
+		$path = $dir_path . $Filenm;
257
+		$command = "cp " . $FilePath . " " . $path;
258
+		exec($command);
259
+		$email_array = array('accountid' => $AccountData['id'],
260
+			'subject' => $TemplateData['subject'],
261
+			'body' => $TemplateData['template'],
262
+			'from' => $invoice_conf['emailaddress'],
263
+			'to' => $AccountData['email'],
264
+			'status' => "1",
265
+			'attachment' => $Filenm,
266
+			'template' => '');
267
+		//echo "<pre>"; print_r($TemplateData); exit;
268
+		$this->db->insert("mail_details", $email_array);
269
+	}
270 270
 
271 271
 }
272 272
 
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
         if ($query->num_rows > 0) {
53 53
             $account_data = $query->result_array();
54 54
             foreach ($account_data as $data_key => $account_value) {
55
-                $end_date = gmdate("Y-m-d") . " 23:59:59";
56
-                $account_value['sweep_id'] = (int) $account_value['sweep_id'];
55
+                $end_date = gmdate("Y-m-d")." 23:59:59";
56
+                $account_value['sweep_id'] = (int)$account_value['sweep_id'];
57 57
                 switch ($account_value['sweep_id']) {
58 58
                     case 0:
59 59
                         $start_date = $this->validate_invoice_date($account_value);
60 60
                         if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
61 61
                             $start_date = gmdate("Y-m-d H:i:s");
62 62
                         }
63
-                        $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date . " + 1 days"));
63
+                        $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days"));
64 64
                         $this->Generate_Daily_invoice($account_value, $start_date, $end_date);
65 65
                         break;
66 66
                     case 2:
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
                             if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
70 70
                                 $start_date = gmdate("Y-m-d H:i:s");
71 71
                             }
72
-                            $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date . " + 1 month"));
72
+                            $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month"));
73 73
                             $this->Generate_Monthly_invoice($account_value, $start_date, $end_date);
74 74
                         }
75 75
                         break;
76 76
                 }
77 77
             }
78
-            $screen_path = getcwd() . "/cron";
79
-            $screen_filename = "Email_Broadcast_" . strtotime('now');
80
-            $command = "cd " . $screen_path . " && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
78
+            $screen_path = getcwd()."/cron";
79
+            $screen_filename = "Email_Broadcast_".strtotime('now');
80
+            $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
81 81
             exec($command);
82 82
         }
83 83
     }
84 84
 
85 85
     function validate_invoice_date($account_value) {
86
-        $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"],$account_value['reseller_id'],"to_date");
86
+        $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date");
87 87
         $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation'];
88
-        $last_invoice_date = gmdate("Y-m-d H:i:s",strtotime("+1 Second",strtotime($last_invoice_date)));
88
+        $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date)));
89 89
         return $last_invoice_date;
90 90
     }
91 91
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
         //Get Invoice configuration using single query instead of multiple queries.
112 112
         $invoice_conf = array();
113 113
         $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id'];
114
-        $where = "accountid IN ('" . $reseller_id . "','1')";
114
+        $where = "accountid IN ('".$reseller_id."','1')";
115 115
         $this->db->select('*');
116 116
         $this->db->where($where);
117 117
         $this->db->order_by('accountid', 'desc');
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         $invoice_conf = $this->db->get('invoice_conf');
120 120
         $invoice_conf = (array)$invoice_conf->first_row();
121 121
         /*******************************************************/
122
-        $last_invoice_ID = $this->common->get_invoice_date("invoiceid","", $accountdata['reseller_id']);
122
+        $last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']);
123 123
         if ($last_invoice_ID && $last_invoice_ID > 0) {
124 124
             $last_invoice_ID = ($last_invoice_ID + 1);
125 125
         } else {
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
     function count_invoice_data($account, $start_date = "", $end_date = "") {
144 144
         $cdr_query = "";
145 145
         $inv_data_query = "";
146
-        $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = " . $account['id'];
147
-        $cdr_query .= " AND callstart >='" . $start_date . "' AND callstart <= '" . $end_date . "' AND invoiceid=0 group by calltype";
146
+        $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id'];
147
+        $cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype";
148 148
 //echo $cdr_query; 
149 149
         $cdr_data = $this->db->query($cdr_query);
150 150
         if ($cdr_data->num_rows > 0) {
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
             foreach ($cdr_data as $cdrvalue) {
154 154
                 $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']);
155 155
                 $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0",
156
-                    "description" => $cdrvalue['calltype'] . " CALLS for the period (" . $start_date . " to " . $end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date);
156
+                    "description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date);
157 157
                 $this->db->insert("invoice_details", $tempArr);
158 158
             }
159 159
         }
160
-        $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=" . $account['id'] . " AND created_date >='" . $start_date . "' AND created_date <= '" . $end_date . "'  AND invoiceid=0 AND item_type != 'FREECALL'";
160
+        $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."'  AND invoiceid=0 AND item_type != 'FREECALL'";
161 161
 //echo $inv_data_query;         
162 162
         $invoice_data = $this->db->query($inv_data_query);
163 163
         if ($invoice_data->num_rows > 0) {
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 
176 176
     //Change Order of arguements
177 177
     function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") {
178
-        $inv_data_query = "update invoice_details SET invoiceid = '" . $invoiceid . "' where accountid=" . $accountid;
179
-        $inv_data_query .= " AND created_date >='" . $start_date . "' AND created_date <= '" . $end_date . "'  AND invoiceid=0 AND item_type !='PAYMENT'";
178
+        $inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid;
179
+        $inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."'  AND invoiceid=0 AND item_type !='PAYMENT'";
180 180
         $this->db->query($inv_data_query);
181 181
         return true;
182 182
     }
@@ -184,24 +184,24 @@  discard block
 block discarded – undo
184 184
     function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) {
185 185
         //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days"));
186 186
         if ($invoiceconf['interval'] > 0) {
187
-            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoiceconf['interval'] . " days"));
187
+            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days"));
188 188
         } else {
189
-            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +7 days"));
189
+            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days"));
190 190
         }
191 191
         // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; 
192 192
         $balance = ($account['credit_limit'] - $account['balance']);
193 193
         $automatic_flag = self::$global_config['system_config']['automatic_invoice'];
194
-	if($automatic_flag == 1){
194
+	if ($automatic_flag == 1) {
195 195
 	        $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
196 196
             $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance);
197
-	}else{
197
+	} else {
198 198
 	        $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
199 199
             $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1);
200 200
 	}
201 201
         // echo "<pre>"; print_r($invoice_data); exit;
202 202
         $this->db->insert("invoices", $invoice_data);
203 203
         $invoiceid = $this->db->insert_id();
204
-	if($automatic_flag == 0){
204
+	if ($automatic_flag == 0) {
205 205
             $this->download_invoice($invoiceid, $account, $invoiceconf);
206 206
 	}
207 207
         return $invoiceid;
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
         $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid));
227 227
         $invoicedata = $invoicedata->result_array();
228 228
         $invoicedata = $invoicedata[0];
229
-        $FilePath = FCPATH . "invoices/" . $accountdata["id"] . '/' . $invoicedata['invoice_prefix']."".$invoicedata['invoiceid'] . "_invoice.pdf";
230
-        $Filenm = $invoicedata['invoice_prefix'] ."_". $invoicedata['invoiceid'] . "_invoice.pdf";
229
+        $FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf";
230
+        $Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf";
231 231
         $this->common->get_invoice_template($invoicedata, $accountdata, false);
232 232
         if ($invoice_conf['invoice_notification']) {
233 233
             $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata);
@@ -240,21 +240,21 @@  discard block
 block discarded – undo
240 240
         $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where);
241 241
         foreach ($EmailTemplate->result_array() as $TemplateVal) {
242 242
             $TemplateData = $TemplateVal;
243
-            $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name'] . " " . $AccountData['last_name'], $TemplateData['subject']);
244
-            $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'] . $invData['invoiceid'], $TemplateData['subject']);
245
-            $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name'] . " " . $AccountData['last_name'], $TemplateData['template']);
246
-            $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'] . $invData['invoiceid'], $TemplateData['template']);
243
+            $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']);
244
+            $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']);
245
+            $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']);
246
+            $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']);
247 247
             $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']);
248 248
 
249 249
             $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']);
250 250
             $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']);
251 251
             $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']);
252
-            $TemplateData['template'] = str_replace("#INVOICE_DATE#",$invData['invoice_date'], $TemplateData['template']);
252
+            $TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']);
253 253
             $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']);
254 254
         }
255
-        $dir_path = getcwd() . "/attachments/";
256
-        $path = $dir_path . $Filenm;
257
-        $command = "cp " . $FilePath . " " . $path;
255
+        $dir_path = getcwd()."/attachments/";
256
+        $path = $dir_path.$Filenm;
257
+        $command = "cp ".$FilePath." ".$path;
258 258
         exec($command);
259 259
         $email_array = array('accountid' => $AccountData['id'],
260 260
             'subject' => $TemplateData['subject'],
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@
 block discarded – undo
208 208
 <?php
209 209
 	if($account_data['logo']  != ''){
210 210
 	     $logo=$account_data['file'];
211
-	}else{
211
+	} else{
212 212
 	     $logo=$account_data['logo'];
213 213
 	}
214 214
           if($logo != ''){        
Please login to merge, or discard this patch.
web_interface/astpp/application/controllers/updateBalance.php 4 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -153,6 +153,10 @@  discard block
 block discarded – undo
153 153
         }
154 154
     }
155 155
 
156
+    /**
157
+     * @param string $fromdate
158
+     * @param string $todate
159
+     */
156 160
     function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") {
157 161
         $lastdate = false;
158 162
         $billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month";
@@ -217,6 +221,9 @@  discard block
 block discarded – undo
217 221
         return $lastdate;
218 222
     }
219 223
 
224
+    /**
225
+     * @param string $todate
226
+     */
220 227
     function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) {
221 228
         $invoiceid = 0;
222 229
         $Bal = "0.00"; 
@@ -263,6 +270,10 @@  discard block
 block discarded – undo
263 270
         $this->manage_invoice($invoice_item_arr);
264 271
     }
265 272
     
273
+    /**
274
+     * @param string $select
275
+     * @param string $table
276
+     */
266 277
     function get_table_data($select, $table, $where) {
267 278
         $query = $this->db_model->getSelect($select, $table, $where);
268 279
         if ($query->num_rows > 0) {
Please login to merge, or discard this patch.
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -24,258 +24,258 @@
 block discarded – undo
24 24
 
25 25
 class UpdateBalance extends MX_Controller {
26 26
 
27
-    public $account_arr = array();
28
-    public $currentdate = '';
27
+	public $account_arr = array();
28
+	public $currentdate = '';
29 29
 
30
-    function __construct() {
31
-        parent::__construct();
32
-        $this->load->model("db_model");
33
-        $this->load->model("common_model");
34
-        $this->load->library("astpp/common");
35
-        $this->currentdate = gmdate('Y-m-d H:i:s');
36
-    }
30
+	function __construct() {
31
+		parent::__construct();
32
+		$this->load->model("db_model");
33
+		$this->load->model("common_model");
34
+		$this->load->library("astpp/common");
35
+		$this->currentdate = gmdate('Y-m-d H:i:s');
36
+	}
37 37
 
38
-    function GetUpdateBalance() {
39
-        $accounts_data = $this->get_table_data("*", "accounts", array("status" => "0", "deleted" => "0"));
40
-        foreach ($accounts_data as $account_val) {
41
-            $this->process_subscriptions($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
42
-            $this->process_DID_charges($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
43
-        }
44
-    }
38
+	function GetUpdateBalance() {
39
+		$accounts_data = $this->get_table_data("*", "accounts", array("status" => "0", "deleted" => "0"));
40
+		foreach ($accounts_data as $account_val) {
41
+			$this->process_subscriptions($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
42
+			$this->process_DID_charges($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
43
+		}
44
+	}
45 45
 
46
-    function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) {
46
+	function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) {
47 47
 //        Defined Original Sweep it for calculation start date for first time.
48
-        $accountinfo['original_sweep_id'] = $accountinfo['sweep_id'];
49
-        $invoiceid = 0;
48
+		$accountinfo['original_sweep_id'] = $accountinfo['sweep_id'];
49
+		$invoiceid = 0;
50 50
         
51
-        // Check Charge is applied that is for first time or already calculated before
51
+		// Check Charge is applied that is for first time or already calculated before
52 52
 
53
-        $where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='" . gmdate("Y-m-d H:i:s") . "')";
54
-        $this->db->where('accountid', $accountinfo['id']);
55
-        $this->db->where($where);
56
-        $this->db->select('*');
57
-        $account_charges = $this->db->get('charge_to_account');
58
-        if ($account_charges->num_rows() > 0) {
59
-            $accountchargs = $account_charges->result_array();
53
+		$where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='" . gmdate("Y-m-d H:i:s") . "')";
54
+		$this->db->where('accountid', $accountinfo['id']);
55
+		$this->db->where($where);
56
+		$this->db->select('*');
57
+		$account_charges = $this->db->get('charge_to_account');
58
+		if ($account_charges->num_rows() > 0) {
59
+			$accountchargs = $account_charges->result_array();
60 60
 
61
-            foreach ($accountchargs as $accharges) {
62
-                //Get information from database of active charges.
63
-                $charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0"));
64
-                if ($charge_data && !empty($charge_data)) {
65
-                    $charge_data = $charge_data[0];
66
-                    //Get Start Date of Charge
67
-                    $charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ?
68
-                            date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) :$accharges["assign_date"];
69
-                   if($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day']< gmdate("d",strtotime($accharges['assign_date'])))) {
70
-                      $charge_upto=   date("Y-m-" . $accountinfo['invoice_day'] . " H:i:s", strtotime($accharges["assign_date"]));
71
-                   }
72
-                    //Overwrite Billing scehdule of customer assign proper charge
73
-                    if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) {
74
-                        $accountinfo['sweep_id'] = $charge_data['sweep_id'];
75
-                    }
76
-                    //IF its already assigned before invoice start date then no need to applied same charge one more time
77
-                    if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
78
-                        $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
79
-                        if ($Manualflg) {
80
-                            $todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
81
-                        } else {
82
-                            $todate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
83
-                        }
84
-                        /*
61
+			foreach ($accountchargs as $accharges) {
62
+				//Get information from database of active charges.
63
+				$charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0"));
64
+				if ($charge_data && !empty($charge_data)) {
65
+					$charge_data = $charge_data[0];
66
+					//Get Start Date of Charge
67
+					$charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ?
68
+							date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) :$accharges["assign_date"];
69
+				   if($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day']< gmdate("d",strtotime($accharges['assign_date'])))) {
70
+					  $charge_upto=   date("Y-m-" . $accountinfo['invoice_day'] . " H:i:s", strtotime($accharges["assign_date"]));
71
+				   }
72
+					//Overwrite Billing scehdule of customer assign proper charge
73
+					if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) {
74
+						$accountinfo['sweep_id'] = $charge_data['sweep_id'];
75
+					}
76
+					//IF its already assigned before invoice start date then no need to applied same charge one more time
77
+					if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
78
+						$fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
79
+						if ($Manualflg) {
80
+							$todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
81
+						} else {
82
+							$todate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
83
+						}
84
+						/*
85 85
                          * Add assign_date and charge_upto variable for calculation purpose.
86 86
                          */
87
-                        $itemArr = array('description' => $charge_data['description'],
88
-                            'item_id' => $charge_data['id'],
89
-                            "type" => "SUBCHRG",
90
-                            "cycle" => $charge_data["sweep_id"],
91
-                            "assign_date"=>$accharges['assign_date'],
92
-                            "charge_upto"=>$accharges['charge_upto']);
87
+						$itemArr = array('description' => $charge_data['description'],
88
+							'item_id' => $charge_data['id'],
89
+							"type" => "SUBCHRG",
90
+							"cycle" => $charge_data["sweep_id"],
91
+							"assign_date"=>$accharges['assign_date'],
92
+							"charge_upto"=>$accharges['charge_upto']);
93 93
 			//Add a new arguement ($accharges) which have all information of charges.
94
-                        $lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]);
95
-                        if ($lastdate)
96
-                       $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"]));
97
-                    }
98
-                }
99
-            }
100
-        }
101
-    }
94
+						$lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]);
95
+						if ($lastdate)
96
+					   $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"]));
97
+					}
98
+				}
99
+			}
100
+		}
101
+	}
102 102
 
103
-    function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) {
104
-        $dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"]));
105
-        $AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id'];
106
-        $AccountDATA['sweep_id'] = '2';
107
-        if ($dids_data) {
108
-            foreach ($dids_data as $did_value) {
109
-                $charge_upto = ($did_value["charge_upto"] != "0000-00-00 00:00:00" && $did_value["charge_upto"] != "") ? $did_value["charge_upto"] : $did_value["assign_date"];
103
+	function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) {
104
+		$dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"]));
105
+		$AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id'];
106
+		$AccountDATA['sweep_id'] = '2';
107
+		if ($dids_data) {
108
+			foreach ($dids_data as $did_value) {
109
+				$charge_upto = ($did_value["charge_upto"] != "0000-00-00 00:00:00" && $did_value["charge_upto"] != "") ? $did_value["charge_upto"] : $did_value["assign_date"];
110 110
 
111
-                if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
112
-                    $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
113
-                    if ($Manualflg) {
114
-                        $todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
115
-                    } else {
116
-                        $todate = gmdate("Y-m-d H:i:s", strtotime($did_value["upto_date"]));
117
-                    }
118
-                    $itemArr = array('description' => $did_value['number'],
119
-                                    'item_id' => $did_value['id'],
120
-                                    "type" => "DIDCHRG",
121
-                                    "cycle" => "2",
122
-                                    "assign_date"=>$did_value['assign_date'],
123
-                                    "charge_upto"=>$did_value['charge_upto']);
124
-                    if ($did_value['parent_id'] > 0) {
125
-                        $parent_id = $did_value['parent_id'];
126
-                        while ($parent_id != 0) {
127
-                            $reseller_dids = $this->get_table_data("*", "reseller_pricing", array("reseller_id" => $parent_id, "note" => $did_value['number']));
128
-                            $reseller_acc_data = $this->get_table_data("*", "accounts", array("id" => $parent_id));
129
-                            $reseller_acc_data = $reseller_acc_data['0'];
130
-                            $reseller_acc_data['sweep_id'] = '2';
131
-                            $reseller_dids = $reseller_dids[0];
132
-                            if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) {
133
-                                //Apply charges to resellers customers.
134
-                                $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
135
-                                if ($lastdate)
136
-                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
137
-                            }else {
138
-                                //Apply charges to Resellers.
139
-                                $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
140
-                                if ($lastdate)
141
-                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
142
-                            }
143
-                            $parent_id = $reseller_dids['parent_id'];
144
-                        }
145
-                    }
111
+				if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
112
+					$fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
113
+					if ($Manualflg) {
114
+						$todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
115
+					} else {
116
+						$todate = gmdate("Y-m-d H:i:s", strtotime($did_value["upto_date"]));
117
+					}
118
+					$itemArr = array('description' => $did_value['number'],
119
+									'item_id' => $did_value['id'],
120
+									"type" => "DIDCHRG",
121
+									"cycle" => "2",
122
+									"assign_date"=>$did_value['assign_date'],
123
+									"charge_upto"=>$did_value['charge_upto']);
124
+					if ($did_value['parent_id'] > 0) {
125
+						$parent_id = $did_value['parent_id'];
126
+						while ($parent_id != 0) {
127
+							$reseller_dids = $this->get_table_data("*", "reseller_pricing", array("reseller_id" => $parent_id, "note" => $did_value['number']));
128
+							$reseller_acc_data = $this->get_table_data("*", "accounts", array("id" => $parent_id));
129
+							$reseller_acc_data = $reseller_acc_data['0'];
130
+							$reseller_acc_data['sweep_id'] = '2';
131
+							$reseller_dids = $reseller_dids[0];
132
+							if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) {
133
+								//Apply charges to resellers customers.
134
+								$lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
135
+								if ($lastdate)
136
+									$this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
137
+							}else {
138
+								//Apply charges to Resellers.
139
+								$lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
140
+								if ($lastdate)
141
+									$this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
142
+							}
143
+							$parent_id = $reseller_dids['parent_id'];
144
+						}
145
+					}
146 146
 //   		else{
147
-                    $lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1");
148
-                    if ($lastdate)
149
-                      $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"]));
147
+					$lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1");
148
+					if ($lastdate)
149
+					  $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"]));
150 150
 //            	}
151
-                }
152
-            }
153
-        }
154
-    }
151
+				}
152
+			}
153
+		}
154
+	}
155 155
 
156
-    function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") {
157
-        $lastdate = false;
158
-        $billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month";
159
-        $last_invoice_date = $this->common->get_invoice_date("invoice_date",$AccountDATA['id'],$AccountDATA['reseller_id']);
160
-      //Below variable gives date based on assign or creation or monthly user billing day
161
-        $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day']< gmdate("d",strtotime($itemArr['assign_date'])))) ? date("Y-m-" . $AccountDATA['invoice_day'] . " 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation']))));
162
-        $last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate;
163
-        $Charges_date_range = array();
164
-        $prorate_array =array();
165
-        $daylen = 60 * 60 * 24;
166
-        /*Get assign day and billing day for postpaid monthly user.
156
+	function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") {
157
+		$lastdate = false;
158
+		$billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month";
159
+		$last_invoice_date = $this->common->get_invoice_date("invoice_date",$AccountDATA['id'],$AccountDATA['reseller_id']);
160
+	  //Below variable gives date based on assign or creation or monthly user billing day
161
+		$last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day']< gmdate("d",strtotime($itemArr['assign_date'])))) ? date("Y-m-" . $AccountDATA['invoice_day'] . " 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation']))));
162
+		$last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate;
163
+		$Charges_date_range = array();
164
+		$prorate_array =array();
165
+		$daylen = 60 * 60 * 24;
166
+		/*Get assign day and billing day for postpaid monthly user.
167 167
          */
168
-        $assign_day=($AccountDATA['original_sweep_id']==2 && $AccountDATA['posttoexternal']==1) ? gmdate("d",strtotime($itemArr['assign_date'])):0;
169
-        $billing_day=($AccountDATA['original_sweep_id']==2 && $AccountDATA['posttoexternal']==1) ? $AccountDATA['invoice_day']:0;
170
-        //Create an array if charge not applied yet and invoice day is greater than assign_day
171
-        if($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate==0 && $itemArr['cycle']==2 && $AccountDATA['original_sweep_id']==2){
168
+		$assign_day=($AccountDATA['original_sweep_id']==2 && $AccountDATA['posttoexternal']==1) ? gmdate("d",strtotime($itemArr['assign_date'])):0;
169
+		$billing_day=($AccountDATA['original_sweep_id']==2 && $AccountDATA['posttoexternal']==1) ? $AccountDATA['invoice_day']:0;
170
+		//Create an array if charge not applied yet and invoice day is greater than assign_day
171
+		if($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate==0 && $itemArr['cycle']==2 && $AccountDATA['original_sweep_id']==2){
172 172
 	  $last_invoice_date = gmdate("Y-m-d H:i:s",strtotime("-1 second",strtotime(date("Y-m-" . $AccountDATA['invoice_day'] . " 00:00:00", strtotime($itemArr["assign_date"])))));
173 173
 	  $prorate_array[] = array("start_date" => date("Y-m-d H:i:s",strtotime($itemArr['assign_date'])), "end_date" => $last_invoice_date);
174 174
 	  
175
-        }
176
-        while (strtotime($last_invoice_date) <= strtotime($todate)) {
177
-            $startdate=$last_invoice_date;
178
-            $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+" . $billing_cycle, strtotime($last_invoice_date)));
179
-            $Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s",strtotime("+1 Second",strtotime($startdate))), "end_date" => $last_invoice_date);
180
-        }
181
-        if(!empty($prorate_array)){
182
-         array_pop($Charges_date_range);
183
-         $Charges_date_range=array_merge($prorate_array,$Charges_date_range);
184
-        }
185
-        if (!empty($Charges_date_range)) {
186
-            foreach ($Charges_date_range as $ChargeVal) {
187
-                if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate==0 && $itemArr['cycle']==2 && $AccountDATA['original_sweep_id']==2)) {
188
-                    $ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date'])));
189
-                }
190
-                if (!empty($itemArr['charge_upto']) && empty($lastdate)) {
191
-                    $start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2 ) ? $itemArr['assign_date'] : $ChargeVal['start_date'];
192
-                } else {
193
-                    $start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)));
194
-                }
175
+		}
176
+		while (strtotime($last_invoice_date) <= strtotime($todate)) {
177
+			$startdate=$last_invoice_date;
178
+			$last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+" . $billing_cycle, strtotime($last_invoice_date)));
179
+			$Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s",strtotime("+1 Second",strtotime($startdate))), "end_date" => $last_invoice_date);
180
+		}
181
+		if(!empty($prorate_array)){
182
+		 array_pop($Charges_date_range);
183
+		 $Charges_date_range=array_merge($prorate_array,$Charges_date_range);
184
+		}
185
+		if (!empty($Charges_date_range)) {
186
+			foreach ($Charges_date_range as $ChargeVal) {
187
+				if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate==0 && $itemArr['cycle']==2 && $AccountDATA['original_sweep_id']==2)) {
188
+					$ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date'])));
189
+				}
190
+				if (!empty($itemArr['charge_upto']) && empty($lastdate)) {
191
+					$start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2 ) ? $itemArr['assign_date'] : $ChargeVal['start_date'];
192
+				} else {
193
+					$start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)));
194
+				}
195 195
 
196
-                $lastdate = date("Y-m-d H:i:s", strtotime($ChargeVal['end_date']));
197
-                $end_date_str_time = strtotime("+1 Seconds", strtotime($lastdate));
198
-                $start_date_str_time = strtotime(gmdate("Y-m-d 00:00:00", strtotime($start_date)));
199
-                $temp_f_date = new DateTime(gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate))));
200
-                $temp_t_date = new DateTime($start_date);
201
-                $diff = $temp_f_date->diff($temp_t_date);
202
-                $month = (($diff->format('%y') * 12) + $diff->format('%m'));
203
-                $temp_charge = $charge;
204
-                if (($month != "1" || $pro_rate == "0") && $itemArr['cycle'] != '0') {
205
-                  //Calculate Number of days in month from start date
206
-                    $total_num_of_day = cal_days_in_month(CAL_GREGORIAN, date('m', $start_date_str_time), date('Y', $start_date_str_time));
207
-                    $days_diff = floor(($end_date_str_time - $start_date_str_time) / $daylen);
208
-                    $chrg_per_day = ($charge / $total_num_of_day);
209
-                    $temp_charge = ($chrg_per_day * $days_diff);
210
-                }
196
+				$lastdate = date("Y-m-d H:i:s", strtotime($ChargeVal['end_date']));
197
+				$end_date_str_time = strtotime("+1 Seconds", strtotime($lastdate));
198
+				$start_date_str_time = strtotime(gmdate("Y-m-d 00:00:00", strtotime($start_date)));
199
+				$temp_f_date = new DateTime(gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate))));
200
+				$temp_t_date = new DateTime($start_date);
201
+				$diff = $temp_f_date->diff($temp_t_date);
202
+				$month = (($diff->format('%y') * 12) + $diff->format('%m'));
203
+				$temp_charge = $charge;
204
+				if (($month != "1" || $pro_rate == "0") && $itemArr['cycle'] != '0') {
205
+				  //Calculate Number of days in month from start date
206
+					$total_num_of_day = cal_days_in_month(CAL_GREGORIAN, date('m', $start_date_str_time), date('Y', $start_date_str_time));
207
+					$days_diff = floor(($end_date_str_time - $start_date_str_time) / $daylen);
208
+					$chrg_per_day = ($charge / $total_num_of_day);
209
+					$temp_charge = ($chrg_per_day * $days_diff);
210
+				}
211 211
                 
212
-                if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date']))
213
-                    $this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate);
212
+				if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date']))
213
+					$this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate);
214 214
 //                echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>";
215
-            }
216
-        }
217
-        return $lastdate;
218
-    }
215
+			}
216
+		}
217
+		return $lastdate;
218
+	}
219 219
 
220
-    function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) {
221
-        $invoiceid = 0;
222
-        $Bal = "0.00"; 
223
-        if ($AccountData["posttoexternal"] == 0) {
224
-	    $reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0;
225
-	    $where = "accountid IN ('" . $reseller_id . "','1')";
226
-	    $this->db->where($where);
227
-	    $this->db->select('*');
228
-	    $this->db->order_by('accountid', 'desc');
229
-	    $this->db->limit(1);
230
-	    $invoiceconf = $this->db->get('invoice_conf');
231
-	    $invoice_conf = (array) $invoiceconf->first_row();
232
-	    $last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']);
233
-	    if ($last_invoiceid && $last_invoiceid > 0) {
234
-	    	$last_invoiceid = ($last_invoiceid + 1);
235
-  	    } else {
236
-	    	$last_invoiceid = $invoice_conf['invoice_start_from'];
237
-	    }
238
-	    $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
239
-	    $invoice_prefix = $invoice_conf['invoice_prefix'];
240
-	    $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoice_conf['interval'] . " days"));
220
+	function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) {
221
+		$invoiceid = 0;
222
+		$Bal = "0.00"; 
223
+		if ($AccountData["posttoexternal"] == 0) {
224
+		$reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0;
225
+		$where = "accountid IN ('" . $reseller_id . "','1')";
226
+		$this->db->where($where);
227
+		$this->db->select('*');
228
+		$this->db->order_by('accountid', 'desc');
229
+		$this->db->limit(1);
230
+		$invoiceconf = $this->db->get('invoice_conf');
231
+		$invoice_conf = (array) $invoiceconf->first_row();
232
+		$last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']);
233
+		if ($last_invoiceid && $last_invoiceid > 0) {
234
+			$last_invoiceid = ($last_invoiceid + 1);
235
+  		} else {
236
+			$last_invoiceid = $invoice_conf['invoice_start_from'];
237
+		}
238
+		$last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
239
+		$invoice_prefix = $invoice_conf['invoice_prefix'];
240
+		$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoice_conf['interval'] . " days"));
241 241
 
242
-            $invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date);
243
-            $this->db->set('balance', 'balance-' . $charge, FALSE);
244
-            $this->db->where('id', $AccountData["id"]);
245
-            $this->db->update("accounts");
246
-            $AccountData['balance'] = ($AccountData['balance'] - $charge);
247
-            $Bal = $AccountData['balance'];
248
-        } else {
249
-            $Bal = ($AccountData["credit_limit"] - $AccountData["balance"]);
250
-        }
251
-        if ($Bal <= 0) {
252
-            $this->db->set('status', "1", FALSE);
253
-            $this->db->where('id', $AccountData["id"]);
254
-            $this->db->update("accounts");
255
-        }
256
-        $invoice_item_arr = array("accountid" => $AccountData["id"],
257
-            "reseller_id" => $AccountData["reseller_id"],
258
-            "description" => trim($description . "-" . $fromdate . " to " . $todate),
259
-            "item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid,
260
-            "created_date" => trim($invoicedate),
261
-            "item_type" => $type
262
-        );
263
-        $this->manage_invoice($invoice_item_arr);
264
-    }
242
+			$invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date);
243
+			$this->db->set('balance', 'balance-' . $charge, FALSE);
244
+			$this->db->where('id', $AccountData["id"]);
245
+			$this->db->update("accounts");
246
+			$AccountData['balance'] = ($AccountData['balance'] - $charge);
247
+			$Bal = $AccountData['balance'];
248
+		} else {
249
+			$Bal = ($AccountData["credit_limit"] - $AccountData["balance"]);
250
+		}
251
+		if ($Bal <= 0) {
252
+			$this->db->set('status', "1", FALSE);
253
+			$this->db->where('id', $AccountData["id"]);
254
+			$this->db->update("accounts");
255
+		}
256
+		$invoice_item_arr = array("accountid" => $AccountData["id"],
257
+			"reseller_id" => $AccountData["reseller_id"],
258
+			"description" => trim($description . "-" . $fromdate . " to " . $todate),
259
+			"item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid,
260
+			"created_date" => trim($invoicedate),
261
+			"item_type" => $type
262
+		);
263
+		$this->manage_invoice($invoice_item_arr);
264
+	}
265 265
     
266
-    function get_table_data($select, $table, $where) {
267
-        $query = $this->db_model->getSelect($select, $table, $where);
268
-        if ($query->num_rows > 0) {
269
-            $query_result = $query->result_array();
270
-            return $query_result;
271
-        } else {
272
-            return false;
273
-        }
274
-    }
266
+	function get_table_data($select, $table, $where) {
267
+		$query = $this->db_model->getSelect($select, $table, $where);
268
+		if ($query->num_rows > 0) {
269
+			$query_result = $query->result_array();
270
+			return $query_result;
271
+		} else {
272
+			return false;
273
+		}
274
+	}
275 275
 
276
-    function Manage_Invoice($invoice_item_arr) {
277
-       $this->db->insert("invoice_details", $invoice_item_arr);
278
-    }
276
+	function Manage_Invoice($invoice_item_arr) {
277
+	   $this->db->insert("invoice_details", $invoice_item_arr);
278
+	}
279 279
 
280 280
 }
281 281
 ?> 
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         
51 51
         // Check Charge is applied that is for first time or already calculated before
52 52
 
53
-        $where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='" . gmdate("Y-m-d H:i:s") . "')";
53
+        $where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='".gmdate("Y-m-d H:i:s")."')";
54 54
         $this->db->where('accountid', $accountinfo['id']);
55 55
         $this->db->where($where);
56 56
         $this->db->select('*');
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
             foreach ($accountchargs as $accharges) {
62 62
                 //Get information from database of active charges.
63 63
                 $charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0"));
64
-                if ($charge_data && !empty($charge_data)) {
64
+                if ($charge_data && ! empty($charge_data)) {
65 65
                     $charge_data = $charge_data[0];
66 66
                     //Get Start Date of Charge
67 67
                     $charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ?
68
-                            date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) :$accharges["assign_date"];
69
-                   if($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day']< gmdate("d",strtotime($accharges['assign_date'])))) {
70
-                      $charge_upto=   date("Y-m-" . $accountinfo['invoice_day'] . " H:i:s", strtotime($accharges["assign_date"]));
68
+                            date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) : $accharges["assign_date"];
69
+                   if ($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day'] < gmdate("d", strtotime($accharges['assign_date'])))) {
70
+                      $charge_upto = date("Y-m-".$accountinfo['invoice_day']." H:i:s", strtotime($accharges["assign_date"]));
71 71
                    }
72 72
                     //Overwrite Billing scehdule of customer assign proper charge
73 73
                     if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                                 $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
135 135
                                 if ($lastdate)
136 136
                                     $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
137
-                            }else {
137
+                            } else {
138 138
                                 //Apply charges to Resellers.
139 139
                                 $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
140 140
                                 if ($lastdate)
@@ -156,39 +156,39 @@  discard block
 block discarded – undo
156 156
     function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") {
157 157
         $lastdate = false;
158 158
         $billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month";
159
-        $last_invoice_date = $this->common->get_invoice_date("invoice_date",$AccountDATA['id'],$AccountDATA['reseller_id']);
159
+        $last_invoice_date = $this->common->get_invoice_date("invoice_date", $AccountDATA['id'], $AccountDATA['reseller_id']);
160 160
       //Below variable gives date based on assign or creation or monthly user billing day
161
-        $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day']< gmdate("d",strtotime($itemArr['assign_date'])))) ? date("Y-m-" . $AccountDATA['invoice_day'] . " 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation']))));
161
+        $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day'] < gmdate("d", strtotime($itemArr['assign_date'])))) ? date("Y-m-".$AccountDATA['invoice_day']." 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation']))));
162 162
         $last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate;
163 163
         $Charges_date_range = array();
164
-        $prorate_array =array();
164
+        $prorate_array = array();
165 165
         $daylen = 60 * 60 * 24;
166 166
         /*Get assign day and billing day for postpaid monthly user.
167 167
          */
168
-        $assign_day=($AccountDATA['original_sweep_id']==2 && $AccountDATA['posttoexternal']==1) ? gmdate("d",strtotime($itemArr['assign_date'])):0;
169
-        $billing_day=($AccountDATA['original_sweep_id']==2 && $AccountDATA['posttoexternal']==1) ? $AccountDATA['invoice_day']:0;
168
+        $assign_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? gmdate("d", strtotime($itemArr['assign_date'])) : 0;
169
+        $billing_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? $AccountDATA['invoice_day'] : 0;
170 170
         //Create an array if charge not applied yet and invoice day is greater than assign_day
171
-        if($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate==0 && $itemArr['cycle']==2 && $AccountDATA['original_sweep_id']==2){
172
-	  $last_invoice_date = gmdate("Y-m-d H:i:s",strtotime("-1 second",strtotime(date("Y-m-" . $AccountDATA['invoice_day'] . " 00:00:00", strtotime($itemArr["assign_date"])))));
173
-	  $prorate_array[] = array("start_date" => date("Y-m-d H:i:s",strtotime($itemArr['assign_date'])), "end_date" => $last_invoice_date);
171
+        if ($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2) {
172
+	  $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("-1 second", strtotime(date("Y-m-".$AccountDATA['invoice_day']." 00:00:00", strtotime($itemArr["assign_date"])))));
173
+	  $prorate_array[] = array("start_date" => date("Y-m-d H:i:s", strtotime($itemArr['assign_date'])), "end_date" => $last_invoice_date);
174 174
 	  
175 175
         }
176 176
         while (strtotime($last_invoice_date) <= strtotime($todate)) {
177
-            $startdate=$last_invoice_date;
178
-            $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+" . $billing_cycle, strtotime($last_invoice_date)));
179
-            $Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s",strtotime("+1 Second",strtotime($startdate))), "end_date" => $last_invoice_date);
177
+            $startdate = $last_invoice_date;
178
+            $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+".$billing_cycle, strtotime($last_invoice_date)));
179
+            $Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($startdate))), "end_date" => $last_invoice_date);
180 180
         }
181
-        if(!empty($prorate_array)){
181
+        if ( ! empty($prorate_array)) {
182 182
          array_pop($Charges_date_range);
183
-         $Charges_date_range=array_merge($prorate_array,$Charges_date_range);
183
+         $Charges_date_range = array_merge($prorate_array, $Charges_date_range);
184 184
         }
185
-        if (!empty($Charges_date_range)) {
185
+        if ( ! empty($Charges_date_range)) {
186 186
             foreach ($Charges_date_range as $ChargeVal) {
187
-                if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate==0 && $itemArr['cycle']==2 && $AccountDATA['original_sweep_id']==2)) {
187
+                if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2)) {
188 188
                     $ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date'])));
189 189
                 }
190
-                if (!empty($itemArr['charge_upto']) && empty($lastdate)) {
191
-                    $start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2 ) ? $itemArr['assign_date'] : $ChargeVal['start_date'];
190
+                if ( ! empty($itemArr['charge_upto']) && empty($lastdate)) {
191
+                    $start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2) ? $itemArr['assign_date'] : $ChargeVal['start_date'];
192 192
                 } else {
193 193
                     $start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)));
194 194
                 }
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
         $Bal = "0.00"; 
223 223
         if ($AccountData["posttoexternal"] == 0) {
224 224
 	    $reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0;
225
-	    $where = "accountid IN ('" . $reseller_id . "','1')";
225
+	    $where = "accountid IN ('".$reseller_id."','1')";
226 226
 	    $this->db->where($where);
227 227
 	    $this->db->select('*');
228 228
 	    $this->db->order_by('accountid', 'desc');
229 229
 	    $this->db->limit(1);
230 230
 	    $invoiceconf = $this->db->get('invoice_conf');
231
-	    $invoice_conf = (array) $invoiceconf->first_row();
231
+	    $invoice_conf = (array)$invoiceconf->first_row();
232 232
 	    $last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']);
233 233
 	    if ($last_invoiceid && $last_invoiceid > 0) {
234 234
 	    	$last_invoiceid = ($last_invoiceid + 1);
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	    }
238 238
 	    $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
239 239
 	    $invoice_prefix = $invoice_conf['invoice_prefix'];
240
-	    $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoice_conf['interval'] . " days"));
240
+	    $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days"));
241 241
 
242 242
             $invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date);
243
-            $this->db->set('balance', 'balance-' . $charge, FALSE);
243
+            $this->db->set('balance', 'balance-'.$charge, FALSE);
244 244
             $this->db->where('id', $AccountData["id"]);
245 245
             $this->db->update("accounts");
246 246
             $AccountData['balance'] = ($AccountData['balance'] - $charge);
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         }
256 256
         $invoice_item_arr = array("accountid" => $AccountData["id"],
257 257
             "reseller_id" => $AccountData["reseller_id"],
258
-            "description" => trim($description . "-" . $fromdate . " to " . $todate),
258
+            "description" => trim($description."-".$fromdate." to ".$todate),
259 259
             "item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid,
260 260
             "created_date" => trim($invoicedate),
261 261
             "item_type" => $type
Please login to merge, or discard this patch.
Braces   +18 added lines, -13 removed lines patch added patch discarded remove patch
@@ -92,8 +92,9 @@  discard block
 block discarded – undo
92 92
                             "charge_upto"=>$accharges['charge_upto']);
93 93
 			//Add a new arguement ($accharges) which have all information of charges.
94 94
                         $lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]);
95
-                        if ($lastdate)
96
-                       $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"]));
95
+                        if ($lastdate) {
96
+                                               $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"]));
97
+                        }
97 98
                     }
98 99
                 }
99 100
             }
@@ -132,22 +133,25 @@  discard block
 block discarded – undo
132 133
                             if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) {
133 134
                                 //Apply charges to resellers customers.
134 135
                                 $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
135
-                                if ($lastdate)
136
-                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
137
-                            }else {
136
+                                if ($lastdate) {
137
+                                                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
138
+                                }
139
+                            } else {
138 140
                                 //Apply charges to Resellers.
139 141
                                 $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
140
-                                if ($lastdate)
141
-                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
142
+                                if ($lastdate) {
143
+                                                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
144
+                                }
142 145
                             }
143 146
                             $parent_id = $reseller_dids['parent_id'];
144 147
                         }
145 148
                     }
146 149
 //   		else{
147 150
                     $lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1");
148
-                    if ($lastdate)
149
-                      $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"]));
150
-//            	}
151
+                    if ($lastdate) {
152
+                                          $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"]));
153
+                    }
154
+                    //            	}
151 155
                 }
152 156
             }
153 157
         }
@@ -209,9 +213,10 @@  discard block
 block discarded – undo
209 213
                     $temp_charge = ($chrg_per_day * $days_diff);
210 214
                 }
211 215
                 
212
-                if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date']))
213
-                    $this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate);
214
-//                echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>";
216
+                if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date'])) {
217
+                                    $this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate);
218
+                }
219
+                //                echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>";
215 220
             }
216 221
         }
217 222
         return $lastdate;
Please login to merge, or discard this patch.
web_interface/astpp/application/libraries/astpp/common.php 4 patches
Doc Comments   +39 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,8 +44,6 @@  discard block
 block discarded – undo
44 44
 // __construct
45 45
     /**
46 46
      * adds raw html to the field array
47
-     * @param type $label
48
-     * @param type $field add
49 47
      */
50 48
     function generate_password() {
51 49
         $pass = substr(md5(rand(0, 1000000000)), 0, common_model::$global_config['system_config']['pinlength']);
@@ -93,6 +91,9 @@  discard block
 block discarded – undo
93 91
         return $uname;
94 92
     }
95 93
 
94
+    /**
95
+     * @param string $length
96
+     */
96 97
     function random_string($length) {
97 98
         $chars = "1234567890"; //length:36
98 99
         $final_rand = '';
@@ -132,6 +133,10 @@  discard block
 block discarded – undo
132 133
         return $number;
133 134
     }
134 135
 
136
+    /**
137
+     * @param string $select
138
+     * @param string $table
139
+     */
135 140
     function get_field_count($select, $table, $where) {
136 141
 //        echo $select."=====".$table."===".$where;
137 142
         if (is_array($where)) {
@@ -147,6 +152,10 @@  discard block
 block discarded – undo
147 152
         }
148 153
     }
149 154
 
155
+    /**
156
+     * @param string $select
157
+     * @param string $table
158
+     */
150 159
     function get_field_name($select, $table, $where) {
151 160
         if (is_array($where)) {
152 161
             $where = $where;
@@ -162,6 +171,10 @@  discard block
 block discarded – undo
162 171
         }
163 172
     }
164 173
 
174
+    /**
175
+     * @param string $select
176
+     * @param string $table
177
+     */
165 178
     function get_field_name_coma_new($select, $table, $where) {
166 179
         $value = '';
167 180
         if (is_array($where)) {
@@ -504,6 +517,9 @@  discard block
 block discarded – undo
504 517
     }
505 518
    
506 519
 
520
+    /**
521
+     * @param string $select
522
+     */
507 523
     function get_invoice_date($select, $accountid = 0, $reseller_id, $order_by = 'id') {
508 524
         $where = array("reseller_id" => $reseller_id);
509 525
         if ($accountid > 0) {
@@ -1175,6 +1191,9 @@  discard block
 block discarded – undo
1175 1191
 
1176 1192
     }
1177 1193
 
1194
+    /**
1195
+     * @param string $message
1196
+     */
1178 1197
     function emailFunction($from, $to, $subject, $message, $company_name = "", $attachment = "", $account_id, $reseller_id) {
1179 1198
         $send_mail_details = array('from' => $from,
1180 1199
             'to' => $to,
@@ -1373,12 +1392,18 @@  discard block
 block discarded – undo
1373 1392
       Password encode decode
1374 1393
      * ******* */
1375 1394
 
1395
+    /**
1396
+     * @param string $string
1397
+     */
1376 1398
     function encode_params($string) {
1377 1399
         $data = base64_encode($string);
1378 1400
         $data = str_replace(array('+', '/', '='), array('-', '$', ''), $data);
1379 1401
         return $data;
1380 1402
     }
1381 1403
 
1404
+    /**
1405
+     * @param string $value
1406
+     */
1382 1407
     function encode($value) {
1383 1408
         $text = $value;
1384 1409
         $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
@@ -1830,14 +1855,26 @@  discard block
 block discarded – undo
1830 1855
         }
1831 1856
     }
1832 1857
     
1858
+    /**
1859
+     * @param string $table_name
1860
+     */
1833 1861
     function delete_data($table_name,$where_arr){
1834 1862
         $this->CI->db->where($where_arr);
1835 1863
         $this->CI->db->delete($table_name);
1836 1864
     }
1865
+
1866
+    /**
1867
+     * @param string $table_name
1868
+     */
1837 1869
     function update_data($table_name,$where_arr,$update_arr){
1838 1870
         $this->CI->db->where($where_arr);
1839 1871
         $this->CI->db->update($table_name,$update_arr);
1840 1872
     }
1873
+
1874
+    /**
1875
+     * @param string $table_name
1876
+     * @param string $select
1877
+     */
1841 1878
     function select_data($table_name,$where_arr,$select){
1842 1879
         $this->CI->db->where($where_arr);
1843 1880
         $this->CI->db->select($select);
Please login to merge, or discard this patch.
Indentation   +1773 added lines, -1773 removed lines patch added patch discarded remove patch
@@ -23,453 +23,453 @@  discard block
 block discarded – undo
23 23
 ###############################################################################
24 24
 
25 25
 if (!defined('BASEPATH'))
26
-    exit('No direct script access allowed');
26
+	exit('No direct script access allowed');
27 27
 
28 28
 /**
29 29
  * Dynamically build forms for display
30 30
  */
31 31
 class common {
32 32
 
33
-    protected $CI; // codeigniter
33
+	protected $CI; // codeigniter
34 34
 
35
-    function __construct($library_name = '') {
35
+	function __construct($library_name = '') {
36 36
 
37
-        $this->CI = & get_instance();
38
-        $this->CI->load->library("timezone");
39
-        $this->CI->load->model('db_model');
40
-        $this->CI->load->library('email');
41
-        $this->CI->load->library('session');
42
-    }
37
+		$this->CI = & get_instance();
38
+		$this->CI->load->library("timezone");
39
+		$this->CI->load->model('db_model');
40
+		$this->CI->load->library('email');
41
+		$this->CI->load->library('session');
42
+	}
43 43
 
44 44
 // __construct
45
-    /**
46
-     * adds raw html to the field array
47
-     * @param type $label
48
-     * @param type $field add
49
-     */
50
-    function generate_password() {
51
-        $pass = substr(md5(rand(0, 1000000000)), 0, common_model::$global_config['system_config']['pinlength']);
52
-        return $pass;
53
-    }
54
-
55
-    function find_uniq_rendno($size = '', $field = '', $tablename = '') {
56
-
57
-        if ($tablename != '') {
58
-            $accounttype_array = array();
59
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
60
-            $where = array($field => $uname);
61
-            $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
62
-            $acc_result = $acc_result->result();
63
-            while ($acc_result[0]->count != 0) {
64
-                $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
65
-                $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
66
-            }
67
-        } else {
68
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
69
-        }
70
-        return $uname;
71
-    }
72
-
73
-    function find_uniq_rendno_customer($size = '', $field = '', $tablename = '') {
74
-        if ($tablename != '') {
75
-            $accounttype_array = array();
76
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
77
-            $where = array($field => $uname);
78
-            $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
79
-            $acc_result = $acc_result->result();
80
-            while ($acc_result[0]->count != 0) {
81
-                $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
82
-                $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
83
-            }
84
-        } else {
85
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
86
-        }
87
-        $start_prifix_value = common_model::$global_config['system_config']['startingdigit'];
88
-        if ($tablename == 'accounts' && $start_prifix_value != 0) {
89
-            $length = strlen($start_prifix_value);
90
-            $uname = substr($uname, $length);
91
-            $uname = $start_prifix_value . $uname;
92
-        }
93
-        return $uname;
94
-    }
95
-
96
-    function random_string($length) {
97
-        $chars = "1234567890"; //length:36
98
-        $final_rand = '';
99
-        for ($i = 0; $i < $length; $i++) {
100
-            $final_rand .= $chars[rand(0, strlen($chars) - 1)];
101
-        }
102
-        return $final_rand;
103
-    }
104
-
105
-    function find_uniq_rendno_accno($length = '', $field = '', $tablename = '', $default, $creation_count) {
106
-        $number = array();
107
-        $j = 0;
108
-
109
-        $total_count = pow(10, $length);
110
-        for ($i = 1; $i <= $total_count; $i++) {
111
-
112
-            $flag = false;
113
-            $uname = $this->random_string($length);
114
-            $uname = strtolower($uname);
115
-            if (isset($default))
116
-                $uname = $default . $uname;
117
-            if (!in_array($uname, $number)) {
118
-                $where = array($field => $uname);
119
-                $acc_result = $this->CI->db_model->getSelect('Count(id) as count', $tablename, $where);
120
-                $acc_result = $acc_result->result_array();
121
-                if ($acc_result[0]['count'] == 0 && !in_array($uname, $number)) {
122
-                    $number[] = $uname;
123
-                    $j++;
124
-                }
125
-                if ($j == $creation_count) {
126
-                    break;
127
-                }
128
-            } else {
129
-                $total_count++;
130
-            }
131
-        }
132
-        return $number;
133
-    }
134
-
135
-    function get_field_count($select, $table, $where) {
45
+	/**
46
+	 * adds raw html to the field array
47
+	 * @param type $label
48
+	 * @param type $field add
49
+	 */
50
+	function generate_password() {
51
+		$pass = substr(md5(rand(0, 1000000000)), 0, common_model::$global_config['system_config']['pinlength']);
52
+		return $pass;
53
+	}
54
+
55
+	function find_uniq_rendno($size = '', $field = '', $tablename = '') {
56
+
57
+		if ($tablename != '') {
58
+			$accounttype_array = array();
59
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
60
+			$where = array($field => $uname);
61
+			$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
62
+			$acc_result = $acc_result->result();
63
+			while ($acc_result[0]->count != 0) {
64
+				$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
65
+				$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
66
+			}
67
+		} else {
68
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
69
+		}
70
+		return $uname;
71
+	}
72
+
73
+	function find_uniq_rendno_customer($size = '', $field = '', $tablename = '') {
74
+		if ($tablename != '') {
75
+			$accounttype_array = array();
76
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
77
+			$where = array($field => $uname);
78
+			$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
79
+			$acc_result = $acc_result->result();
80
+			while ($acc_result[0]->count != 0) {
81
+				$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
82
+				$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
83
+			}
84
+		} else {
85
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
86
+		}
87
+		$start_prifix_value = common_model::$global_config['system_config']['startingdigit'];
88
+		if ($tablename == 'accounts' && $start_prifix_value != 0) {
89
+			$length = strlen($start_prifix_value);
90
+			$uname = substr($uname, $length);
91
+			$uname = $start_prifix_value . $uname;
92
+		}
93
+		return $uname;
94
+	}
95
+
96
+	function random_string($length) {
97
+		$chars = "1234567890"; //length:36
98
+		$final_rand = '';
99
+		for ($i = 0; $i < $length; $i++) {
100
+			$final_rand .= $chars[rand(0, strlen($chars) - 1)];
101
+		}
102
+		return $final_rand;
103
+	}
104
+
105
+	function find_uniq_rendno_accno($length = '', $field = '', $tablename = '', $default, $creation_count) {
106
+		$number = array();
107
+		$j = 0;
108
+
109
+		$total_count = pow(10, $length);
110
+		for ($i = 1; $i <= $total_count; $i++) {
111
+
112
+			$flag = false;
113
+			$uname = $this->random_string($length);
114
+			$uname = strtolower($uname);
115
+			if (isset($default))
116
+				$uname = $default . $uname;
117
+			if (!in_array($uname, $number)) {
118
+				$where = array($field => $uname);
119
+				$acc_result = $this->CI->db_model->getSelect('Count(id) as count', $tablename, $where);
120
+				$acc_result = $acc_result->result_array();
121
+				if ($acc_result[0]['count'] == 0 && !in_array($uname, $number)) {
122
+					$number[] = $uname;
123
+					$j++;
124
+				}
125
+				if ($j == $creation_count) {
126
+					break;
127
+				}
128
+			} else {
129
+				$total_count++;
130
+			}
131
+		}
132
+		return $number;
133
+	}
134
+
135
+	function get_field_count($select, $table, $where) {
136 136
 //        echo $select."=====".$table."===".$where;
137
-        if (is_array($where)) {
138
-            $where = $where;
139
-        } else {
140
-            $where = array($select => $where);
141
-        }
142
-        $field_name = $this->CI->db_model->countQuery($select, $table, $where);
143
-        if (isset($field_name) && !empty($field_name)) {
144
-            return $field_name;
145
-        } else {
146
-            return "0";
147
-        }
148
-    }
149
-
150
-    function get_field_name($select, $table, $where) {
151
-        if (is_array($where)) {
152
-            $where = $where;
153
-        } else {
154
-            $where = array("id" => $where);
155
-        }
156
-        $field_name = $this->CI->db_model->getSelect($select, $table, $where);
157
-        $field_name = $field_name->result();
158
-        if (isset($field_name) && !empty($field_name)) {
159
-            return $field_name[0]->$select;
160
-        } else {
161
-            return "";
162
-        }
163
-    }
164
-
165
-    function get_field_name_coma_new($select, $table, $where) {
166
-        $value = '';
167
-        if (is_array($where)) {
168
-            $where = $where;
169
-        } else {
170
-            $where = explode(',', $where);
171
-        }
172
-        $select1 = explode(',', $select);
173
-        for ($i = 0; $i < count($where); $i++) {
174
-            $where_in = array("id" => $where[$i]);
175
-
176
-            $field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
177
-            $field_name = $field_name->result();
178
-            if (isset($field_name) && !empty($field_name)) {
179
-                foreach ($select1 as $sel) {
180
-                    if ($sel == 'number') {
181
-                        $value.="(" . $field_name[0]->$sel . ")";
182
-                    } else {
183
-                        $value.= $field_name[0]->$sel . " ";
184
-                    }
185
-                }
186
-            } else {
187
-                $value = "";
188
-            }
189
-        }
190
-        return rtrim($value, ',');
191
-    }
192
-
193
-    function check_did_avl($select, $table, $where) {
194
-        $accountinfo = $this->CI->session->userdata('accountinfo');
195
-        $flag_status = "";
196
-        $where = array("number" => $where);
197
-        $field_name = $this->CI->db_model->getSelect("id,accountid,parent_id", 'dids', $where);
198
-        $field_name = $field_name->result();
199
-        if (isset($field_name) && !empty($field_name)) {
200
-            if (isset($field_name[0]) && $accountinfo['type'] != 1) {
201
-                if ($field_name[0]->accountid != 0 && $field_name[0]->parent_id ==0) {
202
-                    $flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
203
-                } else if ($field_name[0]->parent_id != 0) {
204
-                    $flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
205
-                } else {
206
-                    $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
207
-                }
208
-            } else {
209
-                $reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
210
-                $where = array("note" => $field_name[0]->number, 'parent_id' => $reseller_id);
211
-                $field_name_re = $this->CI->db_model->getSelect("reseller_id", 'reseller_pricing', $where);
212
-                $field_name_re = $field_name_re->result();
213
-
214
-                if (isset($field_name_re) && !empty($field_name_re)) {
215
-                    $flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
216
-                } else {
217
-                    $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
218
-                }
219
-            }
220
-        } else {
221
-            $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
222
-        }
223
-        return $flag_status;
224
-    }
225
-    function check_did_avl_export($number){
226
-      $this->CI->db->where('number',$number);
227
-      $this->CI->db->select('id,accountid,parent_id');
228
-      $status=null;
229
-      $did_info=(array)$this->CI->db->get('dids')->first_row();
230
-      $accountinfo=$this->CI->session->userdata('accountinfo');
231
-      if($did_info['accountid'] ==0 && $did_info['parent_id']==0){
137
+		if (is_array($where)) {
138
+			$where = $where;
139
+		} else {
140
+			$where = array($select => $where);
141
+		}
142
+		$field_name = $this->CI->db_model->countQuery($select, $table, $where);
143
+		if (isset($field_name) && !empty($field_name)) {
144
+			return $field_name;
145
+		} else {
146
+			return "0";
147
+		}
148
+	}
149
+
150
+	function get_field_name($select, $table, $where) {
151
+		if (is_array($where)) {
152
+			$where = $where;
153
+		} else {
154
+			$where = array("id" => $where);
155
+		}
156
+		$field_name = $this->CI->db_model->getSelect($select, $table, $where);
157
+		$field_name = $field_name->result();
158
+		if (isset($field_name) && !empty($field_name)) {
159
+			return $field_name[0]->$select;
160
+		} else {
161
+			return "";
162
+		}
163
+	}
164
+
165
+	function get_field_name_coma_new($select, $table, $where) {
166
+		$value = '';
167
+		if (is_array($where)) {
168
+			$where = $where;
169
+		} else {
170
+			$where = explode(',', $where);
171
+		}
172
+		$select1 = explode(',', $select);
173
+		for ($i = 0; $i < count($where); $i++) {
174
+			$where_in = array("id" => $where[$i]);
175
+
176
+			$field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
177
+			$field_name = $field_name->result();
178
+			if (isset($field_name) && !empty($field_name)) {
179
+				foreach ($select1 as $sel) {
180
+					if ($sel == 'number') {
181
+						$value.="(" . $field_name[0]->$sel . ")";
182
+					} else {
183
+						$value.= $field_name[0]->$sel . " ";
184
+					}
185
+				}
186
+			} else {
187
+				$value = "";
188
+			}
189
+		}
190
+		return rtrim($value, ',');
191
+	}
192
+
193
+	function check_did_avl($select, $table, $where) {
194
+		$accountinfo = $this->CI->session->userdata('accountinfo');
195
+		$flag_status = "";
196
+		$where = array("number" => $where);
197
+		$field_name = $this->CI->db_model->getSelect("id,accountid,parent_id", 'dids', $where);
198
+		$field_name = $field_name->result();
199
+		if (isset($field_name) && !empty($field_name)) {
200
+			if (isset($field_name[0]) && $accountinfo['type'] != 1) {
201
+				if ($field_name[0]->accountid != 0 && $field_name[0]->parent_id ==0) {
202
+					$flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
203
+				} else if ($field_name[0]->parent_id != 0) {
204
+					$flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
205
+				} else {
206
+					$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
207
+				}
208
+			} else {
209
+				$reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
210
+				$where = array("note" => $field_name[0]->number, 'parent_id' => $reseller_id);
211
+				$field_name_re = $this->CI->db_model->getSelect("reseller_id", 'reseller_pricing', $where);
212
+				$field_name_re = $field_name_re->result();
213
+
214
+				if (isset($field_name_re) && !empty($field_name_re)) {
215
+					$flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
216
+				} else {
217
+					$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
218
+				}
219
+			}
220
+		} else {
221
+			$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
222
+		}
223
+		return $flag_status;
224
+	}
225
+	function check_did_avl_export($number){
226
+	  $this->CI->db->where('number',$number);
227
+	  $this->CI->db->select('id,accountid,parent_id');
228
+	  $status=null;
229
+	  $did_info=(array)$this->CI->db->get('dids')->first_row();
230
+	  $accountinfo=$this->CI->session->userdata('accountinfo');
231
+	  if($did_info['accountid'] ==0 && $did_info['parent_id']==0){
232 232
 	$status='Not in use';
233
-      }
234
-      elseif($accountinfo['type'] !=1){
233
+	  }
234
+	  elseif($accountinfo['type'] !=1){
235 235
 	if($did_info['accountid'] ==0 && $did_info['parent_id'] > 0){
236 236
 	  $status='Purchase by Reseller';
237 237
 	}
238 238
 	if($did_info['accountid'] > 0 && $did_info['parent_id'] == 0){
239 239
 	  $status='Purchase by Customer';
240 240
 	}
241
-      }else{
242
-       $where_arr=array('note'=>$did_info['number'],"parent_id"=>$accountinfo['id']);
243
-       $this->db->where($where);
244
-       $this->CI->db->select('reseller_id,parent_id');
245
-       $reseller_pricing = (array)$this->db->get('reseller_pricing')->first_row();
246
-       if($reseller_pricing['reseller_id']==0 && $did_info['accountid']==0 && $did_info['parent_id']==$accountinfo['id']){
247
-        $status='Not in use';
248
-       }
249
-       if($reseller_pricing['reseller_id']==0 && $did_info['accountid']==0){
250
-       $status='Not in use';
251
-       }
252
-      }
253
-      return $status;
241
+	  }else{
242
+	   $where_arr=array('note'=>$did_info['number'],"parent_id"=>$accountinfo['id']);
243
+	   $this->db->where($where);
244
+	   $this->CI->db->select('reseller_id,parent_id');
245
+	   $reseller_pricing = (array)$this->db->get('reseller_pricing')->first_row();
246
+	   if($reseller_pricing['reseller_id']==0 && $did_info['accountid']==0 && $did_info['parent_id']==$accountinfo['id']){
247
+		$status='Not in use';
248
+	   }
249
+	   if($reseller_pricing['reseller_id']==0 && $did_info['accountid']==0){
250
+	   $status='Not in use';
251
+	   }
252
+	  }
253
+	  return $status;
254 254
       
255
-    }
256
-    function check_did_avl_reseller($select, $table, $where) {
257
-        $accountinfo = $this->CI->session->userdata('accountinfo');
258
-        $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
259
-        $this->CI->db->where('number',$where);
260
-        $this->CI->db->select('id,accountid,parent_id,number');
261
-        $did_info=(array)$this->CI->db->get('dids')->first_row();
262
-        if($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']){
263
-	    $flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
264
-	}
265
-        else if($accountinfo['type']!=1 && $did_info['parent_id'] != $accountinfo['id']){
266
-	    $flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
267
-        }else{
268
-	    $reseller_id= $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
269
-	    $where = array("note" => $did_info['number'],'parent_id'=>$reseller_id);
270
-            $this->CI->db->where($where);
271
-	    $this->CI->db->select('reseller_id,id');
272
-	    $reseller_pricing_info=(array)$this->CI->db->get('reseller_pricing')->first_row();
273
-	    if (isset($reseller_pricing_info) && !empty($reseller_pricing_info)) {
255
+	}
256
+	function check_did_avl_reseller($select, $table, $where) {
257
+		$accountinfo = $this->CI->session->userdata('accountinfo');
258
+		$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
259
+		$this->CI->db->where('number',$where);
260
+		$this->CI->db->select('id,accountid,parent_id,number');
261
+		$did_info=(array)$this->CI->db->get('dids')->first_row();
262
+		if($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']){
263
+		$flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
264
+	}
265
+		else if($accountinfo['type']!=1 && $did_info['parent_id'] != $accountinfo['id']){
266
+		$flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
267
+		}else{
268
+		$reseller_id= $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
269
+		$where = array("note" => $did_info['number'],'parent_id'=>$reseller_id);
270
+			$this->CI->db->where($where);
271
+		$this->CI->db->select('reseller_id,id');
272
+		$reseller_pricing_info=(array)$this->CI->db->get('reseller_pricing')->first_row();
273
+		if (isset($reseller_pricing_info) && !empty($reseller_pricing_info)) {
274 274
 		  $flag_status="<a href='../did/did_reseller_edit/delete/".$reseller_pricing_info['id']."' title='Reliase' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
275
-	    }else{
276
-	      $flag_status="<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
277
-	    }
278
-        }
279
-        return $flag_status;
280
-    }
275
+		}else{
276
+		  $flag_status="<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
277
+		}
278
+		}
279
+		return $flag_status;
280
+	}
281 281
 
282 282
 //    get data for Comma seprated
283
-    function get_field_name_coma($select, $table, $where) {
284
-        $value = '';
285
-        if (is_array($where)) {
286
-            $where = $where;
287
-        } else {
288
-            $where = explode(',', $where);
289
-        }
290
-        for ($i = 0; $i < count($where); $i++) {
291
-            $where_in = array("id" => $where[$i]);
292
-
293
-            $field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
294
-            $field_name = $field_name->result();
295
-            if (isset($field_name) && !empty($field_name)) {
296
-                $value.= $field_name[0]->$select . ",";
297
-            } else {
298
-                $value = "";
299
-            }
300
-        }
301
-        return rtrim($value, ',');
302
-    }
303
-
304
-    function set_invoice_option($select = "", $table = "", $call_type = "", $edit_value = '') {
305
-
306
-        $invoice_date = false;
307
-        $uri_segment = $this->CI->uri->segments;
308
-        if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
309
-            $field_name = $this->CI->db_model->getSelect("sweep_id,invoice_day", "accounts", array("id" => $uri_segment[3]));
310
-            $field_name = $field_name->result_array();
311
-            $select = $field_name[0]["sweep_id"];
312
-            $invoice_date = $field_name[0]["invoice_day"];
313
-        } else {
314
-            $invoice_date = $edit_value;
315
-        }
316
-        if ($select == "" || $select == "0") {
317
-            $daily_arr = array("0" => "0");
318
-            return $daily_arr;
319
-        }
320
-        if ($select == 1) {
321
-            $week_arr = array("1" => "Monday", "2" => "Tuesday", "3" => "Wednesday", "4" => "Thursday", "5" => "Friday",
322
-                "6" => "Saturday", "7" => "Sunday");
323
-            $rawDate = date("Y-m-d");
324
-            $day = date('N', strtotime($rawDate));
325
-            if (isset($uri_segment[3])) {
326
-                return $week_arr;
327
-            } else {
328
-                $week_drp = form_dropdown(array("name" => 'invoice_day','style'=>"width: 100% !important;" , "class" => "invoice_day"), $week_arr, $day);
329
-                return $week_drp;
330
-            }
331
-        }
332
-        if ($select != 0 && $select != 1) {
333
-            for ($i = 1; $i < 29; $i++) {
334
-                $mon_arr[$i] = $i;
335
-            }
336
-            if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
337
-                return $mon_arr;
338
-            } else {
339
-                $day = $invoice_date > 0 ? $invoice_date : date('d');
340
-                $month_drp = form_dropdown(array("name" => 'invoice_day',"class" => "width_dropdown invoice_day"), $mon_arr, $day);
341
-                return $month_drp;
342
-            }
343
-        }
344
-    }
345
-
346
-    function set_status($status = '') {
347
-        $status_array = array('0' => 'Active', '1' => 'Inactive',);
348
-        return $status_array;
349
-    }
350
-
351
-    function set_routetype($status = '') {
352
-        $status_array = array( '0' => 'LCR','1' => 'COST',);
353
-        return $status_array;
354
-    }
355
-
356
-    function set_prorate($status = '') {
357
-        $status_array = array('0' => 'Yes', '1' => 'No',);
358
-        return $status_array;
359
-    }
360
-    /*
283
+	function get_field_name_coma($select, $table, $where) {
284
+		$value = '';
285
+		if (is_array($where)) {
286
+			$where = $where;
287
+		} else {
288
+			$where = explode(',', $where);
289
+		}
290
+		for ($i = 0; $i < count($where); $i++) {
291
+			$where_in = array("id" => $where[$i]);
292
+
293
+			$field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
294
+			$field_name = $field_name->result();
295
+			if (isset($field_name) && !empty($field_name)) {
296
+				$value.= $field_name[0]->$select . ",";
297
+			} else {
298
+				$value = "";
299
+			}
300
+		}
301
+		return rtrim($value, ',');
302
+	}
303
+
304
+	function set_invoice_option($select = "", $table = "", $call_type = "", $edit_value = '') {
305
+
306
+		$invoice_date = false;
307
+		$uri_segment = $this->CI->uri->segments;
308
+		if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
309
+			$field_name = $this->CI->db_model->getSelect("sweep_id,invoice_day", "accounts", array("id" => $uri_segment[3]));
310
+			$field_name = $field_name->result_array();
311
+			$select = $field_name[0]["sweep_id"];
312
+			$invoice_date = $field_name[0]["invoice_day"];
313
+		} else {
314
+			$invoice_date = $edit_value;
315
+		}
316
+		if ($select == "" || $select == "0") {
317
+			$daily_arr = array("0" => "0");
318
+			return $daily_arr;
319
+		}
320
+		if ($select == 1) {
321
+			$week_arr = array("1" => "Monday", "2" => "Tuesday", "3" => "Wednesday", "4" => "Thursday", "5" => "Friday",
322
+				"6" => "Saturday", "7" => "Sunday");
323
+			$rawDate = date("Y-m-d");
324
+			$day = date('N', strtotime($rawDate));
325
+			if (isset($uri_segment[3])) {
326
+				return $week_arr;
327
+			} else {
328
+				$week_drp = form_dropdown(array("name" => 'invoice_day','style'=>"width: 100% !important;" , "class" => "invoice_day"), $week_arr, $day);
329
+				return $week_drp;
330
+			}
331
+		}
332
+		if ($select != 0 && $select != 1) {
333
+			for ($i = 1; $i < 29; $i++) {
334
+				$mon_arr[$i] = $i;
335
+			}
336
+			if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
337
+				return $mon_arr;
338
+			} else {
339
+				$day = $invoice_date > 0 ? $invoice_date : date('d');
340
+				$month_drp = form_dropdown(array("name" => 'invoice_day',"class" => "width_dropdown invoice_day"), $mon_arr, $day);
341
+				return $month_drp;
342
+			}
343
+		}
344
+	}
345
+
346
+	function set_status($status = '') {
347
+		$status_array = array('0' => 'Active', '1' => 'Inactive',);
348
+		return $status_array;
349
+	}
350
+
351
+	function set_routetype($status = '') {
352
+		$status_array = array( '0' => 'LCR','1' => 'COST',);
353
+		return $status_array;
354
+	}
355
+
356
+	function set_prorate($status = '') {
357
+		$status_array = array('0' => 'Yes', '1' => 'No',);
358
+		return $status_array;
359
+	}
360
+	/*
361 361
       Add For Package Inbound or Outbound or both?
362 362
     */
363
-    function set_package_type($applicable_for = "") {
364
-        $package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
365
-        return $package_applicable;
366
-    }
367
-
368
-    function get_package_type($status = '', $table = "", $applicable_for) {
369
-        $package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
370
-        return $package_applicable[$applicable_for];
371
-    }
372
-    /******************************************** */
373
-    function set_allow($status = '') {
374
-        $status_array = array('1' => 'Yes', '0' => 'No');
375
-        return $status_array;
376
-    }
377
-    function set_allow_invoice($status = '') {
378
-        $status_array = array('1' => 'Yes', '0' => 'No');
379
-        return $status_array;
380
-    }
381
-    function set_pin_allow($status=''){
382
-        $status_array = array('0' => 'Disable','1' => 'Enable');
383
-        return $status_array;
384
-    }
385
-    function set_pin_allow_customer($status=''){
386
-        $status_array = array('0' => 'No','1' => 'Yes');
387
-        return $status_array;
388
-    }
389
-    function get_allow($select = "", $table = "", $status) {
390
-        return ($status == 1) ? "Yes" : "No";
391
-    }
392
-
393
-    function set_call_type($call_type = "") {
394
-        $call_type_array = array("-1" => "--Select--",'1' => 'DID-Local',"3"=>"SIP-DID", '0' => 'PSTN',  '2' => 'Other',);
395
-        return $call_type_array;
396
-    }
397
-    function set_call_type_search(){
363
+	function set_package_type($applicable_for = "") {
364
+		$package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
365
+		return $package_applicable;
366
+	}
367
+
368
+	function get_package_type($status = '', $table = "", $applicable_for) {
369
+		$package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
370
+		return $package_applicable[$applicable_for];
371
+	}
372
+	/******************************************** */
373
+	function set_allow($status = '') {
374
+		$status_array = array('1' => 'Yes', '0' => 'No');
375
+		return $status_array;
376
+	}
377
+	function set_allow_invoice($status = '') {
378
+		$status_array = array('1' => 'Yes', '0' => 'No');
379
+		return $status_array;
380
+	}
381
+	function set_pin_allow($status=''){
382
+		$status_array = array('0' => 'Disable','1' => 'Enable');
383
+		return $status_array;
384
+	}
385
+	function set_pin_allow_customer($status=''){
386
+		$status_array = array('0' => 'No','1' => 'Yes');
387
+		return $status_array;
388
+	}
389
+	function get_allow($select = "", $table = "", $status) {
390
+		return ($status == 1) ? "Yes" : "No";
391
+	}
392
+
393
+	function set_call_type($call_type = "") {
394
+		$call_type_array = array("-1" => "--Select--",'1' => 'DID-Local',"3"=>"SIP-DID", '0' => 'PSTN',  '2' => 'Other',);
395
+		return $call_type_array;
396
+	}
397
+	function set_call_type_search(){
398 398
 	$call_type_array = array("" => "--Select--",'1' => 'DID-Local',"3"=>"SIP-DID", '0' => 'PSTN',  '2' => 'Other',);
399
-        return $call_type_array;
400
-    }
401
-    function get_call_type($select = "", $table = "", $call_type) {
402
-        $call_type_array = array('1' => 'DID-Local',"3"=>"SIP-DID",'0' => 'PSTN',  '2' => 'Other','-1'=>"");
403
-        return $call_type_array[$call_type];
404
-    }
405
-
406
-    function get_custom_call_type($call_type) {
407
-        $call_type_array = array('DID-Local' => '1',"SIP-DID"=>"3",'PSTN' => '0','Other' => '2',""=>"-1");
408
-        return $call_type_array[$call_type];
409
-    }
410
-
411
-    function set_sip_config_option($option = "") {
412
-        $config_option = array("true" => "True", "false" => "False");
413
-        return $config_option;
414
-    }
415
-
416
-    function get_entity_type($select = "", $table = "", $entity_type) {
417
-        $entity_array = array('-1' => "Administrator", '0' => 'Customer', '1' => 'Reseller', '2' => 'Admin', '3' => "Provider", "4" => "Subadmin", "5" => "Callshop");
418
-        return($entity_array[$entity_type]);
419
-    }
420
-
421
-    function set_entity_type_customer($entity_type = "") {
422
-        $entity_array = array('' => "--Select--", '0' => 'Customer', '3' => "Provider");
423
-        return $entity_array;
424
-    }
425
-
426
-    function set_entity_type_admin($entity_type = "") {
427
-        $entity_array = array('' => "--Select--", '2' => 'Admin', "4" => "Sub Admin");
428
-        return $entity_array;
429
-    }
399
+		return $call_type_array;
400
+	}
401
+	function get_call_type($select = "", $table = "", $call_type) {
402
+		$call_type_array = array('1' => 'DID-Local',"3"=>"SIP-DID",'0' => 'PSTN',  '2' => 'Other','-1'=>"");
403
+		return $call_type_array[$call_type];
404
+	}
405
+
406
+	function get_custom_call_type($call_type) {
407
+		$call_type_array = array('DID-Local' => '1',"SIP-DID"=>"3",'PSTN' => '0','Other' => '2',""=>"-1");
408
+		return $call_type_array[$call_type];
409
+	}
410
+
411
+	function set_sip_config_option($option = "") {
412
+		$config_option = array("true" => "True", "false" => "False");
413
+		return $config_option;
414
+	}
415
+
416
+	function get_entity_type($select = "", $table = "", $entity_type) {
417
+		$entity_array = array('-1' => "Administrator", '0' => 'Customer', '1' => 'Reseller', '2' => 'Admin', '3' => "Provider", "4" => "Subadmin", "5" => "Callshop");
418
+		return($entity_array[$entity_type]);
419
+	}
420
+
421
+	function set_entity_type_customer($entity_type = "") {
422
+		$entity_array = array('' => "--Select--", '0' => 'Customer', '3' => "Provider");
423
+		return $entity_array;
424
+	}
425
+
426
+	function set_entity_type_admin($entity_type = "") {
427
+		$entity_array = array('' => "--Select--", '2' => 'Admin', "4" => "Sub Admin");
428
+		return $entity_array;
429
+	}
430 430
 
431 431
 	function set_entity_type_email_mass($entity_type = "") {
432
-        $entity_array = array('' => "--Select--", '0' => 'Customer','1'=>'Reseller','3' => "Provider");
433
-        return $entity_array;
434
-    }
435
-
436
-    function set_sip_config_options($option = "") {
437
-        $config_option = array("false" => "False", "true" => "True");
438
-        return $config_option;
439
-    }
440
-
441
-    function set_sip_config_default($option = "") {
442
-        $config_option = array("" => "--SELECT--", "false" => "False", "true" => "True");
443
-        return $config_option;
444
-    }
445
-
446
-    function set_sip_bind_params($option = "") {
447
-        $config_option = array("" => "--SELECT--", "udp" => "UDP", "tcp" => "TCP");
448
-        return $config_option;
449
-    }
450
-
451
-    function set_sip_vad_option() {
452
-        $config_option = array("in" => "In", "out" => "Out", "both" => "Both");
453
-        return $config_option;
454
-    }
455
-
456
-    function set_sip_drp_option($option = "") {
457
-        $status_array = array('no' => 'No', 'yes' => 'Yes');
458
-        return $status_array;
459
-    }
460
-
461
-    function set_status_callingcard($status = '') {
462
-        $status_array = array('1' => 'Active', '0' => 'Inactive', '2' => 'Deleted');
463
-        return $status_array;
464
-    }
432
+		$entity_array = array('' => "--Select--", '0' => 'Customer','1'=>'Reseller','3' => "Provider");
433
+		return $entity_array;
434
+	}
435
+
436
+	function set_sip_config_options($option = "") {
437
+		$config_option = array("false" => "False", "true" => "True");
438
+		return $config_option;
439
+	}
440
+
441
+	function set_sip_config_default($option = "") {
442
+		$config_option = array("" => "--SELECT--", "false" => "False", "true" => "True");
443
+		return $config_option;
444
+	}
445
+
446
+	function set_sip_bind_params($option = "") {
447
+		$config_option = array("" => "--SELECT--", "udp" => "UDP", "tcp" => "TCP");
448
+		return $config_option;
449
+	}
450
+
451
+	function set_sip_vad_option() {
452
+		$config_option = array("in" => "In", "out" => "Out", "both" => "Both");
453
+		return $config_option;
454
+	}
455
+
456
+	function set_sip_drp_option($option = "") {
457
+		$status_array = array('no' => 'No', 'yes' => 'Yes');
458
+		return $status_array;
459
+	}
460
+
461
+	function set_status_callingcard($status = '') {
462
+		$status_array = array('1' => 'Active', '0' => 'Inactive', '2' => 'Deleted');
463
+		return $status_array;
464
+	}
465 465
    /*
466 466
    show status on all grid
467 467
    */
468 468
    function get_status($select = "", $table = "", $status) {
469
-       if($select !='export'){
470
-        $status_tab=$this->encode($table);
471
-        $status['table']="'".$status_tab."'";
472
-        if($status['status'] == 0){
469
+	   if($select !='export'){
470
+		$status_tab=$this->encode($table);
471
+		$status['table']="'".$status_tab."'";
472
+		if($status['status'] == 0){
473 473
 	$status_array = '<div style="width: 100%; text-align: -moz-center; padding: 0;"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id=switch'.$status['id'].' value='.$status['status'].' onclick="javascript:processForm('.$status['id'].','.$status['table'].')" checked>
474 474
 	<label class="onoffswitch-label" for=switch'.$status["id"].'>
475 475
      	<span class="onoffswitch-inner"></span>
@@ -484,246 +484,246 @@  discard block
 block discarded – undo
484 484
 		return ($status == 0) ? "Active" : "Inactive";
485 485
 	}
486 486
 	return $status_array;
487
-    }
487
+	}
488 488
    
489
-    function get_routetype($select = "", $table = "", $status) {
490
-        return ($status == 0) ? "LCR" : "COST";
491
-    }
489
+	function get_routetype($select = "", $table = "", $status) {
490
+		return ($status == 0) ? "LCR" : "COST";
491
+	}
492 492
    
493 493
    function get_prorate($select = "", $table = "", $status) {
494
-        return ($status == 0) ? "Yes" : "No";
495
-    }
494
+		return ($status == 0) ? "Yes" : "No";
495
+	}
496 496
     
497
-    function get_import_status($status){
498
-     return strtolower(trim($status)) == 'active' ? 0 : 1;
497
+	function get_import_status($status){
498
+	 return strtolower(trim($status)) == 'active' ? 0 : 1;
499 499
      
500
-    }
501
-    function get_did_status($select,$table,$status){
500
+	}
501
+	function get_did_status($select,$table,$status){
502 502
     
503
-      return ($status['status']==0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
504
-    }
503
+	  return ($status['status']==0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
504
+	}
505 505
    
506 506
 
507
-    function get_invoice_date($select, $accountid = 0, $reseller_id, $order_by = 'id') {
508
-        $where = array("reseller_id" => $reseller_id);
509
-        if ($accountid > 0) {
510
-            $where['accountid'] = $accountid;
511
-        }
512
-        $invoice_res = $this->CI->db_model->select($select, "invoices", $where, $order_by, "DESC", "1", "0");
513
-        if ($invoice_res->num_rows > 0) {
514
-            $invoice_info = (array) $invoice_res->first_row();
515
-            return $invoice_info[$select];
516
-        }
517
-        return false;
518
-    }
519
-
520
-    function convert_to_date($select = '', $table = '', $from_date) {
521
-
522
-        $from_date = date('Y-m-d', strtotime($from_date));
523
-        return $from_date;
524
-    }
525
-
526
-
527
-    function get_account_balance($select = "", $table = "", $amount) {
528
-        $this->CI->load->model('common_model');
529
-        if ($amount == 0) {
530
-            return $amount;
531
-        } else {
532
-            $balance = $this->CI->common_model->add_calculate_currency(($amount), "", '', true, true);
533
-
534
-            return $balance;
535
-        }
536
-    }
537
-
538
-    function convert_to_currency($select = "", $table = "", $amount) {
539
-        $this->CI->load->model('common_model');
540
-        return $this->CI->common_model->calculate_currency($amount,'','',true,false);
541
-    }
542
-    function account_number_icon($select = "", $table = "", $number){
543
-    $return_value='';
544
-    $where=array('number'=>$number);
545
-    $account_res = (array)$this->CI->db->get_where("accounts",$where)->first_row();
546
-    if($account_res['type'] == 0){
547
-    $return_value= '<div class="flx_font flx_magenta" title="Customer">C</div>'." <span title='Edit'>". $account_res['number']." </span>";    
548
-    }
549
-    if($account_res['type']==3){
550
-    $return_value='<div class="flx_font flx_blue" title="Provider">P</div>'." <span title='Edit'>".$account_res['number']." </span>";
551
-    }
552
-    if($account_res['type']== -1 || $account_res['type']==2){
553
-      $return_value='<div class="flx_font flx_pink" title="Admin">A</div>'." <span title='Edit'>".$account_res['number']." </span>";
554
-    }
555
-    if($account_res['type']== 4){
556
-      $return_value='<div class="flx_font flx_purple" title="Subadmin">S</div>'." <span title='Edit'>".$account_res['number']." </span>";
557
-    }
558
-    return $return_value;
559
-    }
560
-    function convert_to_currency_account($select = "", $table = "", $amount) {
561
-        $this->CI->load->model('common_model');
562
-        return $this->CI->common_model->calculate_currency_customer($amount);
563
-    }
564
-
565
-    function get_paid_status($select = "", $table = "", $status) {
566
-        return ($status == 1) ? "Paid" : "Unpaid";
567
-    }
568
-
569
-    function set_account_type($status = '') {
570
-        $status_array = array('0' => 'Prepaid', '1' => 'Postpaid');
571
-        return $status_array;
572
-    }
573
-
574
-    function set_account_type_search($status = '') {
575
-        $status_array = array('' => "--Select--", '0' => 'Prepaid', '1' => 'Postpaid');
576
-        return $status_array;
577
-    }
578
-
579
-    function get_account_type($select = "", $table = "", $PTE) {
580
-        return ($PTE == 1) ? "Postpaid" : "Prepaid";
581
-    }
582
-
583
-    /******
507
+	function get_invoice_date($select, $accountid = 0, $reseller_id, $order_by = 'id') {
508
+		$where = array("reseller_id" => $reseller_id);
509
+		if ($accountid > 0) {
510
+			$where['accountid'] = $accountid;
511
+		}
512
+		$invoice_res = $this->CI->db_model->select($select, "invoices", $where, $order_by, "DESC", "1", "0");
513
+		if ($invoice_res->num_rows > 0) {
514
+			$invoice_info = (array) $invoice_res->first_row();
515
+			return $invoice_info[$select];
516
+		}
517
+		return false;
518
+	}
519
+
520
+	function convert_to_date($select = '', $table = '', $from_date) {
521
+
522
+		$from_date = date('Y-m-d', strtotime($from_date));
523
+		return $from_date;
524
+	}
525
+
526
+
527
+	function get_account_balance($select = "", $table = "", $amount) {
528
+		$this->CI->load->model('common_model');
529
+		if ($amount == 0) {
530
+			return $amount;
531
+		} else {
532
+			$balance = $this->CI->common_model->add_calculate_currency(($amount), "", '', true, true);
533
+
534
+			return $balance;
535
+		}
536
+	}
537
+
538
+	function convert_to_currency($select = "", $table = "", $amount) {
539
+		$this->CI->load->model('common_model');
540
+		return $this->CI->common_model->calculate_currency($amount,'','',true,false);
541
+	}
542
+	function account_number_icon($select = "", $table = "", $number){
543
+	$return_value='';
544
+	$where=array('number'=>$number);
545
+	$account_res = (array)$this->CI->db->get_where("accounts",$where)->first_row();
546
+	if($account_res['type'] == 0){
547
+	$return_value= '<div class="flx_font flx_magenta" title="Customer">C</div>'." <span title='Edit'>". $account_res['number']." </span>";    
548
+	}
549
+	if($account_res['type']==3){
550
+	$return_value='<div class="flx_font flx_blue" title="Provider">P</div>'." <span title='Edit'>".$account_res['number']." </span>";
551
+	}
552
+	if($account_res['type']== -1 || $account_res['type']==2){
553
+	  $return_value='<div class="flx_font flx_pink" title="Admin">A</div>'." <span title='Edit'>".$account_res['number']." </span>";
554
+	}
555
+	if($account_res['type']== 4){
556
+	  $return_value='<div class="flx_font flx_purple" title="Subadmin">S</div>'." <span title='Edit'>".$account_res['number']." </span>";
557
+	}
558
+	return $return_value;
559
+	}
560
+	function convert_to_currency_account($select = "", $table = "", $amount) {
561
+		$this->CI->load->model('common_model');
562
+		return $this->CI->common_model->calculate_currency_customer($amount);
563
+	}
564
+
565
+	function get_paid_status($select = "", $table = "", $status) {
566
+		return ($status == 1) ? "Paid" : "Unpaid";
567
+	}
568
+
569
+	function set_account_type($status = '') {
570
+		$status_array = array('0' => 'Prepaid', '1' => 'Postpaid');
571
+		return $status_array;
572
+	}
573
+
574
+	function set_account_type_search($status = '') {
575
+		$status_array = array('' => "--Select--", '0' => 'Prepaid', '1' => 'Postpaid');
576
+		return $status_array;
577
+	}
578
+
579
+	function get_account_type($select = "", $table = "", $PTE) {
580
+		return ($PTE == 1) ? "Postpaid" : "Prepaid";
581
+	}
582
+
583
+	/******
584 584
       Payment to refill
585 585
     ******/
586 586
 
587
-    function get_refill_by($select = "", $table = "", $type) {
588
-        if ($type == '-1') {
589
-            $type = "Admin";
590
-        } else {
591
-            $type = $this->get_field_name("number", "accounts", array("id" => $type));
592
-        }
593
-        return $type;
594
-    }
595
-
596
-    /******************* */
597
-
598
-    function get_payment_by($select = "", $table = "", $type) {
599
-        if ($type == '-1') {
600
-            $type = "Admin";
601
-        } else {
602
-            $type = $this->get_field_name("number", "accounts", array("id" => $type));
603
-        }
604
-        return $type;
605
-    }
606
-
607
-    function set_payment_type($payment_type = '') {
608
-        /*
587
+	function get_refill_by($select = "", $table = "", $type) {
588
+		if ($type == '-1') {
589
+			$type = "Admin";
590
+		} else {
591
+			$type = $this->get_field_name("number", "accounts", array("id" => $type));
592
+		}
593
+		return $type;
594
+	}
595
+
596
+	/******************* */
597
+
598
+	function get_payment_by($select = "", $table = "", $type) {
599
+		if ($type == '-1') {
600
+			$type = "Admin";
601
+		} else {
602
+			$type = $this->get_field_name("number", "accounts", array("id" => $type));
603
+		}
604
+		return $type;
605
+	}
606
+
607
+	function set_payment_type($payment_type = '') {
608
+		/*
609 609
          * Recharge to Refill
610 610
          */
611
-        $status_array = array('0' => 'Refill', '1' => 'Postcharge',);
612
-        return $status_array;
613
-    }
614
-
615
-    function search_int_type($status = '') {
616
-        $status_array = array('1' => 'Is Equal To', '2' => 'Is Not Equal To', '3' => 'Greater Than', '4' => 'Less Than', '5' => 'Greater Or Equal Than', '6' => 'Less Or Equal Than');
617
-        return $status_array;
618
-    }
619
-
620
-    function update_int_type($status = '') {
621
-        $status_array = array('1' => 'Preserve', '2' => 'Set To', '3' => 'Increase By', '4' => 'Decrease By');
622
-        return $status_array;
623
-    }
624
-
625
-    function update_drp_type($status = '') {
626
-        $status_array = array('1' => 'Preserve', '2' => 'Set To');
627
-        return $status_array;
628
-    }
629
-
630
-    function search_string_type($status = '') {
631
-        $status_array = array('5'=>"Begins With",'1' => 'Contains', '2' => 'Doesnt Contain', '3' => 'Is Equal To', '4' => 'Is Not Equal To',"6"=>"Ends With");
632
-        return $status_array;
633
-    }
634
-
635
-    function set_protocal($protpcal = '') {
636
-        $status_array = array('SIP' => 'SIP', 'IAX2' => 'IAX2', 'Zap' => 'Zap', 'Local' => 'Local', 'OH323' => 'OH323', 'OOH323C' => 'OOH323C');
637
-        return $status_array;
638
-    }
639
-
640
-    /*
611
+		$status_array = array('0' => 'Refill', '1' => 'Postcharge',);
612
+		return $status_array;
613
+	}
614
+
615
+	function search_int_type($status = '') {
616
+		$status_array = array('1' => 'Is Equal To', '2' => 'Is Not Equal To', '3' => 'Greater Than', '4' => 'Less Than', '5' => 'Greater Or Equal Than', '6' => 'Less Or Equal Than');
617
+		return $status_array;
618
+	}
619
+
620
+	function update_int_type($status = '') {
621
+		$status_array = array('1' => 'Preserve', '2' => 'Set To', '3' => 'Increase By', '4' => 'Decrease By');
622
+		return $status_array;
623
+	}
624
+
625
+	function update_drp_type($status = '') {
626
+		$status_array = array('1' => 'Preserve', '2' => 'Set To');
627
+		return $status_array;
628
+	}
629
+
630
+	function search_string_type($status = '') {
631
+		$status_array = array('5'=>"Begins With",'1' => 'Contains', '2' => 'Doesnt Contain', '3' => 'Is Equal To', '4' => 'Is Not Equal To',"6"=>"Ends With");
632
+		return $status_array;
633
+	}
634
+
635
+	function set_protocal($protpcal = '') {
636
+		$status_array = array('SIP' => 'SIP', 'IAX2' => 'IAX2', 'Zap' => 'Zap', 'Local' => 'Local', 'OH323' => 'OH323', 'OOH323C' => 'OOH323C');
637
+		return $status_array;
638
+	}
639
+
640
+	/*
641 641
      *
642 642
      * Purpose : Add Profit Margin report
643 643
      * Version 2.1
644 644
      */
645 645
 
646
-    function set_notify_by($status = '') {
647
-        $status_array = array('' => 'Select Notify By', '0' => 'CSV', '1' => 'Email');
648
-        return $status_array;
649
-    }
646
+	function set_notify_by($status = '') {
647
+		$status_array = array('' => 'Select Notify By', '0' => 'CSV', '1' => 'Email');
648
+		return $status_array;
649
+	}
650 650
 
651
-    function convert_to_percentage($select = "", $table = "", $amount) {
652
-        return round($amount, 2) . " %";
653
-    }
651
+	function convert_to_percentage($select = "", $table = "", $amount) {
652
+		return round($amount, 2) . " %";
653
+	}
654 654
 
655
-    function convert_to_minutes($select = "", $table = "", $amount) {
656
-        return str_replace('.', ':', round($amount / 60, 2));
657
-    }
655
+	function convert_to_minutes($select = "", $table = "", $amount) {
656
+		return str_replace('.', ':', round($amount / 60, 2));
657
+	}
658 658
 
659
-    function set_filter_type_search($status = '') {
660
-        $status_array = array('pricelist_id' => 'Rate Group', 'accountid' => 'Customer', 'reseller_id' => 'Reseller');
661
-        return $status_array;
662
-    }
659
+	function set_filter_type_search($status = '') {
660
+		$status_array = array('pricelist_id' => 'Rate Group', 'accountid' => 'Customer', 'reseller_id' => 'Reseller');
661
+		return $status_array;
662
+	}
663 663
     
664
-    	function set_routetype_status($select= ''){
665
-        $status_array = array("" => "--Select--",
666
-            "0" => "LCR",
667
-            "1" => "COST"
668
-        );
669
-        return $status_array;
664
+		function set_routetype_status($select= ''){
665
+		$status_array = array("" => "--Select--",
666
+			"0" => "LCR",
667
+			"1" => "COST"
668
+		);
669
+		return $status_array;
670 670
 }
671 671
 	
672 672
 
673
-    //attachment download in email module...
674
-    function attachment_icons($select = "", $table = "", $attachement = "") {
675
-        if ($attachement != "") {
676
-            $array = explode(",", $attachement);
677
-            $str = '';	
678
-            foreach ($array as $key => $val) {
679
-                $link = base_url() . "email/email_history_list_attachment/" . $val;
680
-                $str.="<a href='" . $link . "' title='" . $val . "' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
681
-            }
682
-            return $str;
683
-        } else {
684
-            return "";
685
-        }
686
-    }
687
-
688
-    /*     * ************************************************************* */
689
-
690
-    function set_despostion($dis = '') {
691
-        $status_array = array("" => "--Select Disposition--",
692
-            "UNSPECIFIED" => "UNSPECIFIED",
693
-            "UNALLOCATED_NUMBER" => "UNALLOCATED_NUMBER",
694
-            "NO_ROUTE_DESTINATION" => "NO_ROUTE_DESTINATION",
695
-            "CHANNEL_UNACCEPTABLE" => "CHANNEL_UNACCEPTABLE",
696
-            "NORMAL_CLEARING" => "NORMAL_CLEARING",
697
-            "SUCCESS" => "SUCCESS",
698
-            "USER_BUSY" => "USER_BUSY",
699
-            "NO_USER_RESPONSE" => "NO_USER_RESPONSE",
700
-            "NO_ANSWER" => "NO_ANSWER",
701
-            "CALL_REJECTED" => "CALL_REJECTED",
702
-            "NUMBER_CHANGED" => "NUMBER_CHANGED",
703
-            "DESTINATION_OUT_OF_ORDER" => "DESTINATION_OUT_OF_ORDER",
704
-            "INVALID_NUMBER_FORMAT" => "INVALID_NUMBER_FORMAT",
705
-            "FACILITY_REJECTED" => "FACILITY_REJECTED",
706
-            "NORMAL_UNSPECIFIED" => "NORMAL_UNSPECIFIED",
707
-            "NORMAL_CIRCUIT_CONGESTION" => "NORMAL_CIRCUIT_CONGESTION",
708
-            "NETWORK_OUT_OF_ORDER" => "NETWORK_OUT_OF_ORDER",
709
-            "NORMAL_TEMPORARY_FAILURE" => "NORMAL_TEMPORARY_FAILURE",
710
-            "SWITCH_CONGESTION" => "SWITCH_CONGESTION",
711
-            "FACILITY_NOT_SUBSCRIBED" => "FACILITY_NOT_SUBSCRIBED",
712
-            "OUTGOING_CALL_BARRED" => "OUTGOING_CALL_BARRED",
713
-            "BEARERCAPABILITY_NOTAUTH" => "BEARERCAPABILITY_NOTAUTH",
714
-            "BEARERCAPABILITY_NOTAVAIL" => "BEARERCAPABILITY_NOTAVAIL",
715
-            "SERVICE_UNAVAILABLE" => "SERVICE_UNAVAILABLE",
716
-            "BEARERCAPABILITY_NOTIMPL" => "BEARERCAPABILITY_NOTIMPL",
717
-            "CHAN_NOT_IMPLEMENTED" => "CHAN_NOT_IMPLEMENTED",
718
-            "FACILITY_NOT_IMPLEMENTED" => "FACILITY_NOT_IMPLEMENTED",
719
-            "SERVICE_NOT_IMPLEMENTED" => "SERVICE_NOT_IMPLEMENTED",
720
-            "INCOMPATIBLE_DESTINATION" => "INCOMPATIBLE_DESTINATION",
721
-            "RECOVERY_ON_TIMER_EXPIRE" => "RECOVERY_ON_TIMER_EXPIRE",
722
-            "ORIGINATOR_CANCEL" => "ORIGINATOR_CANCEL",
723
-            "ALLOTTED_TIMEOUT" => "ALLOTTED_TIMEOUT",
724
-            "MEDIA_TIMEOUT" => "MEDIA_TIMEOUT",
725
-            "PROGRESS_TIMEOUT" => "PROGRESS_TIMEOUT",
726
-            "AUTHENTICATION_FAIL" => "AUTHENTICATION_FAIL",
673
+	//attachment download in email module...
674
+	function attachment_icons($select = "", $table = "", $attachement = "") {
675
+		if ($attachement != "") {
676
+			$array = explode(",", $attachement);
677
+			$str = '';	
678
+			foreach ($array as $key => $val) {
679
+				$link = base_url() . "email/email_history_list_attachment/" . $val;
680
+				$str.="<a href='" . $link . "' title='" . $val . "' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
681
+			}
682
+			return $str;
683
+		} else {
684
+			return "";
685
+		}
686
+	}
687
+
688
+	/*     * ************************************************************* */
689
+
690
+	function set_despostion($dis = '') {
691
+		$status_array = array("" => "--Select Disposition--",
692
+			"UNSPECIFIED" => "UNSPECIFIED",
693
+			"UNALLOCATED_NUMBER" => "UNALLOCATED_NUMBER",
694
+			"NO_ROUTE_DESTINATION" => "NO_ROUTE_DESTINATION",
695
+			"CHANNEL_UNACCEPTABLE" => "CHANNEL_UNACCEPTABLE",
696
+			"NORMAL_CLEARING" => "NORMAL_CLEARING",
697
+			"SUCCESS" => "SUCCESS",
698
+			"USER_BUSY" => "USER_BUSY",
699
+			"NO_USER_RESPONSE" => "NO_USER_RESPONSE",
700
+			"NO_ANSWER" => "NO_ANSWER",
701
+			"CALL_REJECTED" => "CALL_REJECTED",
702
+			"NUMBER_CHANGED" => "NUMBER_CHANGED",
703
+			"DESTINATION_OUT_OF_ORDER" => "DESTINATION_OUT_OF_ORDER",
704
+			"INVALID_NUMBER_FORMAT" => "INVALID_NUMBER_FORMAT",
705
+			"FACILITY_REJECTED" => "FACILITY_REJECTED",
706
+			"NORMAL_UNSPECIFIED" => "NORMAL_UNSPECIFIED",
707
+			"NORMAL_CIRCUIT_CONGESTION" => "NORMAL_CIRCUIT_CONGESTION",
708
+			"NETWORK_OUT_OF_ORDER" => "NETWORK_OUT_OF_ORDER",
709
+			"NORMAL_TEMPORARY_FAILURE" => "NORMAL_TEMPORARY_FAILURE",
710
+			"SWITCH_CONGESTION" => "SWITCH_CONGESTION",
711
+			"FACILITY_NOT_SUBSCRIBED" => "FACILITY_NOT_SUBSCRIBED",
712
+			"OUTGOING_CALL_BARRED" => "OUTGOING_CALL_BARRED",
713
+			"BEARERCAPABILITY_NOTAUTH" => "BEARERCAPABILITY_NOTAUTH",
714
+			"BEARERCAPABILITY_NOTAVAIL" => "BEARERCAPABILITY_NOTAVAIL",
715
+			"SERVICE_UNAVAILABLE" => "SERVICE_UNAVAILABLE",
716
+			"BEARERCAPABILITY_NOTIMPL" => "BEARERCAPABILITY_NOTIMPL",
717
+			"CHAN_NOT_IMPLEMENTED" => "CHAN_NOT_IMPLEMENTED",
718
+			"FACILITY_NOT_IMPLEMENTED" => "FACILITY_NOT_IMPLEMENTED",
719
+			"SERVICE_NOT_IMPLEMENTED" => "SERVICE_NOT_IMPLEMENTED",
720
+			"INCOMPATIBLE_DESTINATION" => "INCOMPATIBLE_DESTINATION",
721
+			"RECOVERY_ON_TIMER_EXPIRE" => "RECOVERY_ON_TIMER_EXPIRE",
722
+			"ORIGINATOR_CANCEL" => "ORIGINATOR_CANCEL",
723
+			"ALLOTTED_TIMEOUT" => "ALLOTTED_TIMEOUT",
724
+			"MEDIA_TIMEOUT" => "MEDIA_TIMEOUT",
725
+			"PROGRESS_TIMEOUT" => "PROGRESS_TIMEOUT",
726
+			"AUTHENTICATION_FAIL" => "AUTHENTICATION_FAIL",
727 727
 			"ACCOUNT_INACTIVE_DELETED" => "ACCOUNT_INACTIVE_DELETED",
728 728
 			"ACCOUNT_EXPIRE" => "ACCOUNT_EXPIRE",
729 729
 			"NO_SUFFICIENT_FUND" => "NO_SUFFICIENT_FUND",
@@ -732,141 +732,141 @@  discard block
 block discarded – undo
732 732
 			"RESELLER_COST_CHEAP" => "RESELLER_COST_CHEAP",
733 733
 			"TERMINATION_RATE_NOT_FOUND" => "TERMINATION_RATE_NOT_FOUND",
734 734
 			"DID_DESTINATION_NOT_FOUND" => "DID_DESTINATION_NOT_FOUND",
735
-        );
736
-        return $status_array;
737
-    }
738
-
739
-    function set_calltype($type = '') {
740
-        $status_array = array("" => "--Select Type--",
741
-            "STANDARD" => "STANDARD",
742
-            "DID" => "DID",
743
-            "CALLINGCARD" => "CALLINGCARD",
744
-            "FREE" => "FREE",
745
-        );
746
-        return $status_array;
747
-    }
748
-
749
-    function set_search_status($select = '') {
750
-        $status_array = array("" => "--Select--",
751
-            "0" => "Active",
752
-            "1" => "Inactive"
753
-        );
754
-        return $status_array;
755
-    }
735
+		);
736
+		return $status_array;
737
+	}
738
+
739
+	function set_calltype($type = '') {
740
+		$status_array = array("" => "--Select Type--",
741
+			"STANDARD" => "STANDARD",
742
+			"DID" => "DID",
743
+			"CALLINGCARD" => "CALLINGCARD",
744
+			"FREE" => "FREE",
745
+		);
746
+		return $status_array;
747
+	}
748
+
749
+	function set_search_status($select = '') {
750
+		$status_array = array("" => "--Select--",
751
+			"0" => "Active",
752
+			"1" => "Inactive"
753
+		);
754
+		return $status_array;
755
+	}
756 756
         
757
-    function set_Billing_Schedule_status($select = '') {
758
-        $status_array = array("" => "--Select--",
759
-            "0" => "Daily",
760
-            "2" => "Monthly"
761
-        );
762
-        return $status_array;
763
-    }
764
-
765
-    function get_action_buttons($buttons_arr, $linkid) {
766
-        $ret_url = '';
767
-        if (!empty($buttons_arr) && $buttons_arr != '') {
768
-            foreach ($buttons_arr as $button_key => $buttons_params) {
769
-                if (strtoupper($button_key) == "EDIT") {
770
-                    $ret_url .= $this->build_edit_button($buttons_params, $linkid);
771
-                }
772
-                /*
757
+	function set_Billing_Schedule_status($select = '') {
758
+		$status_array = array("" => "--Select--",
759
+			"0" => "Daily",
760
+			"2" => "Monthly"
761
+		);
762
+		return $status_array;
763
+	}
764
+
765
+	function get_action_buttons($buttons_arr, $linkid) {
766
+		$ret_url = '';
767
+		if (!empty($buttons_arr) && $buttons_arr != '') {
768
+			foreach ($buttons_arr as $button_key => $buttons_params) {
769
+				if (strtoupper($button_key) == "EDIT") {
770
+					$ret_url .= $this->build_edit_button($buttons_params, $linkid);
771
+				}
772
+				/*
773 773
                  *
774 774
                  * Purpose : Add resend link
775 775
                  * Version 2.1
776 776
                  */
777
-                if (strtoupper($button_key) == "RESEND") {
778
-                    $ret_url .= $this->build_edit_button_resend($buttons_params, $linkid);
779
-                }
780
-                /*                 * ************************************* */
781
-                if (strtoupper($button_key) == "EDIT_RESTORE") {
782
-                    $ret_url .= $this->build_edit_button_restore($buttons_params, $linkid);
783
-                }
784
-                if (strtoupper($button_key) == "DELETE") {
785
-                    $ret_url .= $this->build_delete_button($buttons_params->url, $linkid);
786
-                }
787
-                if (strtoupper($button_key) == "VIEW") {
788
-                    $ret_url .= $this->build_view_button($buttons_params, $linkid);
789
-                }
790
-                if (strtoupper($button_key) == "TAXES") {
791
-                    $ret_url .= $this->build_add_taxes_button($buttons_params, $linkid);
792
-                }
793
-                if (strtoupper($button_key) == "BLUEBOX_LOGIN") {
794
-                    $ret_url .= $this->build_bluebox_login($buttons_params->url, $linkid);
795
-                }
796
-                if (strtoupper($button_key) == "CALLERID") {
797
-                    $ret_url .= $this->build_add_callerid_button($buttons_params, $linkid);
798
-                }
799
-                if (strtoupper($button_key) == "PAYMENT") {
800
-                    $ret_url .= $this->build_add_payment_button($buttons_params->url, $linkid);
801
-                }
802
-                if (strtoupper($button_key) == "DOWNLOAD") {
803
-                    $ret_url .= $this->build_add_download_button($buttons_params->url, $linkid);
804
-                }
805
-                if (strtoupper($button_key) == "START") {
806
-                    $ret_url .= $this->build_start_button($buttons_params->url, $linkid);
807
-                }
808
-                if (strtoupper($button_key) == "STOP") {
809
-                    $ret_url .= $this->build_stop_button($buttons_params->url, $linkid);
810
-                }
811
-                if (strtoupper($button_key) == "RELOAD") {
812
-                    $ret_url .= $this->build_reload_button($buttons_params->url, $linkid);
813
-                }
814
-                if (strtoupper($button_key) == "RESCAN") {
815
-                    $ret_url .= $this->build_rescan_button($buttons_params->url, $linkid);
816
-                }
817
-
818
-                if (strtoupper($button_key) == "DOWNLOAD_DATABASE") {
819
-                    $ret_url .= $this->build_add_download_database_button($buttons_params->url, $linkid);
820
-                }
821
-                if (strtoupper($button_key) == "DELETE_ANIMAP") {
822
-                    $ret_url .= $this->build_delete_button_animap($buttons_params->url, $linkid);
823
-                }
824
-                if (strtoupper($button_key) == "EDIT_ANIMAP") {
825
-                    $ret_url .= $this->build_edit_button_animap($buttons_params, $linkid);
826
-                }
827
-                if (strtoupper($button_key) == "ANIMAP") {
828
-                    $ret_url .= $this->build_animap_button($buttons_params, $linkid);
829
-                }
830
-            }
831
-        }
832
-        return $ret_url;
833
-    }
834
-
835
-    function build_delete_button_animap($url, $linkid) {
836
-        $link = base_url() . $url . "" . $linkid;
837
-        return '<a href="javascript:void(0)" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg_destination(' . $linkid . ');"><i class="fa fa-trash fa-fw"></i></a>';
838
-    }
839
-
840
-    function build_edit_button_animap($button_params, $linkid) {
841
-        $link = base_url() . $button_params->url . "" . $linkid;
842
-        return '<a href="javascript:void(0);" id="destination_new" class="btn btn-royelblue btn-sm" onclick="return get_destination(' . $linkid . ');" title="Update"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
843
-    }
844
-
845
-    function build_animap_button($button_params, $linkid) {
846
-        $link = base_url() . $button_params->url . "" . $linkid;
847
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm animap_image" rel="facebox" title="ANI Map"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
848
-    }
849
-
850
-    function build_edit_button($button_params, $linkid) {
851
-        $link = base_url() . $button_params->url . "" . $linkid;
777
+				if (strtoupper($button_key) == "RESEND") {
778
+					$ret_url .= $this->build_edit_button_resend($buttons_params, $linkid);
779
+				}
780
+				/*                 * ************************************* */
781
+				if (strtoupper($button_key) == "EDIT_RESTORE") {
782
+					$ret_url .= $this->build_edit_button_restore($buttons_params, $linkid);
783
+				}
784
+				if (strtoupper($button_key) == "DELETE") {
785
+					$ret_url .= $this->build_delete_button($buttons_params->url, $linkid);
786
+				}
787
+				if (strtoupper($button_key) == "VIEW") {
788
+					$ret_url .= $this->build_view_button($buttons_params, $linkid);
789
+				}
790
+				if (strtoupper($button_key) == "TAXES") {
791
+					$ret_url .= $this->build_add_taxes_button($buttons_params, $linkid);
792
+				}
793
+				if (strtoupper($button_key) == "BLUEBOX_LOGIN") {
794
+					$ret_url .= $this->build_bluebox_login($buttons_params->url, $linkid);
795
+				}
796
+				if (strtoupper($button_key) == "CALLERID") {
797
+					$ret_url .= $this->build_add_callerid_button($buttons_params, $linkid);
798
+				}
799
+				if (strtoupper($button_key) == "PAYMENT") {
800
+					$ret_url .= $this->build_add_payment_button($buttons_params->url, $linkid);
801
+				}
802
+				if (strtoupper($button_key) == "DOWNLOAD") {
803
+					$ret_url .= $this->build_add_download_button($buttons_params->url, $linkid);
804
+				}
805
+				if (strtoupper($button_key) == "START") {
806
+					$ret_url .= $this->build_start_button($buttons_params->url, $linkid);
807
+				}
808
+				if (strtoupper($button_key) == "STOP") {
809
+					$ret_url .= $this->build_stop_button($buttons_params->url, $linkid);
810
+				}
811
+				if (strtoupper($button_key) == "RELOAD") {
812
+					$ret_url .= $this->build_reload_button($buttons_params->url, $linkid);
813
+				}
814
+				if (strtoupper($button_key) == "RESCAN") {
815
+					$ret_url .= $this->build_rescan_button($buttons_params->url, $linkid);
816
+				}
817
+
818
+				if (strtoupper($button_key) == "DOWNLOAD_DATABASE") {
819
+					$ret_url .= $this->build_add_download_database_button($buttons_params->url, $linkid);
820
+				}
821
+				if (strtoupper($button_key) == "DELETE_ANIMAP") {
822
+					$ret_url .= $this->build_delete_button_animap($buttons_params->url, $linkid);
823
+				}
824
+				if (strtoupper($button_key) == "EDIT_ANIMAP") {
825
+					$ret_url .= $this->build_edit_button_animap($buttons_params, $linkid);
826
+				}
827
+				if (strtoupper($button_key) == "ANIMAP") {
828
+					$ret_url .= $this->build_animap_button($buttons_params, $linkid);
829
+				}
830
+			}
831
+		}
832
+		return $ret_url;
833
+	}
834
+
835
+	function build_delete_button_animap($url, $linkid) {
836
+		$link = base_url() . $url . "" . $linkid;
837
+		return '<a href="javascript:void(0)" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg_destination(' . $linkid . ');"><i class="fa fa-trash fa-fw"></i></a>';
838
+	}
839
+
840
+	function build_edit_button_animap($button_params, $linkid) {
841
+		$link = base_url() . $button_params->url . "" . $linkid;
842
+		return '<a href="javascript:void(0);" id="destination_new" class="btn btn-royelblue btn-sm" onclick="return get_destination(' . $linkid . ');" title="Update"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
843
+	}
844
+
845
+	function build_animap_button($button_params, $linkid) {
846
+		$link = base_url() . $button_params->url . "" . $linkid;
847
+		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm animap_image" rel="facebox" title="ANI Map"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
848
+	}
849
+
850
+	function build_edit_button($button_params, $linkid) {
851
+		$link = base_url() . $button_params->url . "" . $linkid;
852 852
        
853
-        if ($button_params->mode == 'popup') {
854
-            $rel = (isset($button_params->layout) && $button_params->layout != '')?"facebox_".$button_params->layout:"facebox";
855
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="Edit" ="small"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
853
+		if ($button_params->mode == 'popup') {
854
+			$rel = (isset($button_params->layout) && $button_params->layout != '')?"facebox_".$button_params->layout:"facebox";
855
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="Edit" ="small"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
856 856
             
857
-        }else if(strpos($link,'customer_edit') !== false){
858
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
859
-        }else {
860
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
861
-        }
862
-    }
863
-
864
-    /**
857
+		}else if(strpos($link,'customer_edit') !== false){
858
+		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
859
+		}else {
860
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
861
+		}
862
+	}
863
+
864
+	/**
865 865
       For Edit on Account number or name
866
-     **/
867
-    function build_custome_edit_button($button_params, $field, $linkid) {
868
-        $link = base_url() . $button_params->url . "" . $linkid;
869
-        if(isset($button_params->layout)){
866
+	 **/
867
+	function build_custome_edit_button($button_params, $field, $linkid) {
868
+		$link = base_url() . $button_params->url . "" . $linkid;
869
+		if(isset($button_params->layout)){
870 870
 			if ($button_params->mode == 'popup') {
871 871
 				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" rel="facebox_medium" title="Update">' . $field . '</a>&nbsp;';
872 872
 			} else {
@@ -879,258 +879,258 @@  discard block
 block discarded – undo
879 879
 				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" title="Edit">' . $field . '</a>&nbsp;';
880 880
 			}
881 881
 		}
882
-    }
883
-
884
-    /************************************ */
885
-
886
-    function build_edit_button_restore($button_params, $linkid) {
887
-        $link = base_url() . $button_params->url . "" . $linkid;
888
-        if ($button_params->mode == 'popup') {
889
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Restore" onClick="return get_alert_msg();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
890
-        } else {
891
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Restore" onClick="return get_alert_msg_restore();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
892
-        }
893
-    }
894
-
895
-    function build_delete_button($url, $linkid) {
896
-        $flag='0';
897
-        $data=  explode("/",$url);
898
-        $link = base_url() . $url . "" . $linkid;
899
-        foreach($data as $key=>$value){
900
-            if($value == 'price_delete')
901
-                $flag = '1';
902
-            if($value == 'trunk_remove')
903
-                $flag='2';
904
-            if($value == 'customer_delete' ||$value =='provider_delete')
905
-                $flag='3';
906
-            if($value == 'reseller_delete')
907
-                $flag='4';
908
-            }    
909
-            if($flag=='1'){
910
-                $where=array('pricelist_id'=>$linkid,'deleted !=' =>'1');
911
-                $customer_cnt=$this->get_field_count('id','accounts',$where);
912
-                    $where=array('pricelist_id'=>$linkid);
913
-                    $rategroup_cnt=$this->get_field_count('id','routes',$where);
914
-                    if($rategroup_cnt > 0 || $customer_cnt > 0 ){
882
+	}
883
+
884
+	/************************************ */
885
+
886
+	function build_edit_button_restore($button_params, $linkid) {
887
+		$link = base_url() . $button_params->url . "" . $linkid;
888
+		if ($button_params->mode == 'popup') {
889
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Restore" onClick="return get_alert_msg();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
890
+		} else {
891
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Restore" onClick="return get_alert_msg_restore();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
892
+		}
893
+	}
894
+
895
+	function build_delete_button($url, $linkid) {
896
+		$flag='0';
897
+		$data=  explode("/",$url);
898
+		$link = base_url() . $url . "" . $linkid;
899
+		foreach($data as $key=>$value){
900
+			if($value == 'price_delete')
901
+				$flag = '1';
902
+			if($value == 'trunk_remove')
903
+				$flag='2';
904
+			if($value == 'customer_delete' ||$value =='provider_delete')
905
+				$flag='3';
906
+			if($value == 'reseller_delete')
907
+				$flag='4';
908
+			}    
909
+			if($flag=='1'){
910
+				$where=array('pricelist_id'=>$linkid,'deleted !=' =>'1');
911
+				$customer_cnt=$this->get_field_count('id','accounts',$where);
912
+					$where=array('pricelist_id'=>$linkid);
913
+					$rategroup_cnt=$this->get_field_count('id','routes',$where);
914
+					if($rategroup_cnt > 0 || $customer_cnt > 0 ){
915 915
                         
916
-                        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$rategroup_cnt.','.$customer_cnt.','.$linkid.',1);"><i class="fa fa-trash fa-fw"></i></a>';
917
-                    }
918
-                    else{
919
-                        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
920
-                    }
921
-            }
922
-            if($flag=='2'){
923
-                $where=array('trunk_id'=>$linkid);
924
-                $trunk_cnt=$this->get_field_count('id','outbound_routes',$where);
925
-                if($trunk_cnt > 0){
926
-                    return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$trunk_cnt.',null,'.$linkid.',2);"><i class="fa fa-trash fa-fw"></i></a>';
927
-                }
928
-                else{
929
-                    return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
930
-                }
931
-            }
932
-            if($flag == '3'){
916
+						return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$rategroup_cnt.','.$customer_cnt.','.$linkid.',1);"><i class="fa fa-trash fa-fw"></i></a>';
917
+					}
918
+					else{
919
+						return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
920
+					}
921
+			}
922
+			if($flag=='2'){
923
+				$where=array('trunk_id'=>$linkid);
924
+				$trunk_cnt=$this->get_field_count('id','outbound_routes',$where);
925
+				if($trunk_cnt > 0){
926
+					return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$trunk_cnt.',null,'.$linkid.',2);"><i class="fa fa-trash fa-fw"></i></a>';
927
+				}
928
+				else{
929
+					return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
930
+				}
931
+			}
932
+			if($flag == '3'){
933 933
 		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message(0,null,'.$linkid.',3);">
934 934
 		<i class="fa fa-trash fa-fw"></i></a>';
935
-            }
936
-            if($flag == '4'){
935
+			}
936
+			if($flag == '4'){
937 937
 		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message(0,null,'.$linkid.',4);">
938 938
 		<i class="fa fa-trash fa-fw"></i></a>';
939
-            }
940
-            if($flag=='0' && $url.$linkid !='accounts/admin_delete/1' ){
941
-                return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
942
-            }  
943
-    }
944
-
945
-    function build_view_button($button_params, $linkid) {
946
-        $link = base_url() . $button_params->url . "" . $linkid;
947
-        if ($button_params->mode == 'popup') {
939
+			}
940
+			if($flag=='0' && $url.$linkid !='accounts/admin_delete/1' ){
941
+				return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
942
+			}  
943
+	}
944
+
945
+	function build_view_button($button_params, $linkid) {
946
+		$link = base_url() . $button_params->url . "" . $linkid;
947
+		if ($button_params->mode == 'popup') {
948 948
 			$rel = (isset($button_params->layout) && $button_params->layout != '')?"facebox_".$button_params->layout:"facebox";
949
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
950
-        } else {
951
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
952
-        }
953
-    }
954
-
955
-    function build_add_taxes_button($button_params, $linkid) {
956
-        $link = base_url() . $button_params->url . "" . $linkid;
957
-        if ($button_params->mode == 'popup') {
958
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
959
-        } else {
960
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
961
-        }
962
-    }
963
-
964
-    function build_add_download_database_button($url, $linkid) {
965
-        $link = base_url() . $url . "" . $linkid;
966
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm "  title="Download Database" ><i class="fa-fw fa fa-file-archive-o"></i></a>&nbsp;';
967
-    }
968
-
969
-    function build_add_callerid_button($button_params, $linkid) {
970
-        $link = base_url() . $button_params->url . "" . $linkid;
971
-        if ($button_params->mode == 'popup') {
972
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Force Caller Id"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
973
-        } else {
974
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="CallerID"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
975
-        }
976
-    }
977
-
978
-    function build_start_button($url, $linkid) {
979
-        $link = base_url() . $url . "" . $linkid;
980
-
981
-        return '<a href="' . $link . '" class=""  title="Start" style="text-decoration:none;color: #428BCA;"><b>Start |</b></a>&nbsp;';
982
-    }
983
-
984
-    function build_stop_button($url, $linkid) {
985
-        $link = base_url() . $url . "" . $linkid;
986
-        return '<a href="' . $link . '" class=""  title="Stop" style="text-decoration:none;color: #428BCA;" ><b>Stop |</b></a>&nbsp;';
987
-    }
988
-
989
-    function build_reload_button($url, $linkid) {
990
-        $link = base_url() . $url . "" . $linkid;
991
-        return '<a href="' . $link . '" class=""  title="reload" style="text-decoration:none;color: #428BCA;"><b>Reload |</b></a>&nbsp;';
992
-    }
993
-
994
-    function build_rescan_button($url, $linkid) {
995
-        $link = base_url() . $url . "" . $linkid;
996
-        return '<a href="' . $link . '" class=""  title="rescan" style="text-decoration:none;color: #428BCA;"><b>Rescan</b></a>&nbsp;';
997
-    }
998
-
999
-    function build_add_payment_button($url, $linkid) {
1000
-        $link = base_url() . $url . "" . $linkid;
1001
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Refill" ><i class="fa fa-usd fa-fw"></i></a>&nbsp;';
1002
-    }
1003
-
1004
-    function build_add_download_button($url, $linkid) {
1005
-        $link = base_url() . $url . "" . $linkid;
1006
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm"  title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a>&nbsp;';
1007
-    }
1008
-
1009
-    /*
949
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
950
+		} else {
951
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
952
+		}
953
+	}
954
+
955
+	function build_add_taxes_button($button_params, $linkid) {
956
+		$link = base_url() . $button_params->url . "" . $linkid;
957
+		if ($button_params->mode == 'popup') {
958
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
959
+		} else {
960
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
961
+		}
962
+	}
963
+
964
+	function build_add_download_database_button($url, $linkid) {
965
+		$link = base_url() . $url . "" . $linkid;
966
+		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm "  title="Download Database" ><i class="fa-fw fa fa-file-archive-o"></i></a>&nbsp;';
967
+	}
968
+
969
+	function build_add_callerid_button($button_params, $linkid) {
970
+		$link = base_url() . $button_params->url . "" . $linkid;
971
+		if ($button_params->mode == 'popup') {
972
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Force Caller Id"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
973
+		} else {
974
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="CallerID"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
975
+		}
976
+	}
977
+
978
+	function build_start_button($url, $linkid) {
979
+		$link = base_url() . $url . "" . $linkid;
980
+
981
+		return '<a href="' . $link . '" class=""  title="Start" style="text-decoration:none;color: #428BCA;"><b>Start |</b></a>&nbsp;';
982
+	}
983
+
984
+	function build_stop_button($url, $linkid) {
985
+		$link = base_url() . $url . "" . $linkid;
986
+		return '<a href="' . $link . '" class=""  title="Stop" style="text-decoration:none;color: #428BCA;" ><b>Stop |</b></a>&nbsp;';
987
+	}
988
+
989
+	function build_reload_button($url, $linkid) {
990
+		$link = base_url() . $url . "" . $linkid;
991
+		return '<a href="' . $link . '" class=""  title="reload" style="text-decoration:none;color: #428BCA;"><b>Reload |</b></a>&nbsp;';
992
+	}
993
+
994
+	function build_rescan_button($url, $linkid) {
995
+		$link = base_url() . $url . "" . $linkid;
996
+		return '<a href="' . $link . '" class=""  title="rescan" style="text-decoration:none;color: #428BCA;"><b>Rescan</b></a>&nbsp;';
997
+	}
998
+
999
+	function build_add_payment_button($url, $linkid) {
1000
+		$link = base_url() . $url . "" . $linkid;
1001
+		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Refill" ><i class="fa fa-usd fa-fw"></i></a>&nbsp;';
1002
+	}
1003
+
1004
+	function build_add_download_button($url, $linkid) {
1005
+		$link = base_url() . $url . "" . $linkid;
1006
+		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm"  title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a>&nbsp;';
1007
+	}
1008
+
1009
+	/*
1010 1010
      * Purpose : Add following for resent icon
1011 1011
      * Version 2.1
1012 1012
      */
1013 1013
 
1014
-    function build_edit_button_resend($button_params, $linkid) {
1015
-        $link = base_url() . $button_params->url . "" . $linkid;
1016
-        if ($button_params->mode == 'popup') {
1017
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1018
-        } else {
1019
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1020
-        }
1021
-    }
1014
+	function build_edit_button_resend($button_params, $linkid) {
1015
+		$link = base_url() . $button_params->url . "" . $linkid;
1016
+		if ($button_params->mode == 'popup') {
1017
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1018
+		} else {
1019
+			return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1020
+		}
1021
+	}
1022 1022
 
1023
-    /*
1023
+	/*
1024 1024
      * ----------------------------------------------------------------------------
1025 1025
      */
1026 1026
 
1027
-    function get_only_numeric_val($select = "", $table = "", $string) {
1028
-        return filter_var($string, FILTER_SANITIZE_NUMBER_INT);
1029
-    }
1027
+	function get_only_numeric_val($select = "", $table = "", $string) {
1028
+		return filter_var($string, FILTER_SANITIZE_NUMBER_INT);
1029
+	}
1030 1030
 
1031
-    function mail_to_users($type, $accountinfo, $attachment = "", $amount = "") {
1031
+	function mail_to_users($type, $accountinfo, $attachment = "", $amount = "") {
1032 1032
 		$subject = "";
1033
-        $settings_reply_email = '[email protected]';
1034
-        $reseller_id=$accountinfo['reseller_id'] > 0 ? $accountinfo['reseller_id'] : 0;
1033
+		$settings_reply_email = '[email protected]';
1034
+		$reseller_id=$accountinfo['reseller_id'] > 0 ? $accountinfo['reseller_id'] : 0;
1035 1035
 		$where="accountid IN ('".$reseller_id."','1')";
1036
-        $this->CI->db->where($where);
1037
-        $this->CI->db->select('emailaddress');
1038
-        $this->CI->db->order_by('accountid', 'desc');
1039
-        $this->CI->db->limit(1);
1040
-        $invoiceconf = $this->CI->db->get('invoice_conf');
1041
-        $invoiceconf = (array)$invoiceconf->first_row();
1042
-        $settings_reply_email=$invoiceconf['emailaddress'];
1043
-        $company_name=Common_model::$global_config['system_config']['company_name'];
1044
-        $company_website=Common_model::$global_config['system_config']['company_website'];
1045
-        $where = array('name' => $type);
1046
-        $query = $this->CI->db_model->getSelect("*", "default_templates", $where);
1047
-        $query = $query->result();
1048
-        $message = $query[0]->template;
1049
-        $useremail = $accountinfo['email'];
1050
-        $message = html_entity_decode($message);
1051
-        $message = str_replace("#COMPANY_EMAIL#", $settings_reply_email, $message);
1052
-        $message = str_replace("#COMPANY_NAME#", $company_name, $message);
1053
-        $message = str_replace("#COMPANY_WEBSITE#", $company_website, $message);
1054
-        $message = str_replace("</p>", "", $message);
1036
+		$this->CI->db->where($where);
1037
+		$this->CI->db->select('emailaddress');
1038
+		$this->CI->db->order_by('accountid', 'desc');
1039
+		$this->CI->db->limit(1);
1040
+		$invoiceconf = $this->CI->db->get('invoice_conf');
1041
+		$invoiceconf = (array)$invoiceconf->first_row();
1042
+		$settings_reply_email=$invoiceconf['emailaddress'];
1043
+		$company_name=Common_model::$global_config['system_config']['company_name'];
1044
+		$company_website=Common_model::$global_config['system_config']['company_website'];
1045
+		$where = array('name' => $type);
1046
+		$query = $this->CI->db_model->getSelect("*", "default_templates", $where);
1047
+		$query = $query->result();
1048
+		$message = $query[0]->template;
1049
+		$useremail = $accountinfo['email'];
1050
+		$message = html_entity_decode($message);
1051
+		$message = str_replace("#COMPANY_EMAIL#", $settings_reply_email, $message);
1052
+		$message = str_replace("#COMPANY_NAME#", $company_name, $message);
1053
+		$message = str_replace("#COMPANY_WEBSITE#", $company_website, $message);
1054
+		$message = str_replace("</p>", "", $message);
1055 1055
 		if(isset($accountinfo['refill_amount']) && $accountinfo['refill_amount']!= ""){
1056 1056
 			$refillamount = $accountinfo['refill_amount'];
1057 1057
 		}else{
1058 1058
 			$refillamount = "0";
1059 1059
 		}
1060 1060
 		
1061
-        switch ($type) {
1062
-            case 'email_add_user':
1063
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1064
-                $message = str_replace('#NUMBER#', $accountinfo['number'], $message);
1065
-                $message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1066
-                $message = str_replace('#LINK#', $accountinfo['confirm'], $message);
1067
-                break;
1068
-            case 'email_forgot_user':
1069
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1070
-                $message = str_replace('#NUMBER#', $accountinfo['number'], $message);
1071
-                $message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1072
-                $message = str_replace('#LINK#', $accountinfo['link'], $message);
1073
-                break;
1074
-
1075
-            case 'email_forgot_confirmation':
1076
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1077
-                $message = str_replace('#CONFIRM#', $accountinfo['confirm'], $message);
1078
-                break;
1079
-
1080
-            case 'email_signup_confirmation':
1081
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1082
-                $message = str_replace('#CONFIRM#', $accountinfo['confirm'], $message);
1083
-                break;
1084
-            case 'add_sip_device':
1085
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1086
-                $message = str_replace('#USERNAME#', $accountinfo['number'], $message);
1087
-                $message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1088
-                break;
1061
+		switch ($type) {
1062
+			case 'email_add_user':
1063
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1064
+				$message = str_replace('#NUMBER#', $accountinfo['number'], $message);
1065
+				$message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1066
+				$message = str_replace('#LINK#', $accountinfo['confirm'], $message);
1067
+				break;
1068
+			case 'email_forgot_user':
1069
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1070
+				$message = str_replace('#NUMBER#', $accountinfo['number'], $message);
1071
+				$message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1072
+				$message = str_replace('#LINK#', $accountinfo['link'], $message);
1073
+				break;
1074
+
1075
+			case 'email_forgot_confirmation':
1076
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1077
+				$message = str_replace('#CONFIRM#', $accountinfo['confirm'], $message);
1078
+				break;
1079
+
1080
+			case 'email_signup_confirmation':
1081
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1082
+				$message = str_replace('#CONFIRM#', $accountinfo['confirm'], $message);
1083
+				break;
1084
+			case 'add_sip_device':
1085
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1086
+				$message = str_replace('#USERNAME#', $accountinfo['number'], $message);
1087
+				$message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1088
+				break;
1089 1089
                               
1090
-            case 'voip_account_refilled':
1091
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1092
-                $message = str_replace('#REFILLBALANCE#', $accountinfo['refill_amount'], $message);
1093
-                $message = str_replace('#BALANCE#', $accountinfo['refill_amount'] + $accountinfo['balance'], $message);
1094
-                break;
1095
-            case 'voip_child_account_refilled':
1096
-                $reseller_number= $this->CI->common->get_field_name('number', 'accounts', $accountinfo['reseller_id']);
1097
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1098
-                $message = str_replace('#REFILLBALANCE#', $accountinfo['refill_amount'], $message);
1099
-                $message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1100
-                $message = str_replace('#ACCOUNTNUMBER#',$reseller_number, $message);
1101
-                break;
1102
-            case 'add_subscription':
1103
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1104
-                break;
1105
-            case 'remove_subscription':
1106
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1107
-                break;
1108
-            case 'add_package':
1109
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1110
-                break;
1111
-            case 'remove_package':
1112
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1113
-                break;
1114
-            case 'email_calling_card':
1115
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1116
-                $message = str_replace('#CARDNUMBER#', $accountinfo['cardnumber'], $message);
1117
-                $message = str_replace('#PIN#', $accountinfo['pin'], $message);
1118
-                $message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1119
-                break;
1120
-            case 'email_low_balance';
1121
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1122
-                $to_currency = $this->CI->common->get_field_name('currency', 'currency', $accountinfo['currency_id']);
1123
-                $balance = $this->CI->common_model->calculate_currency($accountinfo['balance'], "", $to_currency, true, true);
1124
-                $message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1125
-                break;
1126
-            case 'email_new_invoice';
1127
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1128
-                $message = str_replace('#AMOUNT#', $amount, $message);
1129
-                $message = str_replace('#INVOICE_NUMBER#', $amount, $message);
1130
-                $subject = $query[0]->subject;
1131
-                $subject = str_replace("#INVOICE_NUMBER#", $amount, $subject);
1132
-                break;
1133
-             case 'email_add_did';
1090
+			case 'voip_account_refilled':
1091
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1092
+				$message = str_replace('#REFILLBALANCE#', $accountinfo['refill_amount'], $message);
1093
+				$message = str_replace('#BALANCE#', $accountinfo['refill_amount'] + $accountinfo['balance'], $message);
1094
+				break;
1095
+			case 'voip_child_account_refilled':
1096
+				$reseller_number= $this->CI->common->get_field_name('number', 'accounts', $accountinfo['reseller_id']);
1097
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1098
+				$message = str_replace('#REFILLBALANCE#', $accountinfo['refill_amount'], $message);
1099
+				$message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1100
+				$message = str_replace('#ACCOUNTNUMBER#',$reseller_number, $message);
1101
+				break;
1102
+			case 'add_subscription':
1103
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1104
+				break;
1105
+			case 'remove_subscription':
1106
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1107
+				break;
1108
+			case 'add_package':
1109
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1110
+				break;
1111
+			case 'remove_package':
1112
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1113
+				break;
1114
+			case 'email_calling_card':
1115
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1116
+				$message = str_replace('#CARDNUMBER#', $accountinfo['cardnumber'], $message);
1117
+				$message = str_replace('#PIN#', $accountinfo['pin'], $message);
1118
+				$message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1119
+				break;
1120
+			case 'email_low_balance';
1121
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1122
+				$to_currency = $this->CI->common->get_field_name('currency', 'currency', $accountinfo['currency_id']);
1123
+				$balance = $this->CI->common_model->calculate_currency($accountinfo['balance'], "", $to_currency, true, true);
1124
+				$message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1125
+				break;
1126
+			case 'email_new_invoice';
1127
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1128
+				$message = str_replace('#AMOUNT#', $amount, $message);
1129
+				$message = str_replace('#INVOICE_NUMBER#', $amount, $message);
1130
+				$subject = $query[0]->subject;
1131
+				$subject = str_replace("#INVOICE_NUMBER#", $amount, $subject);
1132
+				break;
1133
+			 case 'email_add_did';
1134 1134
 				if(isset($accountinfo['did_maxchannels']) && $accountinfo['did_maxchannels']!= ""){
1135 1135
 					$accountinfo['did_maxchannels'] = $accountinfo['did_maxchannels'];
1136 1136
 				}else if($accountinfo['did_maxchannels'] == "0"){
@@ -1138,758 +1138,758 @@  discard block
 block discarded – undo
1138 1138
 				}else{
1139 1139
 					$accountinfo['did_maxchannels'] = "Unlimited";
1140 1140
 				}
1141
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1142
-                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'] , $message);
1143
-                $message = str_replace('#COUNTRYNAME#',$accountinfo['did_country_id'], $message);
1144
-                $message = str_replace('#SETUPFEE#',$accountinfo['did_setup'], $message);
1145
-                $message = str_replace('#MONTHLYFEE#',$accountinfo['did_monthlycost'], $message);
1146
-                $message = str_replace('#MAXCHANNEL#',$accountinfo['did_maxchannels'], $message);
1147
-                $message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1141
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1142
+				$message = str_replace('#DIDNUMBER#', $accountinfo['did_number'] , $message);
1143
+				$message = str_replace('#COUNTRYNAME#',$accountinfo['did_country_id'], $message);
1144
+				$message = str_replace('#SETUPFEE#',$accountinfo['did_setup'], $message);
1145
+				$message = str_replace('#MONTHLYFEE#',$accountinfo['did_monthlycost'], $message);
1146
+				$message = str_replace('#MAXCHANNEL#',$accountinfo['did_maxchannels'], $message);
1147
+				$message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1148 1148
 				$subject = $query[0]->subject;
1149 1149
 				$subject = str_replace("#NUMBER#", $accountinfo['number'], $subject);
1150 1150
 				$subject = str_replace("#DIDNUMBER#", $accountinfo['did_number'], $subject);
1151
-                break;
1152
-            case 'email_remove_did';
1153
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1154
-                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'],$message);
1155
-                $message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1151
+				break;
1152
+			case 'email_remove_did';
1153
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1154
+				$message = str_replace('#DIDNUMBER#', $accountinfo['did_number'],$message);
1155
+				$message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1156 1156
 				$subject = $query[0]->subject;
1157 1157
 				$subject = str_replace("#NUMBER#", $accountinfo['number'], $subject);
1158 1158
 				$subject = str_replace("#DIDNUMBER#", $accountinfo['did_number'], $subject);
1159
-                break;
1160
-        }
1159
+				break;
1160
+		}
1161 1161
         
1162
-        if($subject == ""){
1162
+		if($subject == ""){
1163 1163
 			$subject = $query[0]->subject;
1164 1164
 			$subject = str_replace("#NAME#", $accountinfo['first_name'] . " " . $accountinfo['last_name'], $subject);
1165 1165
 			$subject = str_replace("#COMPANY_NAME#", $company_name, $subject);	
1166 1166
 		}
1167
-        $account_id = (isset($accountinfo['last_id']) && $accountinfo['last_id'] != "") ? $accountinfo['last_id'] : $accountinfo['id'];
1168
-        $reseller_id = $accountinfo['reseller_id'];
1169
-        if ($reseller_id != "0") {
1170
-            $reseller_result = $this->CI->db_model->getSelect("email", "accounts", array("id" => $reseller_id));
1171
-            $reseller_info = (array)$reseller_result->first_row();
1172
-            $settings_reply_email = $reseller_info['email'];
1173
-        }
1174
-        $this->emailFunction($settings_reply_email, $useremail, $subject, $message, $company_name, $attachment, $account_id, $reseller_id);
1175
-
1176
-    }
1177
-
1178
-    function emailFunction($from, $to, $subject, $message, $company_name = "", $attachment = "", $account_id, $reseller_id) {
1179
-        $send_mail_details = array('from' => $from,
1180
-            'to' => $to,
1181
-            'subject' => $subject,
1182
-            'body' => $message,
1183
-            'accountid' => $account_id,
1184
-            'status' => '1',
1185
-            'attachment' => $attachment,
1186
-            'reseller_id' => $reseller_id,
1187
-        );
1167
+		$account_id = (isset($accountinfo['last_id']) && $accountinfo['last_id'] != "") ? $accountinfo['last_id'] : $accountinfo['id'];
1168
+		$reseller_id = $accountinfo['reseller_id'];
1169
+		if ($reseller_id != "0") {
1170
+			$reseller_result = $this->CI->db_model->getSelect("email", "accounts", array("id" => $reseller_id));
1171
+			$reseller_info = (array)$reseller_result->first_row();
1172
+			$settings_reply_email = $reseller_info['email'];
1173
+		}
1174
+		$this->emailFunction($settings_reply_email, $useremail, $subject, $message, $company_name, $attachment, $account_id, $reseller_id);
1175
+
1176
+	}
1177
+
1178
+	function emailFunction($from, $to, $subject, $message, $company_name = "", $attachment = "", $account_id, $reseller_id) {
1179
+		$send_mail_details = array('from' => $from,
1180
+			'to' => $to,
1181
+			'subject' => $subject,
1182
+			'body' => $message,
1183
+			'accountid' => $account_id,
1184
+			'status' => '1',
1185
+			'attachment' => $attachment,
1186
+			'reseller_id' => $reseller_id,
1187
+		);
1188 1188
                 
1189
-        $this->CI->db->insert('mail_details', $send_mail_details);
1190
-        return $this->CI->db->insert_id();
1191
-    }
1189
+		$this->CI->db->insert('mail_details', $send_mail_details);
1190
+		return $this->CI->db->insert_id();
1191
+	}
1192 1192
 
1193
-    /*
1193
+	/*
1194 1194
       convert GMT id 0000 condition
1195 1195
      */
1196 1196
 
1197
-    function convert_GMT_to($select = "", $table = "", $date) {
1198
-        if ($date == '0000-00-00 00:00:00') {
1199
-            return $date;
1200
-        } else {
1201
-            return $this->CI->timezone->display_GMT($date);
1202
-        }
1203
-    }
1204
-
1205
-    function convert_GMT($date) {
1206
-        return $this->CI->timezone->convert_to_GMT($select = "", $table = "", $date);
1207
-    }
1208
-
1209
-    function convert_to_ucfirst($select = "", $table = "", $str_value) {
1210
-        return ucfirst($str_value);
1211
-    }
1212
-
1213
-    function set_charge_type($status = '') {
1214
-        $status_array = array('1' => 'Accounts', '2' => 'Rate Group');
1215
-        return $status_array;
1216
-    }
1217
-
1218
-    function build_concat_string($select, $table, $id_where = '') {
1219
-        $select_params = explode(',', $select);
1220
-        $where = array("1");
1221
-        if ($id_where != '') {
1222
-            $where = array("id" => $id_where);
1223
-        }
1224
-        $select_params = explode(',', $select);
1225
-        if (isset($select_params[3])) {
1226
-            $cnt_str = " $select_params[0],' ',$select_params[1],' ','(',$select_params[2],')' ";
1227
-        } else {
1228
-            $cnt_str = " $select_params[0],' (',$select_params[1],')' ";
1229
-        }
1230
-        $select = "concat($cnt_str) as $select_params[0] ";
1231
-        $drp_array = $this->CI->db_model->getSelect($select, $table, $where);
1232
-        $drp_array = $drp_array->result();
1233
-        if (isset($drp_array[0]))
1234
-            return $drp_array[0]->$select_params[0];
1235
-    }
1236
-
1237
-    /* 
1197
+	function convert_GMT_to($select = "", $table = "", $date) {
1198
+		if ($date == '0000-00-00 00:00:00') {
1199
+			return $date;
1200
+		} else {
1201
+			return $this->CI->timezone->display_GMT($date);
1202
+		}
1203
+	}
1204
+
1205
+	function convert_GMT($date) {
1206
+		return $this->CI->timezone->convert_to_GMT($select = "", $table = "", $date);
1207
+	}
1208
+
1209
+	function convert_to_ucfirst($select = "", $table = "", $str_value) {
1210
+		return ucfirst($str_value);
1211
+	}
1212
+
1213
+	function set_charge_type($status = '') {
1214
+		$status_array = array('1' => 'Accounts', '2' => 'Rate Group');
1215
+		return $status_array;
1216
+	}
1217
+
1218
+	function build_concat_string($select, $table, $id_where = '') {
1219
+		$select_params = explode(',', $select);
1220
+		$where = array("1");
1221
+		if ($id_where != '') {
1222
+			$where = array("id" => $id_where);
1223
+		}
1224
+		$select_params = explode(',', $select);
1225
+		if (isset($select_params[3])) {
1226
+			$cnt_str = " $select_params[0],' ',$select_params[1],' ','(',$select_params[2],')' ";
1227
+		} else {
1228
+			$cnt_str = " $select_params[0],' (',$select_params[1],')' ";
1229
+		}
1230
+		$select = "concat($cnt_str) as $select_params[0] ";
1231
+		$drp_array = $this->CI->db_model->getSelect($select, $table, $where);
1232
+		$drp_array = $drp_array->result();
1233
+		if (isset($drp_array[0]))
1234
+			return $drp_array[0]->$select_params[0];
1235
+	}
1236
+
1237
+	/* 
1238 1238
      * Change invoice_total to invoice details 
1239 1239
      */
1240 1240
 
1241
-    function get_invoice_total($select = '', $table = '', $id) {
1242
-        $where_arr = array('invoiceid' => $id, 'item_type <>' => "FREE");
1243
-        $this->CI->db->where($where_arr);
1244
-        $this->CI->db->select('*');
1245
-        $result = $this->CI->db->get('invoice_details');
1246
-        if ($result->num_rows() > 0) {
1247
-            $result = $result->result_array();
1248
-	    if($select == 'debit'){
1241
+	function get_invoice_total($select = '', $table = '', $id) {
1242
+		$where_arr = array('invoiceid' => $id, 'item_type <>' => "FREE");
1243
+		$this->CI->db->where($where_arr);
1244
+		$this->CI->db->select('*');
1245
+		$result = $this->CI->db->get('invoice_details');
1246
+		if ($result->num_rows() > 0) {
1247
+			$result = $result->result_array();
1248
+		if($select == 'debit'){
1249 1249
 		if($result[0]['item_type'] == 'POSTCHARG'){
1250
-	            return $this->convert_to_currency('', '', $result[0]['debit']);
1250
+				return $this->convert_to_currency('', '', $result[0]['debit']);
1251 1251
 		}else{
1252
-	            return $this->convert_to_currency('', '', $result[0]['credit']);
1252
+				return $this->convert_to_currency('', '', $result[0]['credit']);
1253 1253
 		}
1254
-	    }else{
1254
+		}else{
1255 1255
 		   return $result[0][$select];
1256
-	    }
1257
-        } else {
1258
-            return null;
1259
-        }
1260
-    }
1261
-
1262
-    function get_array($select, $table_name, $where = false) {
1263
-        $new_array = array();
1264
-        $select_params = array();
1265
-        $select_params = explode(",", $select);
1266
-        if (isset($select_params[3])) {
1267
-            $cnt_str = " $select_params[1],'(',$select_params[2],' ',$select_params[3],')' ";
1268
-            $select = "concat($cnt_str) as $select_params[3] ";
1269
-            $field_name = $select_params[3];
1270
-        } elseif (isset($select_params[2])) {
1271
-            $cnt_str = " $select_params[1],' ','(',$select_params[2],')' ";
1272
-            $select = "concat($cnt_str) as $select_params[2] ";
1273
-            $field_name = $select_params[2];
1274
-        } else {
1275
-            $select = $select_params[1];
1276
-            $field_name = $select_params[1];
1277
-        }
1278
-        if ($where) {
1279
-            $this->CI->db->where($where);
1280
-        }
1281
-        $this->CI->db->select("$select_params[0],$select", false);
1282
-        $result = $this->CI->db->get($table_name);
1283
-        foreach ($result->result_array() as $key => $value) {
1284
-            $new_array[$value[$select_params[0]]] = $value[$field_name];
1285
-        }
1286
-        ksort($new_array);
1287
-        return $new_array;
1288
-    }
1289
-
1290
-    function get_timezone_offset() {
1291
-        $gmtoffset = 0;
1292
-        $accountinfo = $this->CI->session->userdata('accountinfo');
1293
-        $account_result = $this->CI->db->get_where('accounts', array('id' => $accountinfo['id']));
1294
-        $account_result = $account_result->result_array();
1295
-        $accountinfo = $account_result[0];
1296
-        $timezone_id_arr = array($accountinfo['timezone_id']);
1297
-        $this->CI->db->where_in('id', $timezone_id_arr);
1298
-        $this->CI->db->select('gmtoffset');
1299
-        $this->CI->db->from('timezone');
1300
-        $timezone_result = $this->CI->db->get();
1301
-        if ($timezone_result->num_rows() > 0) {
1302
-
1303
-            $timezone_result = $timezone_result->result_array();
1304
-            foreach ($timezone_result as $data) {
1305
-                $gmtoffset+=$data['gmtoffset'];
1306
-            }
1307
-        }
1256
+		}
1257
+		} else {
1258
+			return null;
1259
+		}
1260
+	}
1261
+
1262
+	function get_array($select, $table_name, $where = false) {
1263
+		$new_array = array();
1264
+		$select_params = array();
1265
+		$select_params = explode(",", $select);
1266
+		if (isset($select_params[3])) {
1267
+			$cnt_str = " $select_params[1],'(',$select_params[2],' ',$select_params[3],')' ";
1268
+			$select = "concat($cnt_str) as $select_params[3] ";
1269
+			$field_name = $select_params[3];
1270
+		} elseif (isset($select_params[2])) {
1271
+			$cnt_str = " $select_params[1],' ','(',$select_params[2],')' ";
1272
+			$select = "concat($cnt_str) as $select_params[2] ";
1273
+			$field_name = $select_params[2];
1274
+		} else {
1275
+			$select = $select_params[1];
1276
+			$field_name = $select_params[1];
1277
+		}
1278
+		if ($where) {
1279
+			$this->CI->db->where($where);
1280
+		}
1281
+		$this->CI->db->select("$select_params[0],$select", false);
1282
+		$result = $this->CI->db->get($table_name);
1283
+		foreach ($result->result_array() as $key => $value) {
1284
+			$new_array[$value[$select_params[0]]] = $value[$field_name];
1285
+		}
1286
+		ksort($new_array);
1287
+		return $new_array;
1288
+	}
1289
+
1290
+	function get_timezone_offset() {
1291
+		$gmtoffset = 0;
1292
+		$accountinfo = $this->CI->session->userdata('accountinfo');
1293
+		$account_result = $this->CI->db->get_where('accounts', array('id' => $accountinfo['id']));
1294
+		$account_result = $account_result->result_array();
1295
+		$accountinfo = $account_result[0];
1296
+		$timezone_id_arr = array($accountinfo['timezone_id']);
1297
+		$this->CI->db->where_in('id', $timezone_id_arr);
1298
+		$this->CI->db->select('gmtoffset');
1299
+		$this->CI->db->from('timezone');
1300
+		$timezone_result = $this->CI->db->get();
1301
+		if ($timezone_result->num_rows() > 0) {
1302
+
1303
+			$timezone_result = $timezone_result->result_array();
1304
+			foreach ($timezone_result as $data) {
1305
+				$gmtoffset+=$data['gmtoffset'];
1306
+			}
1307
+		}
1308 1308
 // 	  echo $gmtoffset;exit;
1309
-        return $gmtoffset;
1310
-    }
1311
-    /** Version 2.1
1312
-     * Purpose : Set default data for new created profile
1313
-     * */
1314
-    function sip_profile_date() {
1315
-        $defualt_profile_data = '{"rtp_ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"false","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"default","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false"}';
1316
-        return $defualt_profile_data;
1317
-    }
1309
+		return $gmtoffset;
1310
+	}
1311
+	/** Version 2.1
1312
+	 * Purpose : Set default data for new created profile
1313
+	 * */
1314
+	function sip_profile_date() {
1315
+		$defualt_profile_data = '{"rtp_ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"false","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"default","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false"}';
1316
+		return $defualt_profile_data;
1317
+	}
1318 1318
 
1319
-    /* ===================================================================== */
1320
-    /*
1319
+	/* ===================================================================== */
1320
+	/*
1321 1321
      * Purpose : Add following for mass mail and mail history
1322 1322
      * Version 2.1
1323 1323
      */
1324 1324
 
1325
-    function set_search_temp($select = '') {
1326
-        $status_array = array("0" => "--Select--",
1327
-            "1" => "Voip account refilled",
1328
-            "3" => "Email add user",
1329
-            "4" => "Add sip device",
1330
-            "8" => "Email add did",
1331
-            "9" => "Email remove did",
1332
-            "10" => "Email new invoice",
1333
-            "11" => "Email low balance",
1334
-            "12" => "Email signup confirmation",
1335
-            "13" => "Password successfully changed",
1336
-            "14" => "Reset your password",
1337
-            "15" => "Email add subscription",
1338
-            "16" => "Email remove subscription",
1339
-            "17" => "Email add package",
1340
-            "18" => "Email remove package",
1341
-            "19" => "Voip child accont refilled",
1342
-        );
1343
-        return $status_array;
1344
-    }
1345
-
1346
-    /*     ***
1325
+	function set_search_temp($select = '') {
1326
+		$status_array = array("0" => "--Select--",
1327
+			"1" => "Voip account refilled",
1328
+			"3" => "Email add user",
1329
+			"4" => "Add sip device",
1330
+			"8" => "Email add did",
1331
+			"9" => "Email remove did",
1332
+			"10" => "Email new invoice",
1333
+			"11" => "Email low balance",
1334
+			"12" => "Email signup confirmation",
1335
+			"13" => "Password successfully changed",
1336
+			"14" => "Reset your password",
1337
+			"15" => "Email add subscription",
1338
+			"16" => "Email remove subscription",
1339
+			"17" => "Email add package",
1340
+			"18" => "Email remove package",
1341
+			"19" => "Voip child accont refilled",
1342
+		);
1343
+		return $status_array;
1344
+	}
1345
+
1346
+	/*     ***
1347 1347
       Refill coupon dropdown
1348 1348
      * ** */
1349 1349
 
1350
-    function set_refill_coupon_status($select = '', $table = '', $status = '') {
1351
-        $refill_coupon_array = array("" => "--Select--", '2' => 'Yes', '0' => 'No');
1352
-        return $refill_coupon_array;
1353
-    }
1350
+	function set_refill_coupon_status($select = '', $table = '', $status = '') {
1351
+		$refill_coupon_array = array("" => "--Select--", '2' => 'Yes', '0' => 'No');
1352
+		return $refill_coupon_array;
1353
+	}
1354 1354
 
1355
-    function get_refill_coupon_status($select = '', $table = '', $status) {
1356
-        $refill_coupon_array = array('0' => 'Inactive', '1' => 'Active', '2' => 'Inuse', "3" => "Expired");
1357
-        return $refill_coupon_array[$status];
1358
-    }
1355
+	function get_refill_coupon_status($select = '', $table = '', $status) {
1356
+		$refill_coupon_array = array('0' => 'Inactive', '1' => 'Active', '2' => 'Inuse', "3" => "Expired");
1357
+		return $refill_coupon_array[$status];
1358
+	}
1359 1359
 
1360
-    function firstused_check($select = '', $table = '', $status) {
1360
+	function firstused_check($select = '', $table = '', $status) {
1361 1361
 
1362
-        if ($status == '0000-00-00 00:00:00') {
1363
-            return '-';
1364
-        }
1365
-        return $status;
1366
-    }
1362
+		if ($status == '0000-00-00 00:00:00') {
1363
+			return '-';
1364
+		}
1365
+		return $status;
1366
+	}
1367 1367
 
1368
-    function get_refill_coupon_used($select = '', $table = '', $status) {
1369
-        return $status['status'] == 2 ? '<img src= "'.base_url().'assets/images/true.png" style="height:20px;width:20px;" title="Yes">' : '<img src= "'. base_url().'/assets/images/false.png" style="height:20px;width:20px;" title="No">';
1370
-    }
1368
+	function get_refill_coupon_used($select = '', $table = '', $status) {
1369
+		return $status['status'] == 2 ? '<img src= "'.base_url().'assets/images/true.png" style="height:20px;width:20px;" title="Yes">' : '<img src= "'. base_url().'/assets/images/false.png" style="height:20px;width:20px;" title="No">';
1370
+	}
1371 1371
 
1372
-    /*     * *******
1372
+	/*     * *******
1373 1373
       Password encode decode
1374 1374
      * ******* */
1375 1375
 
1376
-    function encode_params($string) {
1377
-        $data = base64_encode($string);
1378
-        $data = str_replace(array('+', '/', '='), array('-', '$', ''), $data);
1379
-        return $data;
1380
-    }
1381
-
1382
-    function encode($value) {
1383
-        $text = $value;
1384
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1385
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1386
-        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $text, MCRYPT_MODE_ECB, $iv);
1387
-        return trim($this->encode_params($crypttext));
1388
-    }
1389
-
1390
-    function decode_params($string) {
1391
-        $data = str_replace(array('-', '$'), array('+', '/'), $string);
1392
-        $mod4 = strlen($data) % 4;
1393
-        if ($mod4) {
1394
-            $data .= substr('====', $mod4);
1395
-        }
1396
-        return base64_decode($data);
1397
-    }
1398
-
1399
-    function decode($value) {
1400
-        $crypttext = $this->decode_params($value);
1401
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1402
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1403
-        $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $crypttext, MCRYPT_MODE_ECB, $iv);
1404
-        return trim($decrypttext);
1405
-    }
1406
-
1407
-    /******
1376
+	function encode_params($string) {
1377
+		$data = base64_encode($string);
1378
+		$data = str_replace(array('+', '/', '='), array('-', '$', ''), $data);
1379
+		return $data;
1380
+	}
1381
+
1382
+	function encode($value) {
1383
+		$text = $value;
1384
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1385
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1386
+		$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $text, MCRYPT_MODE_ECB, $iv);
1387
+		return trim($this->encode_params($crypttext));
1388
+	}
1389
+
1390
+	function decode_params($string) {
1391
+		$data = str_replace(array('-', '$'), array('+', '/'), $string);
1392
+		$mod4 = strlen($data) % 4;
1393
+		if ($mod4) {
1394
+			$data .= substr('====', $mod4);
1395
+		}
1396
+		return base64_decode($data);
1397
+	}
1398
+
1399
+	function decode($value) {
1400
+		$crypttext = $this->decode_params($value);
1401
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1402
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1403
+		$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $crypttext, MCRYPT_MODE_ECB, $iv);
1404
+		return trim($decrypttext);
1405
+	}
1406
+
1407
+	/******
1408 1408
       Recording enable/disable dropdown
1409 1409
      * ** */
1410 1410
 
1411
-    function set_recording($status = '') {
1412
-        $status_array = array('0' => 'On', '1' => 'Off',);
1413
-        return $status_array;
1414
-    }
1411
+	function set_recording($status = '') {
1412
+		$status_array = array('0' => 'On', '1' => 'Off',);
1413
+		return $status_array;
1414
+	}
1415 1415
 
1416
-    /*     * ************************** */
1416
+	/*     * ************************** */
1417 1417
 
1418
-    function email_status($select = "", $table = "", $status) {
1419
-        $status = ($status['status'] == 0) ? "Sent" : "Not Sent";
1418
+	function email_status($select = "", $table = "", $status) {
1419
+		$status = ($status['status'] == 0) ? "Sent" : "Not Sent";
1420 1420
 	return $status;    
1421
-    }
1421
+	}
1422 1422
 
1423
-    function email_search_status($select = '') {
1424
-        $status_array = array("" => "--Select--",
1425
-            "0" => "Sent",
1426
-            "1" => "Not Sent"
1427
-        );
1428
-        return $status_array;
1429
-    }
1423
+	function email_search_status($select = '') {
1424
+		$status_array = array("" => "--Select--",
1425
+			"0" => "Sent",
1426
+			"1" => "Not Sent"
1427
+		);
1428
+		return $status_array;
1429
+	}
1430 1430
 
1431
-    /* ===================================================================== */
1431
+	/* ===================================================================== */
1432 1432
 
1433 1433
 
1434
-    /*
1434
+	/*
1435 1435
      * Purpose : Add following for setting page
1436 1436
      * Version 2.1
1437 1437
      */
1438 1438
 
1439
-    function paypal_status($status = '') {
1440
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1441
-        return $status_array;
1442
-    }
1443
-    function playback_audio_notification($status = '') {
1444
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1445
-        return $status_array;
1446
-    }
1447
-    function custom_status($status){
1439
+	function paypal_status($status = '') {
1440
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1441
+		return $status_array;
1442
+	}
1443
+	function playback_audio_notification($status = '') {
1444
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1445
+		return $status_array;
1446
+	}
1447
+	function custom_status($status){
1448 1448
 		$status_array = array('0' => 'Yes', '1' => 'No');
1449
-        return $status_array;
1450
-    }
1449
+		return $status_array;
1450
+	}
1451 1451
     
1452
-    function custom_status_active($status){
1453
-      $status_array = array('0' => 'Active', '1' => 'InActive');
1454
-      return $status_array;
1455
-    }
1456
-    function custom_status_true($status){
1457
-      $status_array = array('0' => 'TRUE', '1' => 'FALSE');
1458
-      return $status_array;
1459
-    }
1460
-    function custom_status_voicemail($status){
1461
-      $status_array = array('true' => 'True', 'false' => 'False');
1462
-      return $status_array;
1463
-    }
1464
-
1465
-    /******
1452
+	function custom_status_active($status){
1453
+	  $status_array = array('0' => 'Active', '1' => 'InActive');
1454
+	  return $status_array;
1455
+	}
1456
+	function custom_status_true($status){
1457
+	  $status_array = array('0' => 'TRUE', '1' => 'FALSE');
1458
+	  return $status_array;
1459
+	}
1460
+	function custom_status_voicemail($status){
1461
+	  $status_array = array('true' => 'True', 'false' => 'False');
1462
+	  return $status_array;
1463
+	}
1464
+
1465
+	/******
1466 1466
       For enable Signup module
1467 1467
      * */
1468
-    function create_sipdevice($status = '') {
1469
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1470
-        return $status_array;
1471
-    }
1468
+	function create_sipdevice($status = '') {
1469
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1470
+		return $status_array;
1471
+	}
1472 1472
 
1473
-    function enable_signup($status = '') {
1474
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1475
-        return $status_array;
1476
-    }
1473
+	function enable_signup($status = '') {
1474
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1475
+		return $status_array;
1476
+	}
1477 1477
 
1478 1478
 	function balance_announce($status = '') {
1479
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1480
-        return $status_array;
1481
-    }
1479
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1480
+		return $status_array;
1481
+	}
1482 1482
 	function minutes_announce($status = '') {
1483
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1484
-        return $status_array;
1485
-    }
1483
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1484
+		return $status_array;
1485
+	}
1486 1486
 	
1487
-    function enable_disable_option(){
1488
-        $option_array = array('0' => 'Enable', '1' => 'Disable');
1489
-        return $option_array;
1490
-    }
1491
-
1492
-    function paypal_mode($status = '') {
1493
-        $status_array = array('0' => 'Live', '1' => 'Sandbox',);
1494
-        return $status_array;
1495
-    }
1496
-
1497
-    function paypal_fee($status = '') {
1498
-        $status_array = array('0' => 'Paid By Admin', '1' => 'Paid By Customer',);
1499
-        return $status_array;
1500
-    }
1501
-
1502
-    function email() {
1503
-        $status_array = array('1' => 'Enable', '0' => 'Disable',);
1504
-        return $status_array;
1505
-    }
1506
-
1507
-    function smtp() {
1508
-        return $this->set_allow();
1509
-    }
1510
-
1511
-    function debug() {
1512
-        $status_array = array('1' => 'Enable', '0' => 'Disable',);
1513
-        return $status_array;
1514
-    }
1515
-    function default_signup_rategroup(){
1516
-        $this->CI->db->select("id,name");
1517
-        $this->CI->db->where("status",0);
1518
-        $this->CI->db->where("reseller_id",0);
1519
-        $pricelist_result=$this->CI->db->get("pricelists")->result_array();
1520
-        $pricelist_arr=array();
1521
-        foreach($pricelist_result as $result){
1522
-            $pricelist_arr[$result['id']]=$result['name'];
1523
-        }
1524
-        return $pricelist_arr;
1487
+	function enable_disable_option(){
1488
+		$option_array = array('0' => 'Enable', '1' => 'Disable');
1489
+		return $option_array;
1490
+	}
1491
+
1492
+	function paypal_mode($status = '') {
1493
+		$status_array = array('0' => 'Live', '1' => 'Sandbox',);
1494
+		return $status_array;
1495
+	}
1496
+
1497
+	function paypal_fee($status = '') {
1498
+		$status_array = array('0' => 'Paid By Admin', '1' => 'Paid By Customer',);
1499
+		return $status_array;
1500
+	}
1501
+
1502
+	function email() {
1503
+		$status_array = array('1' => 'Enable', '0' => 'Disable',);
1504
+		return $status_array;
1505
+	}
1506
+
1507
+	function smtp() {
1508
+		return $this->set_allow();
1509
+	}
1510
+
1511
+	function debug() {
1512
+		$status_array = array('1' => 'Enable', '0' => 'Disable',);
1513
+		return $status_array;
1514
+	}
1515
+	function default_signup_rategroup(){
1516
+		$this->CI->db->select("id,name");
1517
+		$this->CI->db->where("status",0);
1518
+		$this->CI->db->where("reseller_id",0);
1519
+		$pricelist_result=$this->CI->db->get("pricelists")->result_array();
1520
+		$pricelist_arr=array();
1521
+		foreach($pricelist_result as $result){
1522
+			$pricelist_arr[$result['id']]=$result['name'];
1523
+		}
1524
+		return $pricelist_arr;
1525 1525
         
1526
-    }
1527
-    /******
1526
+	}
1527
+	/******
1528 1528
       Enable Fax feature
1529 1529
      * */
1530
-    function outbound_fax() {
1531
-        $status_array = array('0' => 'Enable', '1' => 'Disable',);
1532
-        return $status_array;
1533
-    }
1534
-
1535
-    function inbound_fax() {
1536
-        $status_array = array('0' => 'Enable', '1' => 'Disable',);
1537
-        return $status_array;
1538
-    }
1539
-
1540
-
1541
-    function opensips() {
1542
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1543
-        return $status_array;
1544
-    }
1545
-
1546
-    function cc_ani_auth() {
1547
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1548
-        return $status_array;
1549
-    }
1550
-
1551
-    function calling_cards_balance_announce() {
1552
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1553
-        return $status_array;
1554
-    }
1555
-
1556
-    function calling_cards_timelimit_announce() {
1557
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1558
-        return $status_array;
1559
-    }
1560
-
1561
-    function calling_cards_rate_announce() {
1562
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1563
-        return $status_array;
1564
-    }
1565
-
1566
-    function startingdigit() {
1567
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1568
-        return $status_array;
1569
-    }
1570
-
1571
-    function SMPT() {
1572
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1573
-        return $status_array;
1574
-    }
1575
-
1576
-    function country() {
1577
-        return $this->CI->common_model->get_country_list();
1578
-    }
1579
-
1580
-    function default_timezone() {
1581
-        return $this->CI->db_model->build_dropdown('id,gmtzone', 'timezone');
1582
-    }
1583
-
1584
-    function timezone() {
1585
-        return $this->CI->db_model->build_dropdown('gmttime,gmttime', 'timezone');
1586
-    }
1587
-
1588
-    function base_currency() {
1589
-        return $this->CI->db_model->build_dropdown('currency,currencyname', 'currency');
1590
-    }
1591
-
1592
-    /******	
1530
+	function outbound_fax() {
1531
+		$status_array = array('0' => 'Enable', '1' => 'Disable',);
1532
+		return $status_array;
1533
+	}
1534
+
1535
+	function inbound_fax() {
1536
+		$status_array = array('0' => 'Enable', '1' => 'Disable',);
1537
+		return $status_array;
1538
+	}
1539
+
1540
+
1541
+	function opensips() {
1542
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1543
+		return $status_array;
1544
+	}
1545
+
1546
+	function cc_ani_auth() {
1547
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1548
+		return $status_array;
1549
+	}
1550
+
1551
+	function calling_cards_balance_announce() {
1552
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1553
+		return $status_array;
1554
+	}
1555
+
1556
+	function calling_cards_timelimit_announce() {
1557
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1558
+		return $status_array;
1559
+	}
1560
+
1561
+	function calling_cards_rate_announce() {
1562
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1563
+		return $status_array;
1564
+	}
1565
+
1566
+	function startingdigit() {
1567
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1568
+		return $status_array;
1569
+	}
1570
+
1571
+	function SMPT() {
1572
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1573
+		return $status_array;
1574
+	}
1575
+
1576
+	function country() {
1577
+		return $this->CI->common_model->get_country_list();
1578
+	}
1579
+
1580
+	function default_timezone() {
1581
+		return $this->CI->db_model->build_dropdown('id,gmtzone', 'timezone');
1582
+	}
1583
+
1584
+	function timezone() {
1585
+		return $this->CI->db_model->build_dropdown('gmttime,gmttime', 'timezone');
1586
+	}
1587
+
1588
+	function base_currency() {
1589
+		return $this->CI->db_model->build_dropdown('currency,currencyname', 'currency');
1590
+	}
1591
+
1592
+	/******	
1593 1593
       Calculate Currency manually.
1594 1594
      */
1595 1595
 
1596
-    function calculate_currency_manually($currency_info, $amount, $show_currency_flag = true,$number_format=true) {
1597
-        $decimal_points = $currency_info['decimalpoints'];
1598
-        $system_currency_rate = $currency_info['base_currency']['currencyrate'];
1599
-        $user_currency_rate = $currency_info['user_currency']['currencyrate'];
1600
-        $calculated_amount=(float)(($amount * $currency_info['user_currency']['currencyrate']) / $currency_info['base_currency']['currencyrate']); 
1601
-        if($number_format){
1602
-         $calculated_amount = number_format($calculated_amount,$currency_info['decimalpoints']);
1603
-        }
1604
-        if ($show_currency_flag){
1605
-          return $calculated_amount." ".$currency_info['user_currency']['currency'];
1606
-        }else{
1607
-          return $calculated_amount;
1608
-        }
1609
-    }
1610
-
1611
-    /*
1596
+	function calculate_currency_manually($currency_info, $amount, $show_currency_flag = true,$number_format=true) {
1597
+		$decimal_points = $currency_info['decimalpoints'];
1598
+		$system_currency_rate = $currency_info['base_currency']['currencyrate'];
1599
+		$user_currency_rate = $currency_info['user_currency']['currencyrate'];
1600
+		$calculated_amount=(float)(($amount * $currency_info['user_currency']['currencyrate']) / $currency_info['base_currency']['currencyrate']); 
1601
+		if($number_format){
1602
+		 $calculated_amount = number_format($calculated_amount,$currency_info['decimalpoints']);
1603
+		}
1604
+		if ($show_currency_flag){
1605
+		  return $calculated_amount." ".$currency_info['user_currency']['currency'];
1606
+		}else{
1607
+		  return $calculated_amount;
1608
+		}
1609
+	}
1610
+
1611
+	/*
1612 1612
       Using By Summary Report search
1613 1613
      */
1614 1614
 
1615
-    function search_report_in($select = '') {
1616
-        $status_array = array("minutes" => "Minutes", "seconds" => "Seconds");
1617
-        return $status_array;
1618
-    }
1619
-
1620
-    function set_summarycustomer_groupby($status = '') {
1621
-        $status_array = array('' => "--Select--", 'accountid' => 'Account', 'pattern' => 'Code','package_id'=>"Package");
1622
-        return $status_array;
1623
-    }
1624
-
1625
-    function set_summaryprovider_groupby($status = '') {
1626
-        $status_array = array('' => "--Select--", 'provider_id' => 'Account', 'trunk_id' => "Trunks", 'pattern' => 'Code');
1627
-        return $status_array;
1628
-    }
1629
-
1630
-    function get_currency_info() {
1631
-        //System Currency info 
1632
-        $base_currency = Common_model::$global_config['system_config']['base_currency'];
1633
-        //Get Account Information from session to get currency_id
1634
-        $accountinfo = $this->CI->session->userdata('accountinfo');
1635
-        //Get User Currency id 
1636
-        $user_currency_id = $accountinfo['currency_id'] > 0 ? $accountinfo['currency_id'] : $base_currency;
1637
-        $where = "currency = '" . $base_currency . "' OR id= " . $user_currency_id;
1638
-        $this->CI->db->where($where);
1639
-        $this->CI->db->select('*');
1640
-        $currency_result = $this->CI->db->get('currency');
1641
-
1642
-        if ($currency_result->num_rows() == 2) {
1643
-            $currency_result = $currency_result->result_array();
1644
-            foreach ($currency_result as $key => $records) {
1645
-                //User Currency is currency details of logged in user.
1646
-                if ($records['id'] == $user_currency_id) {
1647
-                    $currency_info['user_currency'] = $records;
1648
-                }
1649
-                //System Currency is currency details of system.
1650
-                if ($records['currency'] == Common_model::$global_config['system_config']['base_currency']) {
1651
-                    $currency_info['base_currency'] = $records;
1652
-                }
1653
-            }
1654
-        } else if ($currency_result->num_rows() == 1) {
1655
-            $currency_info['user_currency'] = $currency_info['base_currency'] = (array) $currency_result->first_row();
1656
-        }
1657
-        //Get Decimal points as per defined from system.
1658
-        $currency_info['decimalpoints'] = Common_model::$global_config['system_config']['decimalpoints'];
1659
-        return $currency_info;
1660
-    }
1661
-
1662
-    function convert_to_show_in($search_name = "", $table = "", $second) {
1663
-        $search_arr = $this->CI->session->userdata($search_name);
1664
-        $show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1665
-        return ($show_seconds === 'minutes') ? ($second > 0 ) ?
1666
-                        sprintf('%02d',$second / 60) . ":" . sprintf('%02d', ($second % 60)) : "00:00"  : sprintf('%02d', $second);
1667
-    }
1668
-
1669
-    function array_column($input, $columnKey, $indexKey = null) {
1670
-        $array = array();
1671
-        foreach ($input as $value) {
1672
-            if (!isset($value[$columnKey])) {
1673
-                trigger_error("Key \"$columnKey\" does not exist in array");
1674
-                return false;
1675
-            }
1676
-
1677
-            if (is_null($indexKey)) {
1678
-                $array[] = $value[$columnKey];
1679
-            } else {
1680
-                if (!isset($value[$indexKey])) {
1681
-                    trigger_error("Key \"$indexKey\" does not exist in array");
1682
-                    return false;
1683
-                }
1684
-                if (!is_scalar($value[$indexKey])) {
1685
-                    trigger_error("Key \"$indexKey\" does not contain scalar value");
1686
-                    return false;
1687
-                }
1688
-                $array[$value[$indexKey]] = $value[$columnKey];
1689
-            }
1690
-        }
1691
-
1692
-        return $array;
1693
-    }
1694
-
1695
-    function group_by_time() {
1696
-        $status_array = array('' => "--Select--", 'HOUR' => 'Hour', 'DAY' => "Day", 'MONTH' => 'Month', "YEAR" => "Year");
1697
-        return $status_array;
1698
-    }
1699
-
1700
-    function currency_decimal($amount) {
1615
+	function search_report_in($select = '') {
1616
+		$status_array = array("minutes" => "Minutes", "seconds" => "Seconds");
1617
+		return $status_array;
1618
+	}
1619
+
1620
+	function set_summarycustomer_groupby($status = '') {
1621
+		$status_array = array('' => "--Select--", 'accountid' => 'Account', 'pattern' => 'Code','package_id'=>"Package");
1622
+		return $status_array;
1623
+	}
1624
+
1625
+	function set_summaryprovider_groupby($status = '') {
1626
+		$status_array = array('' => "--Select--", 'provider_id' => 'Account', 'trunk_id' => "Trunks", 'pattern' => 'Code');
1627
+		return $status_array;
1628
+	}
1629
+
1630
+	function get_currency_info() {
1631
+		//System Currency info 
1632
+		$base_currency = Common_model::$global_config['system_config']['base_currency'];
1633
+		//Get Account Information from session to get currency_id
1634
+		$accountinfo = $this->CI->session->userdata('accountinfo');
1635
+		//Get User Currency id 
1636
+		$user_currency_id = $accountinfo['currency_id'] > 0 ? $accountinfo['currency_id'] : $base_currency;
1637
+		$where = "currency = '" . $base_currency . "' OR id= " . $user_currency_id;
1638
+		$this->CI->db->where($where);
1639
+		$this->CI->db->select('*');
1640
+		$currency_result = $this->CI->db->get('currency');
1641
+
1642
+		if ($currency_result->num_rows() == 2) {
1643
+			$currency_result = $currency_result->result_array();
1644
+			foreach ($currency_result as $key => $records) {
1645
+				//User Currency is currency details of logged in user.
1646
+				if ($records['id'] == $user_currency_id) {
1647
+					$currency_info['user_currency'] = $records;
1648
+				}
1649
+				//System Currency is currency details of system.
1650
+				if ($records['currency'] == Common_model::$global_config['system_config']['base_currency']) {
1651
+					$currency_info['base_currency'] = $records;
1652
+				}
1653
+			}
1654
+		} else if ($currency_result->num_rows() == 1) {
1655
+			$currency_info['user_currency'] = $currency_info['base_currency'] = (array) $currency_result->first_row();
1656
+		}
1657
+		//Get Decimal points as per defined from system.
1658
+		$currency_info['decimalpoints'] = Common_model::$global_config['system_config']['decimalpoints'];
1659
+		return $currency_info;
1660
+	}
1661
+
1662
+	function convert_to_show_in($search_name = "", $table = "", $second) {
1663
+		$search_arr = $this->CI->session->userdata($search_name);
1664
+		$show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1665
+		return ($show_seconds === 'minutes') ? ($second > 0 ) ?
1666
+						sprintf('%02d',$second / 60) . ":" . sprintf('%02d', ($second % 60)) : "00:00"  : sprintf('%02d', $second);
1667
+	}
1668
+
1669
+	function array_column($input, $columnKey, $indexKey = null) {
1670
+		$array = array();
1671
+		foreach ($input as $value) {
1672
+			if (!isset($value[$columnKey])) {
1673
+				trigger_error("Key \"$columnKey\" does not exist in array");
1674
+				return false;
1675
+			}
1676
+
1677
+			if (is_null($indexKey)) {
1678
+				$array[] = $value[$columnKey];
1679
+			} else {
1680
+				if (!isset($value[$indexKey])) {
1681
+					trigger_error("Key \"$indexKey\" does not exist in array");
1682
+					return false;
1683
+				}
1684
+				if (!is_scalar($value[$indexKey])) {
1685
+					trigger_error("Key \"$indexKey\" does not contain scalar value");
1686
+					return false;
1687
+				}
1688
+				$array[$value[$indexKey]] = $value[$columnKey];
1689
+			}
1690
+		}
1691
+
1692
+		return $array;
1693
+	}
1694
+
1695
+	function group_by_time() {
1696
+		$status_array = array('' => "--Select--", 'HOUR' => 'Hour', 'DAY' => "Day", 'MONTH' => 'Month', "YEAR" => "Year");
1697
+		return $status_array;
1698
+	}
1699
+
1700
+	function currency_decimal($amount) {
1701 1701
 		$amount = str_replace( ',', '', $amount );
1702
-        $decimal_amount = Common_model::$global_config['system_config']['decimalpoints'];
1703
-        $number_convert = number_format((float) $amount, $decimal_amount, '.', '');
1704
-        return $number_convert;
1705
-    }
1706
-
1707
-    function add_invoice_details($account_arr, $charge_type, $amount,$description) {
1708
-        $accountinfo = $this->CI->session->userdata('accountinfo');
1709
-        $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
1710
-        $where = "accountid IN ('" . $reseller_id . "','1')";
1711
-        $this->CI->db->where($where);
1712
-        $this->CI->db->select('*');
1713
-        $this->CI->db->order_by('accountid', 'desc');
1714
-        $this->CI->db->limit(1);
1715
-        $invoiceconf = $this->CI->db->get('invoice_conf');
1716
-        $invoice_conf = (array) $invoiceconf->first_row();
1717
-        $last_invoiceid = $this->get_invoice_date('invoiceid', '', $account_arr['reseller_id']);
1718
-        if ($last_invoiceid && $last_invoiceid > 0) {
1719
-            $last_invoiceid = ($last_invoiceid + 1);
1720
-        } else {
1721
-            $last_invoiceid = $invoice_conf['invoice_start_from'];
1722
-        }
1723
-        $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
1724
-        $invoice_prefix = $invoice_conf['invoice_prefix'];
1725
-        $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoice_conf['interval'] . " days"));
1726
-        $invoiceid = $account_arr['posttoexternal'] == 0 ? $this->CI->common_model->generate_receipt($account_arr['id'], $amount, $account_arr, $last_invoiceid, $invoice_prefix, $due_date) : 0;
1702
+		$decimal_amount = Common_model::$global_config['system_config']['decimalpoints'];
1703
+		$number_convert = number_format((float) $amount, $decimal_amount, '.', '');
1704
+		return $number_convert;
1705
+	}
1706
+
1707
+	function add_invoice_details($account_arr, $charge_type, $amount,$description) {
1708
+		$accountinfo = $this->CI->session->userdata('accountinfo');
1709
+		$reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
1710
+		$where = "accountid IN ('" . $reseller_id . "','1')";
1711
+		$this->CI->db->where($where);
1712
+		$this->CI->db->select('*');
1713
+		$this->CI->db->order_by('accountid', 'desc');
1714
+		$this->CI->db->limit(1);
1715
+		$invoiceconf = $this->CI->db->get('invoice_conf');
1716
+		$invoice_conf = (array) $invoiceconf->first_row();
1717
+		$last_invoiceid = $this->get_invoice_date('invoiceid', '', $account_arr['reseller_id']);
1718
+		if ($last_invoiceid && $last_invoiceid > 0) {
1719
+			$last_invoiceid = ($last_invoiceid + 1);
1720
+		} else {
1721
+			$last_invoiceid = $invoice_conf['invoice_start_from'];
1722
+		}
1723
+		$last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
1724
+		$invoice_prefix = $invoice_conf['invoice_prefix'];
1725
+		$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoice_conf['interval'] . " days"));
1726
+		$invoiceid = $account_arr['posttoexternal'] == 0 ? $this->CI->common_model->generate_receipt($account_arr['id'], $amount, $account_arr, $last_invoiceid, $invoice_prefix, $due_date) : 0;
1727 1727
         
1728
-        $insert_arr = array("accountid" => $account_arr['id'],
1729
-            "description" => $description,
1730
-            "debit" => $amount,
1731
-            "credit" => '0',
1732
-            "created_date" => gmdate("Y-m-d H:i:s"),
1733
-            "invoiceid" => $invoiceid,
1734
-            "reseller_id" => $account_arr['reseller_id'],
1735
-            "item_type" => $charge_type,
1736
-            "item_id" => '0',
1737
-        );
1738
-        $this->CI->db->insert("invoice_details", $insert_arr);
1739
-        return true;
1740
-    }
1741
-    /* ASTPP  3.0  Remove all information related to going to delete customer.
1728
+		$insert_arr = array("accountid" => $account_arr['id'],
1729
+			"description" => $description,
1730
+			"debit" => $amount,
1731
+			"credit" => '0',
1732
+			"created_date" => gmdate("Y-m-d H:i:s"),
1733
+			"invoiceid" => $invoiceid,
1734
+			"reseller_id" => $account_arr['reseller_id'],
1735
+			"item_type" => $charge_type,
1736
+			"item_id" => '0',
1737
+		);
1738
+		$this->CI->db->insert("invoice_details", $insert_arr);
1739
+		return true;
1740
+	}
1741
+	/* ASTPP  3.0  Remove all information related to going to delete customer.
1742 1742
      */
1743
-    function customer_delete_dependencies($id){
1744
-          $this->delete_data('ani_map',array('accountid'=>$id));
1745
-          $this->delete_data('block_patterns',array('accountid'=>$id));
1746
-          $this->delete_data('charge_to_account',array('accountid'=>$id));
1747
-          $this->delete_data('counters',array('accountid'=>$id));
1748
-          $this->delete_data('ip_map',array('accountid'=>$id));
1749
-          $this->delete_data('sip_devices',array('accountid'=>$id));
1750
-          $this->delete_data('speed_dial',array('accountid'=>$id));
1751
-          $this->delete_data('taxes_to_accounts',array('accountid'=>$id));
1752
-          $this->delete_data('mail_details',array('accountid'=>$id));
1753
-          $this->update_data('dids',array("accountid"=>$id),array('accountid'=>0));
1754
-          $this->update_data("accounts",array("id"=>$id),array("deleted"=>1));
1755
-    }
1756
-    /*
1743
+	function customer_delete_dependencies($id){
1744
+		  $this->delete_data('ani_map',array('accountid'=>$id));
1745
+		  $this->delete_data('block_patterns',array('accountid'=>$id));
1746
+		  $this->delete_data('charge_to_account',array('accountid'=>$id));
1747
+		  $this->delete_data('counters',array('accountid'=>$id));
1748
+		  $this->delete_data('ip_map',array('accountid'=>$id));
1749
+		  $this->delete_data('sip_devices',array('accountid'=>$id));
1750
+		  $this->delete_data('speed_dial',array('accountid'=>$id));
1751
+		  $this->delete_data('taxes_to_accounts',array('accountid'=>$id));
1752
+		  $this->delete_data('mail_details',array('accountid'=>$id));
1753
+		  $this->update_data('dids',array("accountid"=>$id),array('accountid'=>0));
1754
+		  $this->update_data("accounts",array("id"=>$id),array("deleted"=>1));
1755
+	}
1756
+	/*
1757 1757
      *  ASTPP  3.0 
1758 1758
      *  Remove all information related to going to delete reseller.
1759 1759
      */
1760
-    function reseller_delete_dependencies($id){
1761
-        $accountinfo=$this->CI->session->userdata('accountinfo');
1762
-        $child_arr=$this->select_data("accounts",array("reseller_id"=>$id,"type"=>0),'id,reseller_id');
1763
-        if($child_arr){
1764
-            foreach($child_arr as $value){
1765
-                $this->customer_delete_dependencies($value['id']);
1766
-            }
1767
-        }
1768
-        $package_arr=$this->select_data("packages",array("reseller_id"=>$id),'id');
1769
-        if($package_arr){
1770
-            foreach($package_arr as $value){
1771
-                $this->delete_data('package_patterns',array("id"=>$value['id']));
1772
-            }
1773
-        }
1774
-        $acc_arr=$this->select_data('accounts',array("id"=>$id),'id,reseller_id');
1775
-        $parent_id=0;
1776
-        if($acc_arr){
1777
-            $parent_id=$acc_arr[0]['reseller_id'];
1778
-        }
1779
-        $pricelist_arr=$this->select_data('pricelists',array('reseller_id'=>$id),'id');
1780
-        if($pricelist_arr){
1781
-             foreach($pricelist_arr as $value){
1782
-                $this->delete_data("routing",array("pricelist_id"=>$value['id']));
1783
-                $this->delete_data("routes",array("pricelist_id"=>$value['id']));
1784
-                $this->update_data('pricelists',array('id'=>$value['id']),array('status'=>2));         
1785
-             }
1786
-        }
1787
-        $charge_arr=$this->select_data('charges',array('reseller_id'=>$id),'id');
1788
-        if($charge_arr){
1789
-             foreach($charge_arr as $value){
1790
-                $this->delete_data("charge_to_account",array("charge_id"=>$value['id']));
1791
-             }
1792
-        }
1793
-        $this->delete_data('charges',array('reseller_id'=>$id));
1794
-        $this->update_data('dids',array('parent_id'=>$id),array("parent_id"=>$parent_id));
1795
-        $this->delete_data('reseller_pricing',array("reseller_id"=>$id));
1796
-        $this->delete_data('refill_coupon',array("reseller_id"=>$id));
1797
-        $this->delete_data('mail_details',array('accountid'=>$id));
1798
-        $taxes_arr=$this->select_data('taxes',array("reseller_id"=>$id),'id');
1799
-        if($taxes_arr){
1800
-             foreach($taxes_arr as $value){
1801
-                $this->delete_data("taxes_to_accounts",array("taxes_id"=>$value['id']));
1802
-             }
1803
-        }
1804
-        $this->delete_data('taxes',array("reseller_id"=>$id));
1805
-        $this->delete_data('default_templates',array("reseller_id"=>$id));
1806
-        $package_arr=$this->select_data('packages',array('reseller_id'=>$id),'id');
1807
-        if($package_arr){
1808
-            $this->delete_data("counters",array("package_id"=>$value['id']));
1809
-            $this->delete_data("package_patterns",array("package_id"=>$value['id']));
1810
-        }
1811
-        $this->delete_data('invoice_conf',array('accountid'=>$id));
1812
-        $this->delete_data('packages',array("reseller_id"=>$id));
1813
-        $this->update_data('accounts',array("id"=>$id),array("deleted"=>1));
1814
-    }
1815
-    function subreseller_list($parent_id = '') {
1816
-        $customer_id = $parent_id;
1817
-        $this->reseller_delete_dependencies($parent_id);
1818
-        $query = 'select id,type from accounts where reseller_id = ' . $parent_id .' AND deleted =0';
1819
-        $result = $this->CI->db->query($query);
1820
-        if ($result->num_rows() > 0) {
1821
-            $result = $result->result_array();
1822
-            foreach ($result as $data) {
1823
-	      if($data['type']==1){
1760
+	function reseller_delete_dependencies($id){
1761
+		$accountinfo=$this->CI->session->userdata('accountinfo');
1762
+		$child_arr=$this->select_data("accounts",array("reseller_id"=>$id,"type"=>0),'id,reseller_id');
1763
+		if($child_arr){
1764
+			foreach($child_arr as $value){
1765
+				$this->customer_delete_dependencies($value['id']);
1766
+			}
1767
+		}
1768
+		$package_arr=$this->select_data("packages",array("reseller_id"=>$id),'id');
1769
+		if($package_arr){
1770
+			foreach($package_arr as $value){
1771
+				$this->delete_data('package_patterns',array("id"=>$value['id']));
1772
+			}
1773
+		}
1774
+		$acc_arr=$this->select_data('accounts',array("id"=>$id),'id,reseller_id');
1775
+		$parent_id=0;
1776
+		if($acc_arr){
1777
+			$parent_id=$acc_arr[0]['reseller_id'];
1778
+		}
1779
+		$pricelist_arr=$this->select_data('pricelists',array('reseller_id'=>$id),'id');
1780
+		if($pricelist_arr){
1781
+			 foreach($pricelist_arr as $value){
1782
+				$this->delete_data("routing",array("pricelist_id"=>$value['id']));
1783
+				$this->delete_data("routes",array("pricelist_id"=>$value['id']));
1784
+				$this->update_data('pricelists',array('id'=>$value['id']),array('status'=>2));         
1785
+			 }
1786
+		}
1787
+		$charge_arr=$this->select_data('charges',array('reseller_id'=>$id),'id');
1788
+		if($charge_arr){
1789
+			 foreach($charge_arr as $value){
1790
+				$this->delete_data("charge_to_account",array("charge_id"=>$value['id']));
1791
+			 }
1792
+		}
1793
+		$this->delete_data('charges',array('reseller_id'=>$id));
1794
+		$this->update_data('dids',array('parent_id'=>$id),array("parent_id"=>$parent_id));
1795
+		$this->delete_data('reseller_pricing',array("reseller_id"=>$id));
1796
+		$this->delete_data('refill_coupon',array("reseller_id"=>$id));
1797
+		$this->delete_data('mail_details',array('accountid'=>$id));
1798
+		$taxes_arr=$this->select_data('taxes',array("reseller_id"=>$id),'id');
1799
+		if($taxes_arr){
1800
+			 foreach($taxes_arr as $value){
1801
+				$this->delete_data("taxes_to_accounts",array("taxes_id"=>$value['id']));
1802
+			 }
1803
+		}
1804
+		$this->delete_data('taxes',array("reseller_id"=>$id));
1805
+		$this->delete_data('default_templates',array("reseller_id"=>$id));
1806
+		$package_arr=$this->select_data('packages',array('reseller_id'=>$id),'id');
1807
+		if($package_arr){
1808
+			$this->delete_data("counters",array("package_id"=>$value['id']));
1809
+			$this->delete_data("package_patterns",array("package_id"=>$value['id']));
1810
+		}
1811
+		$this->delete_data('invoice_conf',array('accountid'=>$id));
1812
+		$this->delete_data('packages',array("reseller_id"=>$id));
1813
+		$this->update_data('accounts',array("id"=>$id),array("deleted"=>1));
1814
+	}
1815
+	function subreseller_list($parent_id = '') {
1816
+		$customer_id = $parent_id;
1817
+		$this->reseller_delete_dependencies($parent_id);
1818
+		$query = 'select id,type from accounts where reseller_id = ' . $parent_id .' AND deleted =0';
1819
+		$result = $this->CI->db->query($query);
1820
+		if ($result->num_rows() > 0) {
1821
+			$result = $result->result_array();
1822
+			foreach ($result as $data) {
1823
+		  if($data['type']==1){
1824 1824
 		  $this->reseller_delete_dependencies($data['id']);
1825 1825
 		  $this->subreseller_list($data['id']);
1826
-	      }else{
1826
+		  }else{
1827 1827
 		  $this->customer_delete_dependencies($data['id']);
1828
-	      }
1829
-            }
1830
-        }
1831
-    }
1828
+		  }
1829
+			}
1830
+		}
1831
+	}
1832 1832
     
1833
-    function delete_data($table_name,$where_arr){
1834
-        $this->CI->db->where($where_arr);
1835
-        $this->CI->db->delete($table_name);
1836
-    }
1837
-    function update_data($table_name,$where_arr,$update_arr){
1838
-        $this->CI->db->where($where_arr);
1839
-        $this->CI->db->update($table_name,$update_arr);
1840
-    }
1841
-    function select_data($table_name,$where_arr,$select){
1842
-        $this->CI->db->where($where_arr);
1843
-        $this->CI->db->select($select);
1844
-        $result=$this->CI->db->get($table_name);
1845
-        if($result->num_rows() > 0){
1846
-            return $result->result_array();
1847
-        }else{
1848
-            return false;
1849
-        }
1850
-    }
1833
+	function delete_data($table_name,$where_arr){
1834
+		$this->CI->db->where($where_arr);
1835
+		$this->CI->db->delete($table_name);
1836
+	}
1837
+	function update_data($table_name,$where_arr,$update_arr){
1838
+		$this->CI->db->where($where_arr);
1839
+		$this->CI->db->update($table_name,$update_arr);
1840
+	}
1841
+	function select_data($table_name,$where_arr,$select){
1842
+		$this->CI->db->where($where_arr);
1843
+		$this->CI->db->select($select);
1844
+		$result=$this->CI->db->get($table_name);
1845
+		if($result->num_rows() > 0){
1846
+			return $result->result_array();
1847
+		}else{
1848
+			return false;
1849
+		}
1850
+	}
1851 1851
     
1852
-    function set_call_waiting($status = '') {
1852
+	function set_call_waiting($status = '') {
1853 1853
 		$status_array = array('0' => 'Enable', '1' => 'Disable');
1854 1854
 		return $status_array;
1855 1855
 	} 
1856
-    function get_call_waiting($select = "", $table = "", $status) {
1857
-        return ($status == 0) ? "Enable" : "Disable";
1856
+	function get_call_waiting($select = "", $table = "", $status) {
1857
+		return ($status == 0) ? "Enable" : "Disable";
1858 1858
 	}
1859 1859
   function set_invoice_details($select= ''){
1860
-        $status_array = array("invoice_select" => "--Select--",
1861
-            "invoice_inactive" => "Deleted Invoices",
1862
-            "invoice_active" => "All Invoices",
1863
-        );
1864
-        return $status_array;
1860
+		$status_array = array("invoice_select" => "--Select--",
1861
+			"invoice_inactive" => "Deleted Invoices",
1862
+			"invoice_active" => "All Invoices",
1863
+		);
1864
+		return $status_array;
1865 1865
 }
1866 1866
 function get_invoice_template($invoicedata,$accountdata,$flag){
1867
-      $login_info = $this->CI->session->userdata('accountinfo');
1868
-
1869
-      $invoice_config = $this->CI->db_model->getSelect("*", "invoice_conf", array('accountid'=>$login_info['id']));
1870
-      $invoice_config= $invoice_config->result_array();
1871
-      $invoice_config_res= $invoice_config[0];
1872
-
1873
-      $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $accountdata["currency_id"]);
1874
-      $accountdata["country"] = $this->get_field_name('country', 'countrycode', $accountdata["country_id"]);
1875
-      $data["to_currency"] = Common_model::$global_config['system_config']['base_currency'];
1876
-      if($login_info['type'] == -1){
1877
-          $currency = $data["to_currency"];
1878
-      }elseif($login_info['type'] == 1){
1867
+	  $login_info = $this->CI->session->userdata('accountinfo');
1868
+
1869
+	  $invoice_config = $this->CI->db_model->getSelect("*", "invoice_conf", array('accountid'=>$login_info['id']));
1870
+	  $invoice_config= $invoice_config->result_array();
1871
+	  $invoice_config_res= $invoice_config[0];
1872
+
1873
+	  $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $accountdata["currency_id"]);
1874
+	  $accountdata["country"] = $this->get_field_name('country', 'countrycode', $accountdata["country_id"]);
1875
+	  $data["to_currency"] = Common_model::$global_config['system_config']['base_currency'];
1876
+	  if($login_info['type'] == -1){
1877
+		  $currency = $data["to_currency"];
1878
+	  }elseif($login_info['type'] == 1){
1879 1879
 	  $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $login_info["currency_id"]);
1880
-          $currency = $accountdata["currency_id"];
1881
-      }else{
1882
-          $currency = $accountdata["currency_id"];
1883
-      }
1884
-      $decimal_amount=Common_model::$global_config['system_config']['decimalpoints'];
1885
-      ob_start();
1886
-      $this->CI->load->library('/html2pdf/html2pdf');
1887
-      $this->CI->html2pdf = new HTML2PDF('P','A4','en');
1888
-      $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
1889
-      $template_config=$this->CI->config->item('invoice_template');
1890
-      include($template_config.'invoice_template.php');
1891
-      $content = ob_get_clean();
1892
-      ob_clean();
1880
+		  $currency = $accountdata["currency_id"];
1881
+	  }else{
1882
+		  $currency = $accountdata["currency_id"];
1883
+	  }
1884
+	  $decimal_amount=Common_model::$global_config['system_config']['decimalpoints'];
1885
+	  ob_start();
1886
+	  $this->CI->load->library('/html2pdf/html2pdf');
1887
+	  $this->CI->html2pdf = new HTML2PDF('P','A4','en');
1888
+	  $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
1889
+	  $template_config=$this->CI->config->item('invoice_template');
1890
+	  include($template_config.'invoice_template.php');
1891
+	  $content = ob_get_clean();
1892
+	  ob_clean();
1893 1893
 
1894 1894
 	$ACCOUNTADD = '';
1895 1895
 	$ACCOUNTADD_CUSTOMER ='';
@@ -1912,57 +1912,57 @@  discard block
 block discarded – undo
1912 1912
 	$due_date =date("Y-m-d",$duedate);
1913 1913
 
1914 1914
 /*************************** Company Address Code START ***************************************************/
1915
-        $ACCOUNTADD .= '<tr>';
1916
-        $ACCOUNTADD .= '<td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>'.$invoice_config_res['company_name'].'</b></td>';
1917
-        $ACCOUNTADD .= '</tr>';
1915
+		$ACCOUNTADD .= '<tr>';
1916
+		$ACCOUNTADD .= '<td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>'.$invoice_config_res['company_name'].'</b></td>';
1917
+		$ACCOUNTADD .= '</tr>';
1918 1918
 	if ( $invoice_config_res['address'] != ""){
1919 1919
 
1920
-        $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['address'].'</td></tr>';
1921
-    }
1920
+		$ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['address'].'</td></tr>';
1921
+	}
1922 1922
 	if ( $invoice_config_res['city'] != ""){
1923 1923
 
1924
-        $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['city'].'</td></tr>';
1925
-    }
1924
+		$ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['city'].'</td></tr>';
1925
+	}
1926 1926
 	if ( $invoice_config_res['province'] != ""){
1927 1927
 
1928
-        $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['province'].'</td></tr>';
1929
-    }
1928
+		$ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['province'].'</td></tr>';
1929
+	}
1930 1930
 	if ( $invoice_config_res['country'] != ""){
1931 1931
 
1932
-        $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['country'].'</td></tr>';
1933
-    }
1932
+		$ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['country'].'</td></tr>';
1933
+	}
1934 1934
 	if ( $invoice_config_res['zipcode'] != ""){
1935 1935
 
1936
-        $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['zipcode'].'</td></tr>';
1937
-    }
1936
+		$ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['zipcode'].'</td></tr>';
1937
+	}
1938 1938
 /*************************** Company Address Code END ***************************************************/
1939 1939
 
1940 1940
 /*************************** Customer Address Code START ***************************************************/
1941 1941
 
1942
-        $ACCOUNTADD_CUSTOMER .= '<table><tr>';
1943
-        $ACCOUNTADD_CUSTOMER .= '<td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>'.$accountdata['company_name'].'</b></td></tr>';
1942
+		$ACCOUNTADD_CUSTOMER .= '<table><tr>';
1943
+		$ACCOUNTADD_CUSTOMER .= '<td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>'.$accountdata['company_name'].'</b></td></tr>';
1944 1944
 
1945 1945
 	if ( $accountdata['address_1'] != ""){
1946 1946
 
1947
-        $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['address_1'].'</td></tr>';
1948
-    }
1947
+		$ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['address_1'].'</td></tr>';
1948
+	}
1949 1949
 	if ( $accountdata['city'] != ""){
1950 1950
 
1951
-        $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['city'].'</td></tr>';
1952
-    }
1951
+		$ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['city'].'</td></tr>';
1952
+	}
1953 1953
 	if ( $accountdata['province'] != ""){
1954 1954
 
1955
-        $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['province'].'</td></tr>';
1956
-    }
1955
+		$ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['province'].'</td></tr>';
1956
+	}
1957 1957
 	if ( $accountdata['country'] != ""){
1958 1958
 
1959
-        $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['country'].'</td></tr>';
1960
-    }
1959
+		$ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['country'].'</td></tr>';
1960
+	}
1961 1961
 	if ( $accountdata['postal_code'] != ""){
1962 1962
 
1963
-        $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['postal_code'].'</td></tr>';
1964
-    }
1965
-    $ACCOUNTADD_CUSTOMER .="</table>"; 
1963
+		$ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['postal_code'].'</td></tr>';
1964
+	}
1965
+	$ACCOUNTADD_CUSTOMER .="</table>"; 
1966 1966
 /*************************** Customer Address Code END ***************************************************/
1967 1967
 
1968 1968
 
@@ -1970,26 +1970,26 @@  discard block
 block discarded – undo
1970 1970
 
1971 1971
  	$ACCOUNT_DESCRIPTION .= '<tr style="background-color:#375C7C;">';
1972 1972
 	$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Date</td>';
1973
-        $ACCOUNT_DESCRIPTION .= '<td  style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Description</td>';
1974
-        $ACCOUNT_DESCRIPTION .= '<td  style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Charge Type</td>';
1973
+		$ACCOUNT_DESCRIPTION .= '<td  style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Description</td>';
1974
+		$ACCOUNT_DESCRIPTION .= '<td  style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Charge Type</td>';
1975 1975
 	$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;text-align:right;">Amount ('.$currency .')</td>';
1976
-        $ACCOUNT_DESCRIPTION .= '</tr>';
1976
+		$ACCOUNT_DESCRIPTION .= '</tr>';
1977 1977
 
1978 1978
 
1979 1979
 	$ACCOUNT_CDRS .= '<tr style="background-color:#375C7C;">';
1980 1980
 	$ACCOUNT_CDRS .= '<td style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Description</td>';
1981 1981
 	$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Duration (Seconds)</td>';
1982
-        $ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Total Calls</td>';
1982
+		$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Total Calls</td>';
1983 1983
 	$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;text-align:right;">Amount ('.$currency .')</td>';
1984
-        $ACCOUNT_CDRS .= '</tr>';
1984
+		$ACCOUNT_CDRS .= '</tr>';
1985 1985
 
1986 1986
 	/*** manual invoice **/
1987 1987
 	$this->CI->db->where('item_type <>','INVPAY');
1988
-        $invoice_details = $this->CI->db_model->getSelect('*', 'invoice_details',array("invoiceid"=> $invoicedata['id'],'item_type <>'=> 'TAX' ));
1988
+		$invoice_details = $this->CI->db_model->getSelect('*', 'invoice_details',array("invoiceid"=> $invoicedata['id'],'item_type <>'=> 'TAX' ));
1989 1989
 	$invoice_details= $invoice_details->result_array();
1990 1990
 	$total_sum=0;
1991 1991
 	foreach($invoice_details as $charge_res){
1992
-	    if($charge_res['item_type'] == 'DIDCHRG' || $charge_res['item_type'] == 'SUBCHRG' || $charge_res['item_type'] == 'manual_inv' ){
1992
+		if($charge_res['item_type'] == 'DIDCHRG' || $charge_res['item_type'] == 'SUBCHRG' || $charge_res['item_type'] == 'manual_inv' ){
1993 1993
 		if($charge_res['item_type'] == 'manual_inv'){
1994 1994
 			$charge_res['item_type'] = 'Manual Invoice';
1995 1995
 		}
@@ -2007,10 +2007,10 @@  discard block
 block discarded – undo
2007 2007
 
2008 2008
 		$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($this->CI->common_model->calculate_currency($charge_res['debit'])).'</td>';
2009 2009
 		$ACCOUNT_DESCRIPTION .= '</tr>';
2010
-	     }else{
2011
-            $cdrs_data = $this->CI->db_model->getSelect("sum(billseconds) as billseconds,count(*) as count", "cdrs", array("accountid" => $charge_res['accountid'],"calltype" => $charge_res['item_type']));
2012
-            $cdrs_result = $cdrs_data->result_array();
2013
-	    if($cdrs_result[0]['count'] > 0 ){
2010
+		 }else{
2011
+			$cdrs_data = $this->CI->db_model->getSelect("sum(billseconds) as billseconds,count(*) as count", "cdrs", array("accountid" => $charge_res['accountid'],"calltype" => $charge_res['item_type']));
2012
+			$cdrs_result = $cdrs_data->result_array();
2013
+		if($cdrs_result[0]['count'] > 0 ){
2014 2014
 		$cdrs_record_count=$cdrs_result[0]['count'] ;
2015 2015
 		$cdrs_record_billseconds=$cdrs_result[0]['billseconds'] ;
2016 2016
 /*echo '<pre>'.$cdrs_record_count;
@@ -2022,8 +2022,8 @@  discard block
 block discarded – undo
2022 2022
 		$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$cdrs_record_count.'</td>';
2023 2023
 		$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($this->CI->common_model->calculate_currency($charge_res['debit'])).'</td>';
2024 2024
 		$ACCOUNT_CDRS .= '</tr>';
2025
-	     }
2026
-	    }
2025
+		 }
2026
+		}
2027 2027
 		$total_sum += $charge_res['debit'];
2028 2028
 	}
2029 2029
 /*************************** Charge Histry Code END ***************************************************/
@@ -2031,7 +2031,7 @@  discard block
 block discarded – undo
2031 2031
 /**********************************Tax Apply Start********************************************************************/
2032 2032
 	$total_sum = $total_sum;
2033 2033
 	$total_sum=$this->currency_decimal($this->CI->common_model->calculate_currency($total_sum));
2034
-        $invoice_tax = $this->CI->db_model->getSelect('*', 'invoice_details',array("invoiceid"=> $invoicedata['id'],'item_type '=> 'TAX'));
2034
+		$invoice_tax = $this->CI->db_model->getSelect('*', 'invoice_details',array("invoiceid"=> $invoicedata['id'],'item_type '=> 'TAX'));
2035 2035
  	//$ACCOUNT_TOTAL .= '<td><table style="width:100%;margin-left:360px;">';
2036 2036
 
2037 2037
 	$ACCOUNT_TOTAL .= '<tr>';
@@ -2039,7 +2039,7 @@  discard block
 block discarded – undo
2039 2039
 	$ACCOUNT_TOTAL .= '<td style="width:40%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
2040 2040
 //        $ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"><b>Total Exclusive:</b></td>';
2041 2041
 //	$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$total_sum .'</td>';
2042
-        $ACCOUNT_TOTAL .= '</tr>';
2042
+		$ACCOUNT_TOTAL .= '</tr>';
2043 2043
 
2044 2044
 	if($invoice_tax->num_rows() > 0 ){
2045 2045
 	   foreach($invoice_tax->result_array() as $invoice_tax){
@@ -2077,16 +2077,16 @@  discard block
 block discarded – undo
2077 2077
 
2078 2078
 /*************************** Invoice Details Code START ***************************************************/
2079 2079
 
2080
-        $ACCOUNTADD_RIGHT .= '<table style="width:100%;"><tr style="width:100%;"><td style="width:40%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>Number:</b></td>';
2081
-        $ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#525252;font-family:arial;text-align:right; line-height: 22px;">'.$invoicedata["invoice_prefix"].$invoicedata["invoiceid"].'</td></tr>';
2080
+		$ACCOUNTADD_RIGHT .= '<table style="width:100%;"><tr style="width:100%;"><td style="width:40%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>Number:</b></td>';
2081
+		$ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#525252;font-family:arial;text-align:right; line-height: 22px;">'.$invoicedata["invoice_prefix"].$invoicedata["invoiceid"].'</td></tr>';
2082 2082
 
2083
-        $ACCOUNTADD_RIGHT .= '<tr style="width:100%;"><td style="width:40%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>Date:</b></td>';
2084
-        $ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#525252;font-family:arial;text-align:right; line-height: 22px;">'.$from_date.'</td></tr>';
2085
-        $ACCOUNTADD_RIGHT .= '<tr style="width:100%;"><td style="width:40%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>Due Date:</b></td>';
2086
-        $ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#525252;font-family:arial;text-align:right; line-height: 22px;">'.$due_date.'</td></tr>';
2083
+		$ACCOUNTADD_RIGHT .= '<tr style="width:100%;"><td style="width:40%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>Date:</b></td>';
2084
+		$ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#525252;font-family:arial;text-align:right; line-height: 22px;">'.$from_date.'</td></tr>';
2085
+		$ACCOUNTADD_RIGHT .= '<tr style="width:100%;"><td style="width:40%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>Due Date:</b></td>';
2086
+		$ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#525252;font-family:arial;text-align:right; line-height: 22px;">'.$due_date.'</td></tr>';
2087 2087
 
2088
-        $ACCOUNTADD_RIGHT .= '<tr style="background-color:#375C7C;width:100%; line-height: 30px;"><td style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 30px;"><b>Total Due:</b></td>';
2089
-        $ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#fff;font-family:arial;text-align:right; line-height: 30px;">'.$this->currency_decimal($sub_total).'</td></tr>';
2088
+		$ACCOUNTADD_RIGHT .= '<tr style="background-color:#375C7C;width:100%; line-height: 30px;"><td style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 30px;"><b>Total Due:</b></td>';
2089
+		$ACCOUNTADD_RIGHT .= '<td style="width:60%;font-size: 10px;color:#fff;font-family:arial;text-align:right; line-height: 30px;">'.$this->currency_decimal($sub_total).'</td></tr>';
2090 2090
 	$ACCOUNTADD_RIGHT .= "</table>";
2091 2091
 
2092 2092
 /*************************** Invoice Details Code END ***************************************************/
@@ -2097,8 +2097,8 @@  discard block
 block discarded – undo
2097 2097
 
2098 2098
 
2099 2099
 /*************************** Invoice Note Code END ***************************************************/
2100
-        $invoice_notes = $this->CI->db_model->getSelect('*', 'invoices', array('id'=>$invoicedata['id']));
2101
-        $invoice_notes=$invoice_notes->result_array();
2100
+		$invoice_notes = $this->CI->db_model->getSelect('*', 'invoices', array('id'=>$invoicedata['id']));
2101
+		$invoice_notes=$invoice_notes->result_array();
2102 2102
 	if(isset($invoice_notes[0]['notes'])){
2103 2103
 		$invoice_notes=$invoice_notes[0]['notes'];
2104 2104
 	}else{
@@ -2125,106 +2125,106 @@  discard block
 block discarded – undo
2125 2125
 	$ACCOUNT_TOTAL_FINAL .= '<td style="width:40%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
2126 2126
 	$ACCOUNT_TOTAL_FINAL .= '</tr>';
2127 2127
 
2128
-      //  $content = str_replace("<LOGO>",$image_logo,$content);   
2129
-        $content = str_replace("<ACCOUNTADD>",$ACCOUNTADD,$content);
2130
-        $content = str_replace("<ACCOUNTADD_CUSTOMER>",$ACCOUNTADD_CUSTOMER,$content);
2131
-        $content = str_replace("<ACCOUNTADD_RIGHT>",$ACCOUNTADD_RIGHT,$content);
2128
+	  //  $content = str_replace("<LOGO>",$image_logo,$content);   
2129
+		$content = str_replace("<ACCOUNTADD>",$ACCOUNTADD,$content);
2130
+		$content = str_replace("<ACCOUNTADD_CUSTOMER>",$ACCOUNTADD_CUSTOMER,$content);
2131
+		$content = str_replace("<ACCOUNTADD_RIGHT>",$ACCOUNTADD_RIGHT,$content);
2132 2132
 	$content = str_replace("<ACCOUNT_DESCRIPTION>",$ACCOUNT_DESCRIPTION,$content);
2133 2133
 	$content = str_replace("<ACCOUNT_CDRS>",$ACCOUNT_CDRS,$content);
2134 2134
 	$content = str_replace("<ACCOUNT_TOTAL>",$ACCOUNT_TOTAL,$content);
2135 2135
 	$content = str_replace("<ACCOUNT_TOTAL_FINAL>",$ACCOUNT_TOTAL_FINAL,$content);
2136
-        $content = str_replace("<NOTES>",$invoice_notes,$content);
2136
+		$content = str_replace("<NOTES>",$invoice_notes,$content);
2137 2137
 
2138 2138
 //echo $content; exit;
2139 2139
 
2140 2140
 	$invoice_path=$this->CI->config->item('invoices_path');
2141 2141
 	$download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; 
2142
-       //echo  $download_path; exit;
2143
-       $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
2144
-       $this->CI->html2pdf->writeHTML($content);
2142
+	   //echo  $download_path; exit;
2143
+	   $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
2144
+	   $this->CI->html2pdf->writeHTML($content);
2145 2145
        
2146
-       if($flag== 'TRUE'){
2147
-        $download_path = $invoicedata['invoice_prefix'].$invoicedata['invoiceid'].".pdf";
2146
+	   if($flag== 'TRUE'){
2147
+		$download_path = $invoicedata['invoice_prefix'].$invoicedata['invoiceid'].".pdf";
2148 2148
        
2149
-        $this->CI->html2pdf->Output($download_path,"D");        
2150
-       }else{
2151
-        $current_dir = getcwd()."/invoices/";
2152
-        $dir_name = $accountdata["id"];
2153
-        if(!is_dir($current_dir.$dir_name)){
2154
-                mkdir($current_dir.$dir_name,0777, true);
2155
-                chmod($current_dir.$dir_name, 0777);        
2156
-        }        
2157
-        $invoice_path=$this->CI->config->item('invoices_path');
2158
-        $download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; 
2159
-        $this->CI->html2pdf->Output($download_path,"F");         
2160
-       }
2149
+		$this->CI->html2pdf->Output($download_path,"D");        
2150
+	   }else{
2151
+		$current_dir = getcwd()."/invoices/";
2152
+		$dir_name = $accountdata["id"];
2153
+		if(!is_dir($current_dir.$dir_name)){
2154
+				mkdir($current_dir.$dir_name,0777, true);
2155
+				chmod($current_dir.$dir_name, 0777);        
2156
+		}        
2157
+		$invoice_path=$this->CI->config->item('invoices_path');
2158
+		$download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; 
2159
+		$this->CI->html2pdf->Output($download_path,"F");         
2160
+	   }
2161 2161
 }
2162
-    function reseller_select_value($select, $table, $id_where = '') {
2163
-        $select_params = explode(',', $select);
2164
-        $where = array("1");
2165
-        if ($id_where != '') {
2166
-            $where = array("id" => $id_where);
2167
-        }
2168
-        $select_params = explode(',', $select);
2169
-        $cnt_str = " $select_params[0],' ',$select_params[1],' ','(',$select_params[2],')' ";
2170
-        $select = "concat($cnt_str) as $select_params[2] ";
2171
-        $drp_array = $this->CI->db_model->getSelect($select, $table, $where);
2172
-        $drp_array = $drp_array->result();
2173
-        if (isset($drp_array[0]))
2174
-            return $drp_array[0]->$select_params[2];
2162
+	function reseller_select_value($select, $table, $id_where = '') {
2163
+		$select_params = explode(',', $select);
2164
+		$where = array("1");
2165
+		if ($id_where != '') {
2166
+			$where = array("id" => $id_where);
2167
+		}
2168
+		$select_params = explode(',', $select);
2169
+		$cnt_str = " $select_params[0],' ',$select_params[1],' ','(',$select_params[2],')' ";
2170
+		$select = "concat($cnt_str) as $select_params[2] ";
2171
+		$drp_array = $this->CI->db_model->getSelect($select, $table, $where);
2172
+		$drp_array = $drp_array->result();
2173
+		if (isset($drp_array[0]))
2174
+			return $drp_array[0]->$select_params[2];
2175 2175
 	else
2176 2176
 	   return 'Admin';
2177
-    }
2177
+	}
2178 2178
     
2179
-    function get_subreseller_info($parent_id){
2180
-        if(!empty($parent_id)){
2179
+	function get_subreseller_info($parent_id){
2180
+		if(!empty($parent_id)){
2181 2181
 	  $str=$parent_id.",";
2182
-        }else{
2183
-          $str=null;
2184
-        }
2185
-        $query = "select id from accounts where reseller_id = '$parent_id' AND deleted =0 AND type=1";
2186
-        $result = $this->CI->db->query($query);
2187
-        if($result->num_rows() > 0){
2188
-        $result = $result->result_array();
2182
+		}else{
2183
+		  $str=null;
2184
+		}
2185
+		$query = "select id from accounts where reseller_id = '$parent_id' AND deleted =0 AND type=1";
2186
+		$result = $this->CI->db->query($query);
2187
+		if($result->num_rows() > 0){
2188
+		$result = $result->result_array();
2189 2189
 	  foreach ($result as $data){
2190
-	    if(!empty($data['id'])){
2191
-	      $str.=$this->get_subreseller_info($data['id']);
2192
-	    }
2190
+		if(!empty($data['id'])){
2191
+		  $str.=$this->get_subreseller_info($data['id']);
2192
+		}
2193 2193
 	  }
2194 2194
 	}
2195 2195
 	return $str;
2196
-    }
2197
-    function get_parent_info($child_id,$parent_id){
2198
-        if(!empty($child_id)){
2196
+	}
2197
+	function get_parent_info($child_id,$parent_id){
2198
+		if(!empty($child_id)){
2199 2199
 	  $str=$child_id.",";
2200
-        }else{
2201
-          $str=null;
2202
-        }
2203
-        if($child_id > 0){
2204
-        $query = "select reseller_id from accounts where id = '$child_id'";
2205
-        $result = $this->CI->db->query($query);
2206
-        if($result->num_rows() > 0){
2207
-        $parent_info = (array)$result->first_row();
2200
+		}else{
2201
+		  $str=null;
2202
+		}
2203
+		if($child_id > 0){
2204
+		$query = "select reseller_id from accounts where id = '$child_id'";
2205
+		$result = $this->CI->db->query($query);
2206
+		if($result->num_rows() > 0){
2207
+		$parent_info = (array)$result->first_row();
2208 2208
 	  if($parent_info['reseller_id'] != $parent_id){
2209
-	    $str.=$this->get_parent_info($parent_info['reseller_id'],$parent_id);
2209
+		$str.=$this->get_parent_info($parent_info['reseller_id'],$parent_id);
2210 2210
 	  }
2211 2211
 	}
2212 2212
 	}
2213 2213
 	return $str;
2214
-    }
2215
-    function get_did_accountid($select,$table,$where){
2216
-      $accountinfo=$this->CI->session->userdata('accountinfo');
2217
-      $this->CI->db->where('note',$where);
2218
-      $this->CI->db->where('parent_id',$accountinfo['id']);
2219
-      $this->CI->db->select('reseller_id');
2220
-      $reseller_pricing_result=$this->CI->db->get('reseller_pricing');
2221
-      $account_info=(array)$reseller_pricing_result->first_row();
2222
-      $account_name=$this->get_field_name_coma_new('first_name,last_name,number','accounts',$account_info['reseller_id']);
2223
-      return $account_name;     
2224
-    }
2225
-
2226
-    function get_status_new($select = "",$table = "",$status = "") {
2227
-      return ($status['status']==0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
2228
-    }
2214
+	}
2215
+	function get_did_accountid($select,$table,$where){
2216
+	  $accountinfo=$this->CI->session->userdata('accountinfo');
2217
+	  $this->CI->db->where('note',$where);
2218
+	  $this->CI->db->where('parent_id',$accountinfo['id']);
2219
+	  $this->CI->db->select('reseller_id');
2220
+	  $reseller_pricing_result=$this->CI->db->get('reseller_pricing');
2221
+	  $account_info=(array)$reseller_pricing_result->first_row();
2222
+	  $account_name=$this->get_field_name_coma_new('first_name,last_name,number','accounts',$account_info['reseller_id']);
2223
+	  return $account_name;     
2224
+	}
2225
+
2226
+	function get_status_new($select = "",$table = "",$status = "") {
2227
+	  return ($status['status']==0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
2228
+	}
2229 2229
     
2230 2230
 }
Please login to merge, or discard this patch.
Spacing   +425 added lines, -425 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 23
 ###############################################################################
24 24
 
25
-if (!defined('BASEPATH'))
25
+if ( ! defined('BASEPATH'))
26 26
     exit('No direct script access allowed');
27 27
 
28 28
 /**
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if ($tablename == 'accounts' && $start_prifix_value != 0) {
89 89
             $length = strlen($start_prifix_value);
90 90
             $uname = substr($uname, $length);
91
-            $uname = $start_prifix_value . $uname;
91
+            $uname = $start_prifix_value.$uname;
92 92
         }
93 93
         return $uname;
94 94
     }
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
             $uname = $this->random_string($length);
114 114
             $uname = strtolower($uname);
115 115
             if (isset($default))
116
-                $uname = $default . $uname;
117
-            if (!in_array($uname, $number)) {
116
+                $uname = $default.$uname;
117
+            if ( ! in_array($uname, $number)) {
118 118
                 $where = array($field => $uname);
119 119
                 $acc_result = $this->CI->db_model->getSelect('Count(id) as count', $tablename, $where);
120 120
                 $acc_result = $acc_result->result_array();
121
-                if ($acc_result[0]['count'] == 0 && !in_array($uname, $number)) {
121
+                if ($acc_result[0]['count'] == 0 && ! in_array($uname, $number)) {
122 122
                     $number[] = $uname;
123 123
                     $j++;
124 124
                 }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             $where = array($select => $where);
141 141
         }
142 142
         $field_name = $this->CI->db_model->countQuery($select, $table, $where);
143
-        if (isset($field_name) && !empty($field_name)) {
143
+        if (isset($field_name) && ! empty($field_name)) {
144 144
             return $field_name;
145 145
         } else {
146 146
             return "0";
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
         }
156 156
         $field_name = $this->CI->db_model->getSelect($select, $table, $where);
157 157
         $field_name = $field_name->result();
158
-        if (isset($field_name) && !empty($field_name)) {
158
+        if (isset($field_name) && ! empty($field_name)) {
159 159
             return $field_name[0]->$select;
160 160
         } else {
161 161
             return "";
@@ -175,12 +175,12 @@  discard block
 block discarded – undo
175 175
 
176 176
             $field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
177 177
             $field_name = $field_name->result();
178
-            if (isset($field_name) && !empty($field_name)) {
178
+            if (isset($field_name) && ! empty($field_name)) {
179 179
                 foreach ($select1 as $sel) {
180 180
                     if ($sel == 'number') {
181
-                        $value.="(" . $field_name[0]->$sel . ")";
181
+                        $value .= "(".$field_name[0]->$sel.")";
182 182
                     } else {
183
-                        $value.= $field_name[0]->$sel . " ";
183
+                        $value .= $field_name[0]->$sel." ";
184 184
                     }
185 185
                 }
186 186
             } else {
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
         $where = array("number" => $where);
197 197
         $field_name = $this->CI->db_model->getSelect("id,accountid,parent_id", 'dids', $where);
198 198
         $field_name = $field_name->result();
199
-        if (isset($field_name) && !empty($field_name)) {
199
+        if (isset($field_name) && ! empty($field_name)) {
200 200
             if (isset($field_name[0]) && $accountinfo['type'] != 1) {
201
-                if ($field_name[0]->accountid != 0 && $field_name[0]->parent_id ==0) {
202
-                    $flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
201
+                if ($field_name[0]->accountid != 0 && $field_name[0]->parent_id == 0) {
202
+                    $flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
203 203
                 } else if ($field_name[0]->parent_id != 0) {
204
-                    $flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
204
+                    $flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
205 205
                 } else {
206 206
                     $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
207 207
                 }
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
                 $field_name_re = $this->CI->db_model->getSelect("reseller_id", 'reseller_pricing', $where);
212 212
                 $field_name_re = $field_name_re->result();
213 213
 
214
-                if (isset($field_name_re) && !empty($field_name_re)) {
215
-                    $flag_status = "<a href='../did_list_release/" . $field_name[0]->id . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
214
+                if (isset($field_name_re) && ! empty($field_name_re)) {
215
+                    $flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
216 216
                 } else {
217 217
                     $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
218 218
                 }
@@ -222,32 +222,32 @@  discard block
 block discarded – undo
222 222
         }
223 223
         return $flag_status;
224 224
     }
225
-    function check_did_avl_export($number){
226
-      $this->CI->db->where('number',$number);
225
+    function check_did_avl_export($number) {
226
+      $this->CI->db->where('number', $number);
227 227
       $this->CI->db->select('id,accountid,parent_id');
228
-      $status=null;
229
-      $did_info=(array)$this->CI->db->get('dids')->first_row();
230
-      $accountinfo=$this->CI->session->userdata('accountinfo');
231
-      if($did_info['accountid'] ==0 && $did_info['parent_id']==0){
232
-	$status='Not in use';
228
+      $status = null;
229
+      $did_info = (array)$this->CI->db->get('dids')->first_row();
230
+      $accountinfo = $this->CI->session->userdata('accountinfo');
231
+      if ($did_info['accountid'] == 0 && $did_info['parent_id'] == 0) {
232
+	$status = 'Not in use';
233 233
       }
234
-      elseif($accountinfo['type'] !=1){
235
-	if($did_info['accountid'] ==0 && $did_info['parent_id'] > 0){
236
-	  $status='Purchase by Reseller';
234
+      elseif ($accountinfo['type'] != 1) {
235
+	if ($did_info['accountid'] == 0 && $did_info['parent_id'] > 0) {
236
+	  $status = 'Purchase by Reseller';
237 237
 	}
238
-	if($did_info['accountid'] > 0 && $did_info['parent_id'] == 0){
239
-	  $status='Purchase by Customer';
238
+	if ($did_info['accountid'] > 0 && $did_info['parent_id'] == 0) {
239
+	  $status = 'Purchase by Customer';
240 240
 	}
241
-      }else{
242
-       $where_arr=array('note'=>$did_info['number'],"parent_id"=>$accountinfo['id']);
241
+      } else {
242
+       $where_arr = array('note'=>$did_info['number'], "parent_id"=>$accountinfo['id']);
243 243
        $this->db->where($where);
244 244
        $this->CI->db->select('reseller_id,parent_id');
245 245
        $reseller_pricing = (array)$this->db->get('reseller_pricing')->first_row();
246
-       if($reseller_pricing['reseller_id']==0 && $did_info['accountid']==0 && $did_info['parent_id']==$accountinfo['id']){
247
-        $status='Not in use';
246
+       if ($reseller_pricing['reseller_id'] == 0 && $did_info['accountid'] == 0 && $did_info['parent_id'] == $accountinfo['id']) {
247
+        $status = 'Not in use';
248 248
        }
249
-       if($reseller_pricing['reseller_id']==0 && $did_info['accountid']==0){
250
-       $status='Not in use';
249
+       if ($reseller_pricing['reseller_id'] == 0 && $did_info['accountid'] == 0) {
250
+       $status = 'Not in use';
251 251
        }
252 252
       }
253 253
       return $status;
@@ -256,24 +256,24 @@  discard block
 block discarded – undo
256 256
     function check_did_avl_reseller($select, $table, $where) {
257 257
         $accountinfo = $this->CI->session->userdata('accountinfo');
258 258
         $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
259
-        $this->CI->db->where('number',$where);
259
+        $this->CI->db->where('number', $where);
260 260
         $this->CI->db->select('id,accountid,parent_id,number');
261
-        $did_info=(array)$this->CI->db->get('dids')->first_row();
262
-        if($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']){
263
-	    $flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
261
+        $did_info = (array)$this->CI->db->get('dids')->first_row();
262
+        if ($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']) {
263
+	    $flag_status = "<a href='../did_list_release/".$did_info['id']."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
264 264
 	}
265
-        else if($accountinfo['type']!=1 && $did_info['parent_id'] != $accountinfo['id']){
266
-	    $flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
267
-        }else{
268
-	    $reseller_id= $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
269
-	    $where = array("note" => $did_info['number'],'parent_id'=>$reseller_id);
265
+        else if ($accountinfo['type'] != 1 && $did_info['parent_id'] != $accountinfo['id']) {
266
+	    $flag_status = "<a href='../did_list_release/".$did_info['id']."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
267
+        } else {
268
+	    $reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
269
+	    $where = array("note" => $did_info['number'], 'parent_id'=>$reseller_id);
270 270
             $this->CI->db->where($where);
271 271
 	    $this->CI->db->select('reseller_id,id');
272
-	    $reseller_pricing_info=(array)$this->CI->db->get('reseller_pricing')->first_row();
273
-	    if (isset($reseller_pricing_info) && !empty($reseller_pricing_info)) {
274
-		  $flag_status="<a href='../did/did_reseller_edit/delete/".$reseller_pricing_info['id']."' title='Reliase' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
275
-	    }else{
276
-	      $flag_status="<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
272
+	    $reseller_pricing_info = (array)$this->CI->db->get('reseller_pricing')->first_row();
273
+	    if (isset($reseller_pricing_info) && ! empty($reseller_pricing_info)) {
274
+		  $flag_status = "<a href='../did/did_reseller_edit/delete/".$reseller_pricing_info['id']."' title='Reliase' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
275
+	    } else {
276
+	      $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
277 277
 	    }
278 278
         }
279 279
         return $flag_status;
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 
293 293
             $field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
294 294
             $field_name = $field_name->result();
295
-            if (isset($field_name) && !empty($field_name)) {
296
-                $value.= $field_name[0]->$select . ",";
295
+            if (isset($field_name) && ! empty($field_name)) {
296
+                $value .= $field_name[0]->$select.",";
297 297
             } else {
298 298
                 $value = "";
299 299
             }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
             if (isset($uri_segment[3])) {
326 326
                 return $week_arr;
327 327
             } else {
328
-                $week_drp = form_dropdown(array("name" => 'invoice_day','style'=>"width: 100% !important;" , "class" => "invoice_day"), $week_arr, $day);
328
+                $week_drp = form_dropdown(array("name" => 'invoice_day', 'style'=>"width: 100% !important;", "class" => "invoice_day"), $week_arr, $day);
329 329
                 return $week_drp;
330 330
             }
331 331
         }
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                 return $mon_arr;
338 338
             } else {
339 339
                 $day = $invoice_date > 0 ? $invoice_date : date('d');
340
-                $month_drp = form_dropdown(array("name" => 'invoice_day',"class" => "width_dropdown invoice_day"), $mon_arr, $day);
340
+                $month_drp = form_dropdown(array("name" => 'invoice_day', "class" => "width_dropdown invoice_day"), $mon_arr, $day);
341 341
                 return $month_drp;
342 342
             }
343 343
         }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
     }
350 350
 
351 351
     function set_routetype($status = '') {
352
-        $status_array = array( '0' => 'LCR','1' => 'COST',);
352
+        $status_array = array('0' => 'LCR', '1' => 'COST',);
353 353
         return $status_array;
354 354
     }
355 355
 
@@ -378,12 +378,12 @@  discard block
 block discarded – undo
378 378
         $status_array = array('1' => 'Yes', '0' => 'No');
379 379
         return $status_array;
380 380
     }
381
-    function set_pin_allow($status=''){
382
-        $status_array = array('0' => 'Disable','1' => 'Enable');
381
+    function set_pin_allow($status = '') {
382
+        $status_array = array('0' => 'Disable', '1' => 'Enable');
383 383
         return $status_array;
384 384
     }
385
-    function set_pin_allow_customer($status=''){
386
-        $status_array = array('0' => 'No','1' => 'Yes');
385
+    function set_pin_allow_customer($status = '') {
386
+        $status_array = array('0' => 'No', '1' => 'Yes');
387 387
         return $status_array;
388 388
     }
389 389
     function get_allow($select = "", $table = "", $status) {
@@ -391,20 +391,20 @@  discard block
 block discarded – undo
391 391
     }
392 392
 
393 393
     function set_call_type($call_type = "") {
394
-        $call_type_array = array("-1" => "--Select--",'1' => 'DID-Local',"3"=>"SIP-DID", '0' => 'PSTN',  '2' => 'Other',);
394
+        $call_type_array = array("-1" => "--Select--", '1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other',);
395 395
         return $call_type_array;
396 396
     }
397
-    function set_call_type_search(){
398
-	$call_type_array = array("" => "--Select--",'1' => 'DID-Local',"3"=>"SIP-DID", '0' => 'PSTN',  '2' => 'Other',);
397
+    function set_call_type_search() {
398
+	$call_type_array = array("" => "--Select--", '1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other',);
399 399
         return $call_type_array;
400 400
     }
401 401
     function get_call_type($select = "", $table = "", $call_type) {
402
-        $call_type_array = array('1' => 'DID-Local',"3"=>"SIP-DID",'0' => 'PSTN',  '2' => 'Other','-1'=>"");
402
+        $call_type_array = array('1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other', '-1'=>"");
403 403
         return $call_type_array[$call_type];
404 404
     }
405 405
 
406 406
     function get_custom_call_type($call_type) {
407
-        $call_type_array = array('DID-Local' => '1',"SIP-DID"=>"3",'PSTN' => '0','Other' => '2',""=>"-1");
407
+        $call_type_array = array('DID-Local' => '1', "SIP-DID"=>"3", 'PSTN' => '0', 'Other' => '2', ""=>"-1");
408 408
         return $call_type_array[$call_type];
409 409
     }
410 410
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
     }
430 430
 
431 431
 	function set_entity_type_email_mass($entity_type = "") {
432
-        $entity_array = array('' => "--Select--", '0' => 'Customer','1'=>'Reseller','3' => "Provider");
432
+        $entity_array = array('' => "--Select--", '0' => 'Customer', '1'=>'Reseller', '3' => "Provider");
433 433
         return $entity_array;
434 434
     }
435 435
 
@@ -466,21 +466,21 @@  discard block
 block discarded – undo
466 466
    show status on all grid
467 467
    */
468 468
    function get_status($select = "", $table = "", $status) {
469
-       if($select !='export'){
470
-        $status_tab=$this->encode($table);
471
-        $status['table']="'".$status_tab."'";
472
-        if($status['status'] == 0){
469
+       if ($select != 'export') {
470
+        $status_tab = $this->encode($table);
471
+        $status['table'] = "'".$status_tab."'";
472
+        if ($status['status'] == 0) {
473 473
 	$status_array = '<div style="width: 100%; text-align: -moz-center; padding: 0;"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id=switch'.$status['id'].' value='.$status['status'].' onclick="javascript:processForm('.$status['id'].','.$status['table'].')" checked>
474 474
 	<label class="onoffswitch-label" for=switch'.$status["id"].'>
475 475
      	<span class="onoffswitch-inner"></span>
476 476
 	</label></div>';
477
-	}else{
477
+	} else {
478 478
 	$status_array = '<div style="width: 100%; text-align: -moz-center; padding: 0;"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id=switch'.$status['id'].' value='.$status['status'].' onclick="javascript:processForm('.$status['id'].','.$status['table'].')">
479 479
 	<label class="onoffswitch-label" for=switch'.$status["id"].'>
480 480
      	<span class="onoffswitch-inner"></span>
481 481
 	</label></div>';
482 482
 	}
483
-	}else{
483
+	} else {
484 484
 		return ($status == 0) ? "Active" : "Inactive";
485 485
 	}
486 486
 	return $status_array;
@@ -494,13 +494,13 @@  discard block
 block discarded – undo
494 494
         return ($status == 0) ? "Yes" : "No";
495 495
     }
496 496
     
497
-    function get_import_status($status){
497
+    function get_import_status($status) {
498 498
      return strtolower(trim($status)) == 'active' ? 0 : 1;
499 499
      
500 500
     }
501
-    function get_did_status($select,$table,$status){
501
+    function get_did_status($select, $table, $status) {
502 502
     
503
-      return ($status['status']==0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
503
+      return ($status['status'] == 0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
504 504
     }
505 505
    
506 506
 
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
         }
512 512
         $invoice_res = $this->CI->db_model->select($select, "invoices", $where, $order_by, "DESC", "1", "0");
513 513
         if ($invoice_res->num_rows > 0) {
514
-            $invoice_info = (array) $invoice_res->first_row();
514
+            $invoice_info = (array)$invoice_res->first_row();
515 515
             return $invoice_info[$select];
516 516
         }
517 517
         return false;
@@ -537,23 +537,23 @@  discard block
 block discarded – undo
537 537
 
538 538
     function convert_to_currency($select = "", $table = "", $amount) {
539 539
         $this->CI->load->model('common_model');
540
-        return $this->CI->common_model->calculate_currency($amount,'','',true,false);
540
+        return $this->CI->common_model->calculate_currency($amount, '', '', true, false);
541 541
     }
542
-    function account_number_icon($select = "", $table = "", $number){
543
-    $return_value='';
544
-    $where=array('number'=>$number);
545
-    $account_res = (array)$this->CI->db->get_where("accounts",$where)->first_row();
546
-    if($account_res['type'] == 0){
547
-    $return_value= '<div class="flx_font flx_magenta" title="Customer">C</div>'." <span title='Edit'>". $account_res['number']." </span>";    
542
+    function account_number_icon($select = "", $table = "", $number) {
543
+    $return_value = '';
544
+    $where = array('number'=>$number);
545
+    $account_res = (array)$this->CI->db->get_where("accounts", $where)->first_row();
546
+    if ($account_res['type'] == 0) {
547
+    $return_value = '<div class="flx_font flx_magenta" title="Customer">C</div>'." <span title='Edit'>".$account_res['number']." </span>";    
548 548
     }
549
-    if($account_res['type']==3){
550
-    $return_value='<div class="flx_font flx_blue" title="Provider">P</div>'." <span title='Edit'>".$account_res['number']." </span>";
549
+    if ($account_res['type'] == 3) {
550
+    $return_value = '<div class="flx_font flx_blue" title="Provider">P</div>'." <span title='Edit'>".$account_res['number']." </span>";
551 551
     }
552
-    if($account_res['type']== -1 || $account_res['type']==2){
553
-      $return_value='<div class="flx_font flx_pink" title="Admin">A</div>'." <span title='Edit'>".$account_res['number']." </span>";
552
+    if ($account_res['type'] == -1 || $account_res['type'] == 2) {
553
+      $return_value = '<div class="flx_font flx_pink" title="Admin">A</div>'." <span title='Edit'>".$account_res['number']." </span>";
554 554
     }
555
-    if($account_res['type']== 4){
556
-      $return_value='<div class="flx_font flx_purple" title="Subadmin">S</div>'." <span title='Edit'>".$account_res['number']." </span>";
555
+    if ($account_res['type'] == 4) {
556
+      $return_value = '<div class="flx_font flx_purple" title="Subadmin">S</div>'." <span title='Edit'>".$account_res['number']." </span>";
557 557
     }
558 558
     return $return_value;
559 559
     }
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
     }
629 629
 
630 630
     function search_string_type($status = '') {
631
-        $status_array = array('5'=>"Begins With",'1' => 'Contains', '2' => 'Doesnt Contain', '3' => 'Is Equal To', '4' => 'Is Not Equal To',"6"=>"Ends With");
631
+        $status_array = array('5'=>"Begins With", '1' => 'Contains', '2' => 'Doesnt Contain', '3' => 'Is Equal To', '4' => 'Is Not Equal To', "6"=>"Ends With");
632 632
         return $status_array;
633 633
     }
634 634
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
     }
650 650
 
651 651
     function convert_to_percentage($select = "", $table = "", $amount) {
652
-        return round($amount, 2) . " %";
652
+        return round($amount, 2)." %";
653 653
     }
654 654
 
655 655
     function convert_to_minutes($select = "", $table = "", $amount) {
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
         return $status_array;
662 662
     }
663 663
     
664
-    	function set_routetype_status($select= ''){
664
+    	function set_routetype_status($select = '') {
665 665
         $status_array = array("" => "--Select--",
666 666
             "0" => "LCR",
667 667
             "1" => "COST"
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
             $array = explode(",", $attachement);
677 677
             $str = '';	
678 678
             foreach ($array as $key => $val) {
679
-                $link = base_url() . "email/email_history_list_attachment/" . $val;
680
-                $str.="<a href='" . $link . "' title='" . $val . "' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
679
+                $link = base_url()."email/email_history_list_attachment/".$val;
680
+                $str .= "<a href='".$link."' title='".$val."' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
681 681
             }
682 682
             return $str;
683 683
         } else {
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 
765 765
     function get_action_buttons($buttons_arr, $linkid) {
766 766
         $ret_url = '';
767
-        if (!empty($buttons_arr) && $buttons_arr != '') {
767
+        if ( ! empty($buttons_arr) && $buttons_arr != '') {
768 768
             foreach ($buttons_arr as $button_key => $buttons_params) {
769 769
                 if (strtoupper($button_key) == "EDIT") {
770 770
                     $ret_url .= $this->build_edit_button($buttons_params, $linkid);
@@ -833,31 +833,31 @@  discard block
 block discarded – undo
833 833
     }
834 834
 
835 835
     function build_delete_button_animap($url, $linkid) {
836
-        $link = base_url() . $url . "" . $linkid;
837
-        return '<a href="javascript:void(0)" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg_destination(' . $linkid . ');"><i class="fa fa-trash fa-fw"></i></a>';
836
+        $link = base_url().$url."".$linkid;
837
+        return '<a href="javascript:void(0)" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg_destination('.$linkid.');"><i class="fa fa-trash fa-fw"></i></a>';
838 838
     }
839 839
 
840 840
     function build_edit_button_animap($button_params, $linkid) {
841
-        $link = base_url() . $button_params->url . "" . $linkid;
842
-        return '<a href="javascript:void(0);" id="destination_new" class="btn btn-royelblue btn-sm" onclick="return get_destination(' . $linkid . ');" title="Update"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
841
+        $link = base_url().$button_params->url."".$linkid;
842
+        return '<a href="javascript:void(0);" id="destination_new" class="btn btn-royelblue btn-sm" onclick="return get_destination('.$linkid.');" title="Update"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
843 843
     }
844 844
 
845 845
     function build_animap_button($button_params, $linkid) {
846
-        $link = base_url() . $button_params->url . "" . $linkid;
847
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm animap_image" rel="facebox" title="ANI Map"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
846
+        $link = base_url().$button_params->url."".$linkid;
847
+        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm animap_image" rel="facebox" title="ANI Map"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
848 848
     }
849 849
 
850 850
     function build_edit_button($button_params, $linkid) {
851
-        $link = base_url() . $button_params->url . "" . $linkid;
851
+        $link = base_url().$button_params->url."".$linkid;
852 852
        
853 853
         if ($button_params->mode == 'popup') {
854
-            $rel = (isset($button_params->layout) && $button_params->layout != '')?"facebox_".$button_params->layout:"facebox";
855
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="Edit" ="small"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
854
+            $rel = (isset($button_params->layout) && $button_params->layout != '') ? "facebox_".$button_params->layout : "facebox";
855
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="Edit" ="small"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
856 856
             
857
-        }else if(strpos($link,'customer_edit') !== false){
858
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
859
-        }else {
860
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
857
+        } else if (strpos($link, 'customer_edit') !== false) {
858
+        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
859
+        } else {
860
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
861 861
         }
862 862
     }
863 863
 
@@ -865,18 +865,18 @@  discard block
 block discarded – undo
865 865
       For Edit on Account number or name
866 866
      **/
867 867
     function build_custome_edit_button($button_params, $field, $linkid) {
868
-        $link = base_url() . $button_params->url . "" . $linkid;
869
-        if(isset($button_params->layout)){
868
+        $link = base_url().$button_params->url."".$linkid;
869
+        if (isset($button_params->layout)) {
870 870
 			if ($button_params->mode == 'popup') {
871
-				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" rel="facebox_medium" title="Update">' . $field . '</a>&nbsp;';
871
+				return '<a href="'.$link.'" style="cursor:pointer;color:#005298;" rel="facebox_medium" title="Update">'.$field.'</a>&nbsp;';
872 872
 			} else {
873
-				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" title="Edit">' . $field . '</a>&nbsp;';
873
+				return '<a href="'.$link.'" style="cursor:pointer;color:#005298;" title="Edit">'.$field.'</a>&nbsp;';
874 874
 			}
875
-		}else{ 
875
+		} else { 
876 876
 			if ($button_params->mode == 'popup') {
877
-				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" rel="facebox" title="Update">' . $field . '</a>&nbsp;';
877
+				return '<a href="'.$link.'" style="cursor:pointer;color:#005298;" rel="facebox" title="Update">'.$field.'</a>&nbsp;';
878 878
 			} else {
879
-				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" title="Edit">' . $field . '</a>&nbsp;';
879
+				return '<a href="'.$link.'" style="cursor:pointer;color:#005298;" title="Edit">'.$field.'</a>&nbsp;';
880 880
 			}
881 881
 		}
882 882
     }
@@ -884,126 +884,126 @@  discard block
 block discarded – undo
884 884
     /************************************ */
885 885
 
886 886
     function build_edit_button_restore($button_params, $linkid) {
887
-        $link = base_url() . $button_params->url . "" . $linkid;
887
+        $link = base_url().$button_params->url."".$linkid;
888 888
         if ($button_params->mode == 'popup') {
889
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Restore" onClick="return get_alert_msg();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
889
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="facebox" title="Restore" onClick="return get_alert_msg();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
890 890
         } else {
891
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Restore" onClick="return get_alert_msg_restore();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
891
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Restore" onClick="return get_alert_msg_restore();"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
892 892
         }
893 893
     }
894 894
 
895 895
     function build_delete_button($url, $linkid) {
896
-        $flag='0';
897
-        $data=  explode("/",$url);
898
-        $link = base_url() . $url . "" . $linkid;
899
-        foreach($data as $key=>$value){
900
-            if($value == 'price_delete')
896
+        $flag = '0';
897
+        $data = explode("/", $url);
898
+        $link = base_url().$url."".$linkid;
899
+        foreach ($data as $key=>$value) {
900
+            if ($value == 'price_delete')
901 901
                 $flag = '1';
902
-            if($value == 'trunk_remove')
903
-                $flag='2';
904
-            if($value == 'customer_delete' ||$value =='provider_delete')
905
-                $flag='3';
906
-            if($value == 'reseller_delete')
907
-                $flag='4';
902
+            if ($value == 'trunk_remove')
903
+                $flag = '2';
904
+            if ($value == 'customer_delete' || $value == 'provider_delete')
905
+                $flag = '3';
906
+            if ($value == 'reseller_delete')
907
+                $flag = '4';
908 908
             }    
909
-            if($flag=='1'){
910
-                $where=array('pricelist_id'=>$linkid,'deleted !=' =>'1');
911
-                $customer_cnt=$this->get_field_count('id','accounts',$where);
912
-                    $where=array('pricelist_id'=>$linkid);
913
-                    $rategroup_cnt=$this->get_field_count('id','routes',$where);
914
-                    if($rategroup_cnt > 0 || $customer_cnt > 0 ){
909
+            if ($flag == '1') {
910
+                $where = array('pricelist_id'=>$linkid, 'deleted !=' =>'1');
911
+                $customer_cnt = $this->get_field_count('id', 'accounts', $where);
912
+                    $where = array('pricelist_id'=>$linkid);
913
+                    $rategroup_cnt = $this->get_field_count('id', 'routes', $where);
914
+                    if ($rategroup_cnt > 0 || $customer_cnt > 0) {
915 915
                         
916
-                        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$rategroup_cnt.','.$customer_cnt.','.$linkid.',1);"><i class="fa fa-trash fa-fw"></i></a>';
916
+                        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$rategroup_cnt.','.$customer_cnt.','.$linkid.',1);"><i class="fa fa-trash fa-fw"></i></a>';
917 917
                     }
918
-                    else{
919
-                        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
918
+                    else {
919
+                        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
920 920
                     }
921 921
             }
922
-            if($flag=='2'){
923
-                $where=array('trunk_id'=>$linkid);
924
-                $trunk_cnt=$this->get_field_count('id','outbound_routes',$where);
925
-                if($trunk_cnt > 0){
926
-                    return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$trunk_cnt.',null,'.$linkid.',2);"><i class="fa fa-trash fa-fw"></i></a>';
922
+            if ($flag == '2') {
923
+                $where = array('trunk_id'=>$linkid);
924
+                $trunk_cnt = $this->get_field_count('id', 'outbound_routes', $where);
925
+                if ($trunk_cnt > 0) {
926
+                    return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$trunk_cnt.',null,'.$linkid.',2);"><i class="fa fa-trash fa-fw"></i></a>';
927 927
                 }
928
-                else{
929
-                    return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
928
+                else {
929
+                    return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
930 930
                 }
931 931
             }
932
-            if($flag == '3'){
933
-		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message(0,null,'.$linkid.',3);">
932
+            if ($flag == '3') {
933
+		return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message(0,null,'.$linkid.',3);">
934 934
 		<i class="fa fa-trash fa-fw"></i></a>';
935 935
             }
936
-            if($flag == '4'){
937
-		return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message(0,null,'.$linkid.',4);">
936
+            if ($flag == '4') {
937
+		return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message(0,null,'.$linkid.',4);">
938 938
 		<i class="fa fa-trash fa-fw"></i></a>';
939 939
             }
940
-            if($flag=='0' && $url.$linkid !='accounts/admin_delete/1' ){
941
-                return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
940
+            if ($flag == '0' && $url.$linkid != 'accounts/admin_delete/1') {
941
+                return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
942 942
             }  
943 943
     }
944 944
 
945 945
     function build_view_button($button_params, $linkid) {
946
-        $link = base_url() . $button_params->url . "" . $linkid;
946
+        $link = base_url().$button_params->url."".$linkid;
947 947
         if ($button_params->mode == 'popup') {
948
-			$rel = (isset($button_params->layout) && $button_params->layout != '')?"facebox_".$button_params->layout:"facebox";
949
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
948
+			$rel = (isset($button_params->layout) && $button_params->layout != '') ? "facebox_".$button_params->layout : "facebox";
949
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
950 950
         } else {
951
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
951
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="View Details"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
952 952
         }
953 953
     }
954 954
 
955 955
     function build_add_taxes_button($button_params, $linkid) {
956
-        $link = base_url() . $button_params->url . "" . $linkid;
956
+        $link = base_url().$button_params->url."".$linkid;
957 957
         if ($button_params->mode == 'popup') {
958
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
958
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="facebox" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
959 959
         } else {
960
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
960
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Add Account Taxes"><i class="fa fa-reorder fa-fw"></i></a>&nbsp;';
961 961
         }
962 962
     }
963 963
 
964 964
     function build_add_download_database_button($url, $linkid) {
965
-        $link = base_url() . $url . "" . $linkid;
966
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm "  title="Download Database" ><i class="fa-fw fa fa-file-archive-o"></i></a>&nbsp;';
965
+        $link = base_url().$url."".$linkid;
966
+        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm "  title="Download Database" ><i class="fa-fw fa fa-file-archive-o"></i></a>&nbsp;';
967 967
     }
968 968
 
969 969
     function build_add_callerid_button($button_params, $linkid) {
970
-        $link = base_url() . $button_params->url . "" . $linkid;
970
+        $link = base_url().$button_params->url."".$linkid;
971 971
         if ($button_params->mode == 'popup') {
972
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Force Caller Id"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
972
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="facebox" title="Force Caller Id"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
973 973
         } else {
974
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="CallerID"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
974
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="CallerID"><i class="fa fa-mobile-phone fa-fw"></i></a>&nbsp;';
975 975
         }
976 976
     }
977 977
 
978 978
     function build_start_button($url, $linkid) {
979
-        $link = base_url() . $url . "" . $linkid;
979
+        $link = base_url().$url."".$linkid;
980 980
 
981
-        return '<a href="' . $link . '" class=""  title="Start" style="text-decoration:none;color: #428BCA;"><b>Start |</b></a>&nbsp;';
981
+        return '<a href="'.$link.'" class=""  title="Start" style="text-decoration:none;color: #428BCA;"><b>Start |</b></a>&nbsp;';
982 982
     }
983 983
 
984 984
     function build_stop_button($url, $linkid) {
985
-        $link = base_url() . $url . "" . $linkid;
986
-        return '<a href="' . $link . '" class=""  title="Stop" style="text-decoration:none;color: #428BCA;" ><b>Stop |</b></a>&nbsp;';
985
+        $link = base_url().$url."".$linkid;
986
+        return '<a href="'.$link.'" class=""  title="Stop" style="text-decoration:none;color: #428BCA;" ><b>Stop |</b></a>&nbsp;';
987 987
     }
988 988
 
989 989
     function build_reload_button($url, $linkid) {
990
-        $link = base_url() . $url . "" . $linkid;
991
-        return '<a href="' . $link . '" class=""  title="reload" style="text-decoration:none;color: #428BCA;"><b>Reload |</b></a>&nbsp;';
990
+        $link = base_url().$url."".$linkid;
991
+        return '<a href="'.$link.'" class=""  title="reload" style="text-decoration:none;color: #428BCA;"><b>Reload |</b></a>&nbsp;';
992 992
     }
993 993
 
994 994
     function build_rescan_button($url, $linkid) {
995
-        $link = base_url() . $url . "" . $linkid;
996
-        return '<a href="' . $link . '" class=""  title="rescan" style="text-decoration:none;color: #428BCA;"><b>Rescan</b></a>&nbsp;';
995
+        $link = base_url().$url."".$linkid;
996
+        return '<a href="'.$link.'" class=""  title="rescan" style="text-decoration:none;color: #428BCA;"><b>Rescan</b></a>&nbsp;';
997 997
     }
998 998
 
999 999
     function build_add_payment_button($url, $linkid) {
1000
-        $link = base_url() . $url . "" . $linkid;
1001
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Refill" ><i class="fa fa-usd fa-fw"></i></a>&nbsp;';
1000
+        $link = base_url().$url."".$linkid;
1001
+        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="facebox" title="Refill" ><i class="fa fa-usd fa-fw"></i></a>&nbsp;';
1002 1002
     }
1003 1003
 
1004 1004
     function build_add_download_button($url, $linkid) {
1005
-        $link = base_url() . $url . "" . $linkid;
1006
-        return '<a href="' . $link . '" class="btn btn-royelblue btn-sm"  title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a>&nbsp;';
1005
+        $link = base_url().$url."".$linkid;
1006
+        return '<a href="'.$link.'" class="btn btn-royelblue btn-sm"  title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a>&nbsp;';
1007 1007
     }
1008 1008
 
1009 1009
     /*
@@ -1012,11 +1012,11 @@  discard block
 block discarded – undo
1012 1012
      */
1013 1013
 
1014 1014
     function build_edit_button_resend($button_params, $linkid) {
1015
-        $link = base_url() . $button_params->url . "" . $linkid;
1015
+        $link = base_url().$button_params->url."".$linkid;
1016 1016
         if ($button_params->mode == 'popup') {
1017
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="facebox" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1017
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" rel="facebox" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1018 1018
         } else {
1019
-            return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1019
+            return '<a href="'.$link.'" class="btn btn-royelblue btn-sm" title="Resend Mail"><i class="fa fa-repeat"></i></a>&nbsp;';
1020 1020
         }
1021 1021
     }
1022 1022
 
@@ -1031,17 +1031,17 @@  discard block
 block discarded – undo
1031 1031
     function mail_to_users($type, $accountinfo, $attachment = "", $amount = "") {
1032 1032
 		$subject = "";
1033 1033
         $settings_reply_email = '[email protected]';
1034
-        $reseller_id=$accountinfo['reseller_id'] > 0 ? $accountinfo['reseller_id'] : 0;
1035
-		$where="accountid IN ('".$reseller_id."','1')";
1034
+        $reseller_id = $accountinfo['reseller_id'] > 0 ? $accountinfo['reseller_id'] : 0;
1035
+		$where = "accountid IN ('".$reseller_id."','1')";
1036 1036
         $this->CI->db->where($where);
1037 1037
         $this->CI->db->select('emailaddress');
1038 1038
         $this->CI->db->order_by('accountid', 'desc');
1039 1039
         $this->CI->db->limit(1);
1040 1040
         $invoiceconf = $this->CI->db->get('invoice_conf');
1041 1041
         $invoiceconf = (array)$invoiceconf->first_row();
1042
-        $settings_reply_email=$invoiceconf['emailaddress'];
1043
-        $company_name=Common_model::$global_config['system_config']['company_name'];
1044
-        $company_website=Common_model::$global_config['system_config']['company_website'];
1042
+        $settings_reply_email = $invoiceconf['emailaddress'];
1043
+        $company_name = Common_model::$global_config['system_config']['company_name'];
1044
+        $company_website = Common_model::$global_config['system_config']['company_website'];
1045 1045
         $where = array('name' => $type);
1046 1046
         $query = $this->CI->db_model->getSelect("*", "default_templates", $where);
1047 1047
         $query = $query->result();
@@ -1052,106 +1052,106 @@  discard block
 block discarded – undo
1052 1052
         $message = str_replace("#COMPANY_NAME#", $company_name, $message);
1053 1053
         $message = str_replace("#COMPANY_WEBSITE#", $company_website, $message);
1054 1054
         $message = str_replace("</p>", "", $message);
1055
-		if(isset($accountinfo['refill_amount']) && $accountinfo['refill_amount']!= ""){
1055
+		if (isset($accountinfo['refill_amount']) && $accountinfo['refill_amount'] != "") {
1056 1056
 			$refillamount = $accountinfo['refill_amount'];
1057
-		}else{
1057
+		} else {
1058 1058
 			$refillamount = "0";
1059 1059
 		}
1060 1060
 		
1061 1061
         switch ($type) {
1062 1062
             case 'email_add_user':
1063
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1063
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1064 1064
                 $message = str_replace('#NUMBER#', $accountinfo['number'], $message);
1065 1065
                 $message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1066 1066
                 $message = str_replace('#LINK#', $accountinfo['confirm'], $message);
1067 1067
                 break;
1068 1068
             case 'email_forgot_user':
1069
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1069
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1070 1070
                 $message = str_replace('#NUMBER#', $accountinfo['number'], $message);
1071 1071
                 $message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1072 1072
                 $message = str_replace('#LINK#', $accountinfo['link'], $message);
1073 1073
                 break;
1074 1074
 
1075 1075
             case 'email_forgot_confirmation':
1076
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1076
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1077 1077
                 $message = str_replace('#CONFIRM#', $accountinfo['confirm'], $message);
1078 1078
                 break;
1079 1079
 
1080 1080
             case 'email_signup_confirmation':
1081
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1081
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1082 1082
                 $message = str_replace('#CONFIRM#', $accountinfo['confirm'], $message);
1083 1083
                 break;
1084 1084
             case 'add_sip_device':
1085
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1085
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1086 1086
                 $message = str_replace('#USERNAME#', $accountinfo['number'], $message);
1087 1087
                 $message = str_replace('#PASSWORD#', $accountinfo['password'], $message);
1088 1088
                 break;
1089 1089
                               
1090 1090
             case 'voip_account_refilled':
1091
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1091
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1092 1092
                 $message = str_replace('#REFILLBALANCE#', $accountinfo['refill_amount'], $message);
1093 1093
                 $message = str_replace('#BALANCE#', $accountinfo['refill_amount'] + $accountinfo['balance'], $message);
1094 1094
                 break;
1095 1095
             case 'voip_child_account_refilled':
1096
-                $reseller_number= $this->CI->common->get_field_name('number', 'accounts', $accountinfo['reseller_id']);
1097
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1096
+                $reseller_number = $this->CI->common->get_field_name('number', 'accounts', $accountinfo['reseller_id']);
1097
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1098 1098
                 $message = str_replace('#REFILLBALANCE#', $accountinfo['refill_amount'], $message);
1099 1099
                 $message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1100
-                $message = str_replace('#ACCOUNTNUMBER#',$reseller_number, $message);
1100
+                $message = str_replace('#ACCOUNTNUMBER#', $reseller_number, $message);
1101 1101
                 break;
1102 1102
             case 'add_subscription':
1103
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1103
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1104 1104
                 break;
1105 1105
             case 'remove_subscription':
1106
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1106
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1107 1107
                 break;
1108 1108
             case 'add_package':
1109
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1109
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1110 1110
                 break;
1111 1111
             case 'remove_package':
1112
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1112
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1113 1113
                 break;
1114 1114
             case 'email_calling_card':
1115
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1115
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1116 1116
                 $message = str_replace('#CARDNUMBER#', $accountinfo['cardnumber'], $message);
1117 1117
                 $message = str_replace('#PIN#', $accountinfo['pin'], $message);
1118 1118
                 $message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1119 1119
                 break;
1120 1120
             case 'email_low_balance';
1121
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1121
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1122 1122
                 $to_currency = $this->CI->common->get_field_name('currency', 'currency', $accountinfo['currency_id']);
1123 1123
                 $balance = $this->CI->common_model->calculate_currency($accountinfo['balance'], "", $to_currency, true, true);
1124 1124
                 $message = str_replace('#BALANCE#', $accountinfo['balance'], $message);
1125 1125
                 break;
1126 1126
             case 'email_new_invoice';
1127
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1127
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1128 1128
                 $message = str_replace('#AMOUNT#', $amount, $message);
1129 1129
                 $message = str_replace('#INVOICE_NUMBER#', $amount, $message);
1130 1130
                 $subject = $query[0]->subject;
1131 1131
                 $subject = str_replace("#INVOICE_NUMBER#", $amount, $subject);
1132 1132
                 break;
1133 1133
              case 'email_add_did';
1134
-				if(isset($accountinfo['did_maxchannels']) && $accountinfo['did_maxchannels']!= ""){
1134
+				if (isset($accountinfo['did_maxchannels']) && $accountinfo['did_maxchannels'] != "") {
1135 1135
 					$accountinfo['did_maxchannels'] = $accountinfo['did_maxchannels'];
1136
-				}else if($accountinfo['did_maxchannels'] == "0"){
1136
+				} else if ($accountinfo['did_maxchannels'] == "0") {
1137 1137
 							$accountinfo['did_maxchannels'] = "Unlimited";
1138
-				}else{
1138
+				} else {
1139 1139
 					$accountinfo['did_maxchannels'] = "Unlimited";
1140 1140
 				}
1141
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1142
-                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'] , $message);
1143
-                $message = str_replace('#COUNTRYNAME#',$accountinfo['did_country_id'], $message);
1144
-                $message = str_replace('#SETUPFEE#',$accountinfo['did_setup'], $message);
1145
-                $message = str_replace('#MONTHLYFEE#',$accountinfo['did_monthlycost'], $message);
1146
-                $message = str_replace('#MAXCHANNEL#',$accountinfo['did_maxchannels'], $message);
1141
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1142
+                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'], $message);
1143
+                $message = str_replace('#COUNTRYNAME#', $accountinfo['did_country_id'], $message);
1144
+                $message = str_replace('#SETUPFEE#', $accountinfo['did_setup'], $message);
1145
+                $message = str_replace('#MONTHLYFEE#', $accountinfo['did_monthlycost'], $message);
1146
+                $message = str_replace('#MAXCHANNEL#', $accountinfo['did_maxchannels'], $message);
1147 1147
                 $message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1148 1148
 				$subject = $query[0]->subject;
1149 1149
 				$subject = str_replace("#NUMBER#", $accountinfo['number'], $subject);
1150 1150
 				$subject = str_replace("#DIDNUMBER#", $accountinfo['did_number'], $subject);
1151 1151
                 break;
1152 1152
             case 'email_remove_did';
1153
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1154
-                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'],$message);
1153
+                $message = str_replace('#NAME#', $accountinfo['first_name']." ".$accountinfo['last_name'], $message);
1154
+                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'], $message);
1155 1155
                 $message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1156 1156
 				$subject = $query[0]->subject;
1157 1157
 				$subject = str_replace("#NUMBER#", $accountinfo['number'], $subject);
@@ -1159,9 +1159,9 @@  discard block
 block discarded – undo
1159 1159
                 break;
1160 1160
         }
1161 1161
         
1162
-        if($subject == ""){
1162
+        if ($subject == "") {
1163 1163
 			$subject = $query[0]->subject;
1164
-			$subject = str_replace("#NAME#", $accountinfo['first_name'] . " " . $accountinfo['last_name'], $subject);
1164
+			$subject = str_replace("#NAME#", $accountinfo['first_name']." ".$accountinfo['last_name'], $subject);
1165 1165
 			$subject = str_replace("#COMPANY_NAME#", $company_name, $subject);	
1166 1166
 		}
1167 1167
         $account_id = (isset($accountinfo['last_id']) && $accountinfo['last_id'] != "") ? $accountinfo['last_id'] : $accountinfo['id'];
@@ -1245,13 +1245,13 @@  discard block
 block discarded – undo
1245 1245
         $result = $this->CI->db->get('invoice_details');
1246 1246
         if ($result->num_rows() > 0) {
1247 1247
             $result = $result->result_array();
1248
-	    if($select == 'debit'){
1249
-		if($result[0]['item_type'] == 'POSTCHARG'){
1248
+	    if ($select == 'debit') {
1249
+		if ($result[0]['item_type'] == 'POSTCHARG') {
1250 1250
 	            return $this->convert_to_currency('', '', $result[0]['debit']);
1251
-		}else{
1251
+		} else {
1252 1252
 	            return $this->convert_to_currency('', '', $result[0]['credit']);
1253 1253
 		}
1254
-	    }else{
1254
+	    } else {
1255 1255
 		   return $result[0][$select];
1256 1256
 	    }
1257 1257
         } else {
@@ -1302,7 +1302,7 @@  discard block
 block discarded – undo
1302 1302
 
1303 1303
             $timezone_result = $timezone_result->result_array();
1304 1304
             foreach ($timezone_result as $data) {
1305
-                $gmtoffset+=$data['gmtoffset'];
1305
+                $gmtoffset += $data['gmtoffset'];
1306 1306
             }
1307 1307
         }
1308 1308
 // 	  echo $gmtoffset;exit;
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
     }
1367 1367
 
1368 1368
     function get_refill_coupon_used($select = '', $table = '', $status) {
1369
-        return $status['status'] == 2 ? '<img src= "'.base_url().'assets/images/true.png" style="height:20px;width:20px;" title="Yes">' : '<img src= "'. base_url().'/assets/images/false.png" style="height:20px;width:20px;" title="No">';
1369
+        return $status['status'] == 2 ? '<img src= "'.base_url().'assets/images/true.png" style="height:20px;width:20px;" title="Yes">' : '<img src= "'.base_url().'/assets/images/false.png" style="height:20px;width:20px;" title="No">';
1370 1370
     }
1371 1371
 
1372 1372
     /*     * *******
@@ -1444,20 +1444,20 @@  discard block
 block discarded – undo
1444 1444
         $status_array = array('0' => 'Enable', '1' => 'Disable');
1445 1445
         return $status_array;
1446 1446
     }
1447
-    function custom_status($status){
1447
+    function custom_status($status) {
1448 1448
 		$status_array = array('0' => 'Yes', '1' => 'No');
1449 1449
         return $status_array;
1450 1450
     }
1451 1451
     
1452
-    function custom_status_active($status){
1452
+    function custom_status_active($status) {
1453 1453
       $status_array = array('0' => 'Active', '1' => 'InActive');
1454 1454
       return $status_array;
1455 1455
     }
1456
-    function custom_status_true($status){
1456
+    function custom_status_true($status) {
1457 1457
       $status_array = array('0' => 'TRUE', '1' => 'FALSE');
1458 1458
       return $status_array;
1459 1459
     }
1460
-    function custom_status_voicemail($status){
1460
+    function custom_status_voicemail($status) {
1461 1461
       $status_array = array('true' => 'True', 'false' => 'False');
1462 1462
       return $status_array;
1463 1463
     }
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
         return $status_array;
1485 1485
     }
1486 1486
 	
1487
-    function enable_disable_option(){
1487
+    function enable_disable_option() {
1488 1488
         $option_array = array('0' => 'Enable', '1' => 'Disable');
1489 1489
         return $option_array;
1490 1490
     }
@@ -1512,14 +1512,14 @@  discard block
 block discarded – undo
1512 1512
         $status_array = array('1' => 'Enable', '0' => 'Disable',);
1513 1513
         return $status_array;
1514 1514
     }
1515
-    function default_signup_rategroup(){
1515
+    function default_signup_rategroup() {
1516 1516
         $this->CI->db->select("id,name");
1517
-        $this->CI->db->where("status",0);
1518
-        $this->CI->db->where("reseller_id",0);
1519
-        $pricelist_result=$this->CI->db->get("pricelists")->result_array();
1520
-        $pricelist_arr=array();
1521
-        foreach($pricelist_result as $result){
1522
-            $pricelist_arr[$result['id']]=$result['name'];
1517
+        $this->CI->db->where("status", 0);
1518
+        $this->CI->db->where("reseller_id", 0);
1519
+        $pricelist_result = $this->CI->db->get("pricelists")->result_array();
1520
+        $pricelist_arr = array();
1521
+        foreach ($pricelist_result as $result) {
1522
+            $pricelist_arr[$result['id']] = $result['name'];
1523 1523
         }
1524 1524
         return $pricelist_arr;
1525 1525
         
@@ -1593,17 +1593,17 @@  discard block
 block discarded – undo
1593 1593
       Calculate Currency manually.
1594 1594
      */
1595 1595
 
1596
-    function calculate_currency_manually($currency_info, $amount, $show_currency_flag = true,$number_format=true) {
1596
+    function calculate_currency_manually($currency_info, $amount, $show_currency_flag = true, $number_format = true) {
1597 1597
         $decimal_points = $currency_info['decimalpoints'];
1598 1598
         $system_currency_rate = $currency_info['base_currency']['currencyrate'];
1599 1599
         $user_currency_rate = $currency_info['user_currency']['currencyrate'];
1600
-        $calculated_amount=(float)(($amount * $currency_info['user_currency']['currencyrate']) / $currency_info['base_currency']['currencyrate']); 
1601
-        if($number_format){
1602
-         $calculated_amount = number_format($calculated_amount,$currency_info['decimalpoints']);
1600
+        $calculated_amount = (float)(($amount * $currency_info['user_currency']['currencyrate']) / $currency_info['base_currency']['currencyrate']); 
1601
+        if ($number_format) {
1602
+         $calculated_amount = number_format($calculated_amount, $currency_info['decimalpoints']);
1603 1603
         }
1604
-        if ($show_currency_flag){
1604
+        if ($show_currency_flag) {
1605 1605
           return $calculated_amount." ".$currency_info['user_currency']['currency'];
1606
-        }else{
1606
+        } else {
1607 1607
           return $calculated_amount;
1608 1608
         }
1609 1609
     }
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
     }
1619 1619
 
1620 1620
     function set_summarycustomer_groupby($status = '') {
1621
-        $status_array = array('' => "--Select--", 'accountid' => 'Account', 'pattern' => 'Code','package_id'=>"Package");
1621
+        $status_array = array('' => "--Select--", 'accountid' => 'Account', 'pattern' => 'Code', 'package_id'=>"Package");
1622 1622
         return $status_array;
1623 1623
     }
1624 1624
 
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
         $accountinfo = $this->CI->session->userdata('accountinfo');
1635 1635
         //Get User Currency id 
1636 1636
         $user_currency_id = $accountinfo['currency_id'] > 0 ? $accountinfo['currency_id'] : $base_currency;
1637
-        $where = "currency = '" . $base_currency . "' OR id= " . $user_currency_id;
1637
+        $where = "currency = '".$base_currency."' OR id= ".$user_currency_id;
1638 1638
         $this->CI->db->where($where);
1639 1639
         $this->CI->db->select('*');
1640 1640
         $currency_result = $this->CI->db->get('currency');
@@ -1652,7 +1652,7 @@  discard block
 block discarded – undo
1652 1652
                 }
1653 1653
             }
1654 1654
         } else if ($currency_result->num_rows() == 1) {
1655
-            $currency_info['user_currency'] = $currency_info['base_currency'] = (array) $currency_result->first_row();
1655
+            $currency_info['user_currency'] = $currency_info['base_currency'] = (array)$currency_result->first_row();
1656 1656
         }
1657 1657
         //Get Decimal points as per defined from system.
1658 1658
         $currency_info['decimalpoints'] = Common_model::$global_config['system_config']['decimalpoints'];
@@ -1661,15 +1661,15 @@  discard block
 block discarded – undo
1661 1661
 
1662 1662
     function convert_to_show_in($search_name = "", $table = "", $second) {
1663 1663
         $search_arr = $this->CI->session->userdata($search_name);
1664
-        $show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1665
-        return ($show_seconds === 'minutes') ? ($second > 0 ) ?
1666
-                        sprintf('%02d',$second / 60) . ":" . sprintf('%02d', ($second % 60)) : "00:00"  : sprintf('%02d', $second);
1664
+        $show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1665
+        return ($show_seconds === 'minutes') ? ($second > 0) ?
1666
+                        sprintf('%02d', $second / 60).":".sprintf('%02d', ($second % 60)) : "00:00" : sprintf('%02d', $second);
1667 1667
     }
1668 1668
 
1669 1669
     function array_column($input, $columnKey, $indexKey = null) {
1670 1670
         $array = array();
1671 1671
         foreach ($input as $value) {
1672
-            if (!isset($value[$columnKey])) {
1672
+            if ( ! isset($value[$columnKey])) {
1673 1673
                 trigger_error("Key \"$columnKey\" does not exist in array");
1674 1674
                 return false;
1675 1675
             }
@@ -1677,11 +1677,11 @@  discard block
 block discarded – undo
1677 1677
             if (is_null($indexKey)) {
1678 1678
                 $array[] = $value[$columnKey];
1679 1679
             } else {
1680
-                if (!isset($value[$indexKey])) {
1680
+                if ( ! isset($value[$indexKey])) {
1681 1681
                     trigger_error("Key \"$indexKey\" does not exist in array");
1682 1682
                     return false;
1683 1683
                 }
1684
-                if (!is_scalar($value[$indexKey])) {
1684
+                if ( ! is_scalar($value[$indexKey])) {
1685 1685
                     trigger_error("Key \"$indexKey\" does not contain scalar value");
1686 1686
                     return false;
1687 1687
                 }
@@ -1698,22 +1698,22 @@  discard block
 block discarded – undo
1698 1698
     }
1699 1699
 
1700 1700
     function currency_decimal($amount) {
1701
-		$amount = str_replace( ',', '', $amount );
1701
+		$amount = str_replace(',', '', $amount);
1702 1702
         $decimal_amount = Common_model::$global_config['system_config']['decimalpoints'];
1703
-        $number_convert = number_format((float) $amount, $decimal_amount, '.', '');
1703
+        $number_convert = number_format((float)$amount, $decimal_amount, '.', '');
1704 1704
         return $number_convert;
1705 1705
     }
1706 1706
 
1707
-    function add_invoice_details($account_arr, $charge_type, $amount,$description) {
1707
+    function add_invoice_details($account_arr, $charge_type, $amount, $description) {
1708 1708
         $accountinfo = $this->CI->session->userdata('accountinfo');
1709 1709
         $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
1710
-        $where = "accountid IN ('" . $reseller_id . "','1')";
1710
+        $where = "accountid IN ('".$reseller_id."','1')";
1711 1711
         $this->CI->db->where($where);
1712 1712
         $this->CI->db->select('*');
1713 1713
         $this->CI->db->order_by('accountid', 'desc');
1714 1714
         $this->CI->db->limit(1);
1715 1715
         $invoiceconf = $this->CI->db->get('invoice_conf');
1716
-        $invoice_conf = (array) $invoiceconf->first_row();
1716
+        $invoice_conf = (array)$invoiceconf->first_row();
1717 1717
         $last_invoiceid = $this->get_invoice_date('invoiceid', '', $account_arr['reseller_id']);
1718 1718
         if ($last_invoiceid && $last_invoiceid > 0) {
1719 1719
             $last_invoiceid = ($last_invoiceid + 1);
@@ -1722,7 +1722,7 @@  discard block
 block discarded – undo
1722 1722
         }
1723 1723
         $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
1724 1724
         $invoice_prefix = $invoice_conf['invoice_prefix'];
1725
-        $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s") . " +" . $invoice_conf['interval'] . " days"));
1725
+        $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days"));
1726 1726
         $invoiceid = $account_arr['posttoexternal'] == 0 ? $this->CI->common_model->generate_receipt($account_arr['id'], $amount, $account_arr, $last_invoiceid, $invoice_prefix, $due_date) : 0;
1727 1727
         
1728 1728
         $insert_arr = array("accountid" => $account_arr['id'],
@@ -1740,111 +1740,111 @@  discard block
 block discarded – undo
1740 1740
     }
1741 1741
     /* ASTPP  3.0  Remove all information related to going to delete customer.
1742 1742
      */
1743
-    function customer_delete_dependencies($id){
1744
-          $this->delete_data('ani_map',array('accountid'=>$id));
1745
-          $this->delete_data('block_patterns',array('accountid'=>$id));
1746
-          $this->delete_data('charge_to_account',array('accountid'=>$id));
1747
-          $this->delete_data('counters',array('accountid'=>$id));
1748
-          $this->delete_data('ip_map',array('accountid'=>$id));
1749
-          $this->delete_data('sip_devices',array('accountid'=>$id));
1750
-          $this->delete_data('speed_dial',array('accountid'=>$id));
1751
-          $this->delete_data('taxes_to_accounts',array('accountid'=>$id));
1752
-          $this->delete_data('mail_details',array('accountid'=>$id));
1753
-          $this->update_data('dids',array("accountid"=>$id),array('accountid'=>0));
1754
-          $this->update_data("accounts",array("id"=>$id),array("deleted"=>1));
1743
+    function customer_delete_dependencies($id) {
1744
+          $this->delete_data('ani_map', array('accountid'=>$id));
1745
+          $this->delete_data('block_patterns', array('accountid'=>$id));
1746
+          $this->delete_data('charge_to_account', array('accountid'=>$id));
1747
+          $this->delete_data('counters', array('accountid'=>$id));
1748
+          $this->delete_data('ip_map', array('accountid'=>$id));
1749
+          $this->delete_data('sip_devices', array('accountid'=>$id));
1750
+          $this->delete_data('speed_dial', array('accountid'=>$id));
1751
+          $this->delete_data('taxes_to_accounts', array('accountid'=>$id));
1752
+          $this->delete_data('mail_details', array('accountid'=>$id));
1753
+          $this->update_data('dids', array("accountid"=>$id), array('accountid'=>0));
1754
+          $this->update_data("accounts", array("id"=>$id), array("deleted"=>1));
1755 1755
     }
1756 1756
     /*
1757 1757
      *  ASTPP  3.0 
1758 1758
      *  Remove all information related to going to delete reseller.
1759 1759
      */
1760
-    function reseller_delete_dependencies($id){
1761
-        $accountinfo=$this->CI->session->userdata('accountinfo');
1762
-        $child_arr=$this->select_data("accounts",array("reseller_id"=>$id,"type"=>0),'id,reseller_id');
1763
-        if($child_arr){
1764
-            foreach($child_arr as $value){
1760
+    function reseller_delete_dependencies($id) {
1761
+        $accountinfo = $this->CI->session->userdata('accountinfo');
1762
+        $child_arr = $this->select_data("accounts", array("reseller_id"=>$id, "type"=>0), 'id,reseller_id');
1763
+        if ($child_arr) {
1764
+            foreach ($child_arr as $value) {
1765 1765
                 $this->customer_delete_dependencies($value['id']);
1766 1766
             }
1767 1767
         }
1768
-        $package_arr=$this->select_data("packages",array("reseller_id"=>$id),'id');
1769
-        if($package_arr){
1770
-            foreach($package_arr as $value){
1771
-                $this->delete_data('package_patterns',array("id"=>$value['id']));
1768
+        $package_arr = $this->select_data("packages", array("reseller_id"=>$id), 'id');
1769
+        if ($package_arr) {
1770
+            foreach ($package_arr as $value) {
1771
+                $this->delete_data('package_patterns', array("id"=>$value['id']));
1772 1772
             }
1773 1773
         }
1774
-        $acc_arr=$this->select_data('accounts',array("id"=>$id),'id,reseller_id');
1775
-        $parent_id=0;
1776
-        if($acc_arr){
1777
-            $parent_id=$acc_arr[0]['reseller_id'];
1774
+        $acc_arr = $this->select_data('accounts', array("id"=>$id), 'id,reseller_id');
1775
+        $parent_id = 0;
1776
+        if ($acc_arr) {
1777
+            $parent_id = $acc_arr[0]['reseller_id'];
1778 1778
         }
1779
-        $pricelist_arr=$this->select_data('pricelists',array('reseller_id'=>$id),'id');
1780
-        if($pricelist_arr){
1781
-             foreach($pricelist_arr as $value){
1782
-                $this->delete_data("routing",array("pricelist_id"=>$value['id']));
1783
-                $this->delete_data("routes",array("pricelist_id"=>$value['id']));
1784
-                $this->update_data('pricelists',array('id'=>$value['id']),array('status'=>2));         
1779
+        $pricelist_arr = $this->select_data('pricelists', array('reseller_id'=>$id), 'id');
1780
+        if ($pricelist_arr) {
1781
+             foreach ($pricelist_arr as $value) {
1782
+                $this->delete_data("routing", array("pricelist_id"=>$value['id']));
1783
+                $this->delete_data("routes", array("pricelist_id"=>$value['id']));
1784
+                $this->update_data('pricelists', array('id'=>$value['id']), array('status'=>2));         
1785 1785
              }
1786 1786
         }
1787
-        $charge_arr=$this->select_data('charges',array('reseller_id'=>$id),'id');
1788
-        if($charge_arr){
1789
-             foreach($charge_arr as $value){
1790
-                $this->delete_data("charge_to_account",array("charge_id"=>$value['id']));
1787
+        $charge_arr = $this->select_data('charges', array('reseller_id'=>$id), 'id');
1788
+        if ($charge_arr) {
1789
+             foreach ($charge_arr as $value) {
1790
+                $this->delete_data("charge_to_account", array("charge_id"=>$value['id']));
1791 1791
              }
1792 1792
         }
1793
-        $this->delete_data('charges',array('reseller_id'=>$id));
1794
-        $this->update_data('dids',array('parent_id'=>$id),array("parent_id"=>$parent_id));
1795
-        $this->delete_data('reseller_pricing',array("reseller_id"=>$id));
1796
-        $this->delete_data('refill_coupon',array("reseller_id"=>$id));
1797
-        $this->delete_data('mail_details',array('accountid'=>$id));
1798
-        $taxes_arr=$this->select_data('taxes',array("reseller_id"=>$id),'id');
1799
-        if($taxes_arr){
1800
-             foreach($taxes_arr as $value){
1801
-                $this->delete_data("taxes_to_accounts",array("taxes_id"=>$value['id']));
1793
+        $this->delete_data('charges', array('reseller_id'=>$id));
1794
+        $this->update_data('dids', array('parent_id'=>$id), array("parent_id"=>$parent_id));
1795
+        $this->delete_data('reseller_pricing', array("reseller_id"=>$id));
1796
+        $this->delete_data('refill_coupon', array("reseller_id"=>$id));
1797
+        $this->delete_data('mail_details', array('accountid'=>$id));
1798
+        $taxes_arr = $this->select_data('taxes', array("reseller_id"=>$id), 'id');
1799
+        if ($taxes_arr) {
1800
+             foreach ($taxes_arr as $value) {
1801
+                $this->delete_data("taxes_to_accounts", array("taxes_id"=>$value['id']));
1802 1802
              }
1803 1803
         }
1804
-        $this->delete_data('taxes',array("reseller_id"=>$id));
1805
-        $this->delete_data('default_templates',array("reseller_id"=>$id));
1806
-        $package_arr=$this->select_data('packages',array('reseller_id'=>$id),'id');
1807
-        if($package_arr){
1808
-            $this->delete_data("counters",array("package_id"=>$value['id']));
1809
-            $this->delete_data("package_patterns",array("package_id"=>$value['id']));
1804
+        $this->delete_data('taxes', array("reseller_id"=>$id));
1805
+        $this->delete_data('default_templates', array("reseller_id"=>$id));
1806
+        $package_arr = $this->select_data('packages', array('reseller_id'=>$id), 'id');
1807
+        if ($package_arr) {
1808
+            $this->delete_data("counters", array("package_id"=>$value['id']));
1809
+            $this->delete_data("package_patterns", array("package_id"=>$value['id']));
1810 1810
         }
1811
-        $this->delete_data('invoice_conf',array('accountid'=>$id));
1812
-        $this->delete_data('packages',array("reseller_id"=>$id));
1813
-        $this->update_data('accounts',array("id"=>$id),array("deleted"=>1));
1811
+        $this->delete_data('invoice_conf', array('accountid'=>$id));
1812
+        $this->delete_data('packages', array("reseller_id"=>$id));
1813
+        $this->update_data('accounts', array("id"=>$id), array("deleted"=>1));
1814 1814
     }
1815 1815
     function subreseller_list($parent_id = '') {
1816 1816
         $customer_id = $parent_id;
1817 1817
         $this->reseller_delete_dependencies($parent_id);
1818
-        $query = 'select id,type from accounts where reseller_id = ' . $parent_id .' AND deleted =0';
1818
+        $query = 'select id,type from accounts where reseller_id = '.$parent_id.' AND deleted =0';
1819 1819
         $result = $this->CI->db->query($query);
1820 1820
         if ($result->num_rows() > 0) {
1821 1821
             $result = $result->result_array();
1822 1822
             foreach ($result as $data) {
1823
-	      if($data['type']==1){
1823
+	      if ($data['type'] == 1) {
1824 1824
 		  $this->reseller_delete_dependencies($data['id']);
1825 1825
 		  $this->subreseller_list($data['id']);
1826
-	      }else{
1826
+	      } else {
1827 1827
 		  $this->customer_delete_dependencies($data['id']);
1828 1828
 	      }
1829 1829
             }
1830 1830
         }
1831 1831
     }
1832 1832
     
1833
-    function delete_data($table_name,$where_arr){
1833
+    function delete_data($table_name, $where_arr) {
1834 1834
         $this->CI->db->where($where_arr);
1835 1835
         $this->CI->db->delete($table_name);
1836 1836
     }
1837
-    function update_data($table_name,$where_arr,$update_arr){
1837
+    function update_data($table_name, $where_arr, $update_arr) {
1838 1838
         $this->CI->db->where($where_arr);
1839
-        $this->CI->db->update($table_name,$update_arr);
1839
+        $this->CI->db->update($table_name, $update_arr);
1840 1840
     }
1841
-    function select_data($table_name,$where_arr,$select){
1841
+    function select_data($table_name, $where_arr, $select) {
1842 1842
         $this->CI->db->where($where_arr);
1843 1843
         $this->CI->db->select($select);
1844
-        $result=$this->CI->db->get($table_name);
1845
-        if($result->num_rows() > 0){
1844
+        $result = $this->CI->db->get($table_name);
1845
+        if ($result->num_rows() > 0) {
1846 1846
             return $result->result_array();
1847
-        }else{
1847
+        } else {
1848 1848
             return false;
1849 1849
         }
1850 1850
     }
@@ -1856,82 +1856,82 @@  discard block
 block discarded – undo
1856 1856
     function get_call_waiting($select = "", $table = "", $status) {
1857 1857
         return ($status == 0) ? "Enable" : "Disable";
1858 1858
 	}
1859
-  function set_invoice_details($select= ''){
1859
+  function set_invoice_details($select = '') {
1860 1860
         $status_array = array("invoice_select" => "--Select--",
1861 1861
             "invoice_inactive" => "Deleted Invoices",
1862 1862
             "invoice_active" => "All Invoices",
1863 1863
         );
1864 1864
         return $status_array;
1865 1865
 }
1866
-function get_invoice_template($invoicedata,$accountdata,$flag){
1866
+function get_invoice_template($invoicedata, $accountdata, $flag) {
1867 1867
       $login_info = $this->CI->session->userdata('accountinfo');
1868 1868
 
1869 1869
       $invoice_config = $this->CI->db_model->getSelect("*", "invoice_conf", array('accountid'=>$login_info['id']));
1870
-      $invoice_config= $invoice_config->result_array();
1871
-      $invoice_config_res= $invoice_config[0];
1870
+      $invoice_config = $invoice_config->result_array();
1871
+      $invoice_config_res = $invoice_config[0];
1872 1872
 
1873 1873
       $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $accountdata["currency_id"]);
1874 1874
       $accountdata["country"] = $this->get_field_name('country', 'countrycode', $accountdata["country_id"]);
1875 1875
       $data["to_currency"] = Common_model::$global_config['system_config']['base_currency'];
1876
-      if($login_info['type'] == -1){
1876
+      if ($login_info['type'] == -1) {
1877 1877
           $currency = $data["to_currency"];
1878
-      }elseif($login_info['type'] == 1){
1878
+      }elseif ($login_info['type'] == 1) {
1879 1879
 	  $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $login_info["currency_id"]);
1880 1880
           $currency = $accountdata["currency_id"];
1881
-      }else{
1881
+      } else {
1882 1882
           $currency = $accountdata["currency_id"];
1883 1883
       }
1884
-      $decimal_amount=Common_model::$global_config['system_config']['decimalpoints'];
1884
+      $decimal_amount = Common_model::$global_config['system_config']['decimalpoints'];
1885 1885
       ob_start();
1886 1886
       $this->CI->load->library('/html2pdf/html2pdf');
1887
-      $this->CI->html2pdf = new HTML2PDF('P','A4','en');
1887
+      $this->CI->html2pdf = new HTML2PDF('P', 'A4', 'en');
1888 1888
       $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
1889
-      $template_config=$this->CI->config->item('invoice_template');
1889
+      $template_config = $this->CI->config->item('invoice_template');
1890 1890
       include($template_config.'invoice_template.php');
1891 1891
       $content = ob_get_clean();
1892 1892
       ob_clean();
1893 1893
 
1894 1894
 	$ACCOUNTADD = '';
1895
-	$ACCOUNTADD_CUSTOMER ='';
1895
+	$ACCOUNTADD_CUSTOMER = '';
1896 1896
 	$ACCOUNTADD_RIGHT = '';
1897 1897
 	$ACCOUNT_DESCRIPTION = '';
1898 1898
 	$ACCOUNT_CDRS = '';
1899
-	$ACCOUNT_TOTAL= '';
1899
+	$ACCOUNT_TOTAL = '';
1900 1900
 	$ACCOUNT_TOTAL_FINAL = '';
1901 1901
 	$ACCOUNT_FINAL = '';
1902
-	$CHARGE_ACCOUNT ='';
1902
+	$CHARGE_ACCOUNT = '';
1903 1903
 	$service_info = '';
1904 1904
 	$TotalChrg = "0.00";
1905 1905
 	$NETAMT = "0.00";
1906 1906
 	$TAXAMT = "0.00";
1907
-	$total_sum=0;
1908
-	$total_vat=0;
1907
+	$total_sum = 0;
1908
+	$total_vat = 0;
1909 1909
 	$fromdate = strtotime($invoicedata['from_date']);
1910
-	$from_date =date("Y-m-d",$fromdate);
1910
+	$from_date = date("Y-m-d", $fromdate);
1911 1911
 	$duedate = strtotime($invoicedata['due_date']);
1912
-	$due_date =date("Y-m-d",$duedate);
1912
+	$due_date = date("Y-m-d", $duedate);
1913 1913
 
1914 1914
 /*************************** Company Address Code START ***************************************************/
1915 1915
         $ACCOUNTADD .= '<tr>';
1916 1916
         $ACCOUNTADD .= '<td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>'.$invoice_config_res['company_name'].'</b></td>';
1917 1917
         $ACCOUNTADD .= '</tr>';
1918
-	if ( $invoice_config_res['address'] != ""){
1918
+	if ($invoice_config_res['address'] != "") {
1919 1919
 
1920 1920
         $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['address'].'</td></tr>';
1921 1921
     }
1922
-	if ( $invoice_config_res['city'] != ""){
1922
+	if ($invoice_config_res['city'] != "") {
1923 1923
 
1924 1924
         $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['city'].'</td></tr>';
1925 1925
     }
1926
-	if ( $invoice_config_res['province'] != ""){
1926
+	if ($invoice_config_res['province'] != "") {
1927 1927
 
1928 1928
         $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['province'].'</td></tr>';
1929 1929
     }
1930
-	if ( $invoice_config_res['country'] != ""){
1930
+	if ($invoice_config_res['country'] != "") {
1931 1931
 
1932 1932
         $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['country'].'</td></tr>';
1933 1933
     }
1934
-	if ( $invoice_config_res['zipcode'] != ""){
1934
+	if ($invoice_config_res['zipcode'] != "") {
1935 1935
 
1936 1936
         $ACCOUNTADD .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$invoice_config_res['zipcode'].'</td></tr>';
1937 1937
     }
@@ -1942,27 +1942,27 @@  discard block
 block discarded – undo
1942 1942
         $ACCOUNTADD_CUSTOMER .= '<table><tr>';
1943 1943
         $ACCOUNTADD_CUSTOMER .= '<td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;"><b>'.$accountdata['company_name'].'</b></td></tr>';
1944 1944
 
1945
-	if ( $accountdata['address_1'] != ""){
1945
+	if ($accountdata['address_1'] != "") {
1946 1946
 
1947 1947
         $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['address_1'].'</td></tr>';
1948 1948
     }
1949
-	if ( $accountdata['city'] != ""){
1949
+	if ($accountdata['city'] != "") {
1950 1950
 
1951 1951
         $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['city'].'</td></tr>';
1952 1952
     }
1953
-	if ( $accountdata['province'] != ""){
1953
+	if ($accountdata['province'] != "") {
1954 1954
 
1955 1955
         $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['province'].'</td></tr>';
1956 1956
     }
1957
-	if ( $accountdata['country'] != ""){
1957
+	if ($accountdata['country'] != "") {
1958 1958
 
1959 1959
         $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['country'].'</td></tr>';
1960 1960
     }
1961
-	if ( $accountdata['postal_code'] != ""){
1961
+	if ($accountdata['postal_code'] != "") {
1962 1962
 
1963 1963
         $ACCOUNTADD_CUSTOMER .= '<tr><td style="width:100%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;">'.$accountdata['postal_code'].'</td></tr>';
1964 1964
     }
1965
-    $ACCOUNTADD_CUSTOMER .="</table>"; 
1965
+    $ACCOUNTADD_CUSTOMER .= "</table>"; 
1966 1966
 /*************************** Customer Address Code END ***************************************************/
1967 1967
 
1968 1968
 
@@ -1972,7 +1972,7 @@  discard block
 block discarded – undo
1972 1972
 	$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Date</td>';
1973 1973
         $ACCOUNT_DESCRIPTION .= '<td  style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Description</td>';
1974 1974
         $ACCOUNT_DESCRIPTION .= '<td  style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Charge Type</td>';
1975
-	$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;text-align:right;">Amount ('.$currency .')</td>';
1975
+	$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;text-align:right;">Amount ('.$currency.')</td>';
1976 1976
         $ACCOUNT_DESCRIPTION .= '</tr>';
1977 1977
 
1978 1978
 
@@ -1980,23 +1980,23 @@  discard block
 block discarded – undo
1980 1980
 	$ACCOUNT_CDRS .= '<td style="width:40%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Description</td>';
1981 1981
 	$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Duration (Seconds)</td>';
1982 1982
         $ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;">Total Calls</td>';
1983
-	$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;text-align:right;">Amount ('.$currency .')</td>';
1983
+	$ACCOUNT_CDRS .= '<td style="width:20%;font-size: 12px;color:#fff;font-family:arial; line-height: 22px;text-align:right;">Amount ('.$currency.')</td>';
1984 1984
         $ACCOUNT_CDRS .= '</tr>';
1985 1985
 
1986 1986
 	/*** manual invoice **/
1987
-	$this->CI->db->where('item_type <>','INVPAY');
1988
-        $invoice_details = $this->CI->db_model->getSelect('*', 'invoice_details',array("invoiceid"=> $invoicedata['id'],'item_type <>'=> 'TAX' ));
1989
-	$invoice_details= $invoice_details->result_array();
1990
-	$total_sum=0;
1991
-	foreach($invoice_details as $charge_res){
1992
-	    if($charge_res['item_type'] == 'DIDCHRG' || $charge_res['item_type'] == 'SUBCHRG' || $charge_res['item_type'] == 'manual_inv' ){
1993
-		if($charge_res['item_type'] == 'manual_inv'){
1987
+	$this->CI->db->where('item_type <>', 'INVPAY');
1988
+        $invoice_details = $this->CI->db_model->getSelect('*', 'invoice_details', array("invoiceid"=> $invoicedata['id'], 'item_type <>'=> 'TAX'));
1989
+	$invoice_details = $invoice_details->result_array();
1990
+	$total_sum = 0;
1991
+	foreach ($invoice_details as $charge_res) {
1992
+	    if ($charge_res['item_type'] == 'DIDCHRG' || $charge_res['item_type'] == 'SUBCHRG' || $charge_res['item_type'] == 'manual_inv') {
1993
+		if ($charge_res['item_type'] == 'manual_inv') {
1994 1994
 			$charge_res['item_type'] = 'Manual Invoice';
1995 1995
 		}
1996
-		if($charge_res['item_type'] == 'DIDCHRG'){
1996
+		if ($charge_res['item_type'] == 'DIDCHRG') {
1997 1997
 			$charge_res['item_type'] = 'DID Charge';
1998 1998
 		}
1999
-		if($charge_res['item_type'] == 'SUBCHRG'){
1999
+		if ($charge_res['item_type'] == 'SUBCHRG') {
2000 2000
 			$charge_res['item_type'] = 'Subscription Charge';
2001 2001
 		}
2002 2002
 
@@ -2007,12 +2007,12 @@  discard block
 block discarded – undo
2007 2007
 
2008 2008
 		$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($this->CI->common_model->calculate_currency($charge_res['debit'])).'</td>';
2009 2009
 		$ACCOUNT_DESCRIPTION .= '</tr>';
2010
-	     }else{
2011
-            $cdrs_data = $this->CI->db_model->getSelect("sum(billseconds) as billseconds,count(*) as count", "cdrs", array("accountid" => $charge_res['accountid'],"calltype" => $charge_res['item_type']));
2010
+	     } else {
2011
+            $cdrs_data = $this->CI->db_model->getSelect("sum(billseconds) as billseconds,count(*) as count", "cdrs", array("accountid" => $charge_res['accountid'], "calltype" => $charge_res['item_type']));
2012 2012
             $cdrs_result = $cdrs_data->result_array();
2013
-	    if($cdrs_result[0]['count'] > 0 ){
2014
-		$cdrs_record_count=$cdrs_result[0]['count'] ;
2015
-		$cdrs_record_billseconds=$cdrs_result[0]['billseconds'] ;
2013
+	    if ($cdrs_result[0]['count'] > 0) {
2014
+		$cdrs_record_count = $cdrs_result[0]['count'];
2015
+		$cdrs_record_billseconds = $cdrs_result[0]['billseconds'];
2016 2016
 /*echo '<pre>'.$cdrs_record_count;
2017 2017
 print_r($cdrs_result);
2018 2018
 exit;*/
@@ -2030,8 +2030,8 @@  discard block
 block discarded – undo
2030 2030
 
2031 2031
 /**********************************Tax Apply Start********************************************************************/
2032 2032
 	$total_sum = $total_sum;
2033
-	$total_sum=$this->currency_decimal($this->CI->common_model->calculate_currency($total_sum));
2034
-        $invoice_tax = $this->CI->db_model->getSelect('*', 'invoice_details',array("invoiceid"=> $invoicedata['id'],'item_type '=> 'TAX'));
2033
+	$total_sum = $this->currency_decimal($this->CI->common_model->calculate_currency($total_sum));
2034
+        $invoice_tax = $this->CI->db_model->getSelect('*', 'invoice_details', array("invoiceid"=> $invoicedata['id'], 'item_type '=> 'TAX'));
2035 2035
  	//$ACCOUNT_TOTAL .= '<td><table style="width:100%;margin-left:360px;">';
2036 2036
 
2037 2037
 	$ACCOUNT_TOTAL .= '<tr>';
@@ -2041,35 +2041,35 @@  discard block
 block discarded – undo
2041 2041
 //	$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$total_sum .'</td>';
2042 2042
         $ACCOUNT_TOTAL .= '</tr>';
2043 2043
 
2044
-	if($invoice_tax->num_rows() > 0 ){
2045
-	   foreach($invoice_tax->result_array() as $invoice_tax){
2044
+	if ($invoice_tax->num_rows() > 0) {
2045
+	   foreach ($invoice_tax->result_array() as $invoice_tax) {
2046 2046
 
2047
-		$total_vat +=$invoice_tax['debit'];
2047
+		$total_vat += $invoice_tax['debit'];
2048 2048
 		$ACCOUNT_TOTAL .= '<tr>';
2049 2049
 		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;"></td>';
2050 2050
 		$ACCOUNT_TOTAL .= '<td style="width:40%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;"></td>';
2051 2051
 		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"><b>'.$invoice_tax["description"].':</b></td>';
2052
-		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($this->CI->common_model->calculate_currency($total_vat)) .'</td>';
2052
+		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($this->CI->common_model->calculate_currency($total_vat)).'</td>';
2053 2053
 		$ACCOUNT_TOTAL .= '</tr>';
2054 2054
 
2055 2055
 	   }
2056
-		$total_vat=$this->currency_decimal($this->CI->common_model->calculate_currency($total_vat));	
2057
-	}else{
2056
+		$total_vat = $this->currency_decimal($this->CI->common_model->calculate_currency($total_vat));	
2057
+	} else {
2058 2058
 /********harsh_308***********/
2059 2059
 		$ACCOUNT_TOTAL .= '<tr>';
2060 2060
 		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
2061 2061
 		$ACCOUNT_TOTAL .= '<td style="width:40%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
2062 2062
 		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"><b>Total TAX:</b></td>';
2063
-		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($total_vat) .'</td>';
2063
+		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($total_vat).'</td>';
2064 2064
 		$ACCOUNT_TOTAL .= '</tr>';
2065 2065
 
2066 2066
 	}
2067
-	$sub_total=$total_sum+$total_vat;
2067
+	$sub_total = $total_sum + $total_vat;
2068 2068
 	$ACCOUNT_TOTAL .= '<tr>';
2069 2069
 	$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
2070 2070
 	$ACCOUNT_TOTAL .= '<td style="width:40%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
2071 2071
 	$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"><b>Sub Total:</b></td>';
2072
-	$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($sub_total) .'</td>';
2072
+	$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($sub_total).'</td>';
2073 2073
 	$ACCOUNT_TOTAL .= '</tr>';
2074 2074
 
2075 2075
 
@@ -2098,26 +2098,26 @@  discard block
 block discarded – undo
2098 2098
 
2099 2099
 /*************************** Invoice Note Code END ***************************************************/
2100 2100
         $invoice_notes = $this->CI->db_model->getSelect('*', 'invoices', array('id'=>$invoicedata['id']));
2101
-        $invoice_notes=$invoice_notes->result_array();
2102
-	if(isset($invoice_notes[0]['notes'])){
2103
-		$invoice_notes=$invoice_notes[0]['notes'];
2104
-	}else{
2105
-		if($invoice_notes[0]['invoice_note'] == '0' ){
2106
-			$invoice_notes='THIS IS A 30 DAY ACCOUNT, SO PLEASE MAKE PAYMENT WITHIN THESE TERMS';
2107
-		}else{
2108
-			$invoice_notes=$invoice_notes[0]['invoice_note'];
2101
+        $invoice_notes = $invoice_notes->result_array();
2102
+	if (isset($invoice_notes[0]['notes'])) {
2103
+		$invoice_notes = $invoice_notes[0]['notes'];
2104
+	} else {
2105
+		if ($invoice_notes[0]['invoice_note'] == '0') {
2106
+			$invoice_notes = 'THIS IS A 30 DAY ACCOUNT, SO PLEASE MAKE PAYMENT WITHIN THESE TERMS';
2107
+		} else {
2108
+			$invoice_notes = $invoice_notes[0]['invoice_note'];
2109 2109
 		}
2110 2110
 	}
2111 2111
 /*************************** Invoice Note Code END ***************************************************/
2112 2112
 
2113 2113
 	if (file_exists(getcwd()."/upload/".$invoice_config[0]['accountid']."_".$invoice_config[0]['logo'])) {
2114
-		if($invoice_config[0]['logo'] != ''){
2115
-			$content = str_replace("<LOGO>",base_url()."upload/".$invoice_config[0]['accountid']."_".$invoice_config[0]['logo'],$content);
2116
-		}else{
2117
-			$content = str_replace("<LOGO>",base_url().'/assets/images/logo.png',$content);
2114
+		if ($invoice_config[0]['logo'] != '') {
2115
+			$content = str_replace("<LOGO>", base_url()."upload/".$invoice_config[0]['accountid']."_".$invoice_config[0]['logo'], $content);
2116
+		} else {
2117
+			$content = str_replace("<LOGO>", base_url().'/assets/images/logo.png', $content);
2118 2118
 		}
2119
-	}else{
2120
-		$content = str_replace("<LOGO>",base_url().'/assets/images/logo.png',$content);
2119
+	} else {
2120
+		$content = str_replace("<LOGO>", base_url().'/assets/images/logo.png', $content);
2121 2121
 	}
2122 2122
 
2123 2123
 	$ACCOUNT_TOTAL_FINAL .= '<tr>';
@@ -2126,37 +2126,37 @@  discard block
 block discarded – undo
2126 2126
 	$ACCOUNT_TOTAL_FINAL .= '</tr>';
2127 2127
 
2128 2128
       //  $content = str_replace("<LOGO>",$image_logo,$content);   
2129
-        $content = str_replace("<ACCOUNTADD>",$ACCOUNTADD,$content);
2130
-        $content = str_replace("<ACCOUNTADD_CUSTOMER>",$ACCOUNTADD_CUSTOMER,$content);
2131
-        $content = str_replace("<ACCOUNTADD_RIGHT>",$ACCOUNTADD_RIGHT,$content);
2132
-	$content = str_replace("<ACCOUNT_DESCRIPTION>",$ACCOUNT_DESCRIPTION,$content);
2133
-	$content = str_replace("<ACCOUNT_CDRS>",$ACCOUNT_CDRS,$content);
2134
-	$content = str_replace("<ACCOUNT_TOTAL>",$ACCOUNT_TOTAL,$content);
2135
-	$content = str_replace("<ACCOUNT_TOTAL_FINAL>",$ACCOUNT_TOTAL_FINAL,$content);
2136
-        $content = str_replace("<NOTES>",$invoice_notes,$content);
2129
+        $content = str_replace("<ACCOUNTADD>", $ACCOUNTADD, $content);
2130
+        $content = str_replace("<ACCOUNTADD_CUSTOMER>", $ACCOUNTADD_CUSTOMER, $content);
2131
+        $content = str_replace("<ACCOUNTADD_RIGHT>", $ACCOUNTADD_RIGHT, $content);
2132
+	$content = str_replace("<ACCOUNT_DESCRIPTION>", $ACCOUNT_DESCRIPTION, $content);
2133
+	$content = str_replace("<ACCOUNT_CDRS>", $ACCOUNT_CDRS, $content);
2134
+	$content = str_replace("<ACCOUNT_TOTAL>", $ACCOUNT_TOTAL, $content);
2135
+	$content = str_replace("<ACCOUNT_TOTAL_FINAL>", $ACCOUNT_TOTAL_FINAL, $content);
2136
+        $content = str_replace("<NOTES>", $invoice_notes, $content);
2137 2137
 
2138 2138
 //echo $content; exit;
2139 2139
 
2140
-	$invoice_path=$this->CI->config->item('invoices_path');
2140
+	$invoice_path = $this->CI->config->item('invoices_path');
2141 2141
 	$download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; 
2142 2142
        //echo  $download_path; exit;
2143 2143
        $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
2144 2144
        $this->CI->html2pdf->writeHTML($content);
2145 2145
        
2146
-       if($flag== 'TRUE'){
2146
+       if ($flag == 'TRUE') {
2147 2147
         $download_path = $invoicedata['invoice_prefix'].$invoicedata['invoiceid'].".pdf";
2148 2148
        
2149
-        $this->CI->html2pdf->Output($download_path,"D");        
2150
-       }else{
2149
+        $this->CI->html2pdf->Output($download_path, "D");        
2150
+       } else {
2151 2151
         $current_dir = getcwd()."/invoices/";
2152 2152
         $dir_name = $accountdata["id"];
2153
-        if(!is_dir($current_dir.$dir_name)){
2154
-                mkdir($current_dir.$dir_name,0777, true);
2153
+        if ( ! is_dir($current_dir.$dir_name)) {
2154
+                mkdir($current_dir.$dir_name, 0777, true);
2155 2155
                 chmod($current_dir.$dir_name, 0777);        
2156 2156
         }        
2157
-        $invoice_path=$this->CI->config->item('invoices_path');
2157
+        $invoice_path = $this->CI->config->item('invoices_path');
2158 2158
         $download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; 
2159
-        $this->CI->html2pdf->Output($download_path,"F");         
2159
+        $this->CI->html2pdf->Output($download_path, "F");         
2160 2160
        }
2161 2161
 }
2162 2162
     function reseller_select_value($select, $table, $id_where = '') {
@@ -2176,55 +2176,55 @@  discard block
 block discarded – undo
2176 2176
 	   return 'Admin';
2177 2177
     }
2178 2178
     
2179
-    function get_subreseller_info($parent_id){
2180
-        if(!empty($parent_id)){
2181
-	  $str=$parent_id.",";
2182
-        }else{
2183
-          $str=null;
2179
+    function get_subreseller_info($parent_id) {
2180
+        if ( ! empty($parent_id)) {
2181
+	  $str = $parent_id.",";
2182
+        } else {
2183
+          $str = null;
2184 2184
         }
2185 2185
         $query = "select id from accounts where reseller_id = '$parent_id' AND deleted =0 AND type=1";
2186 2186
         $result = $this->CI->db->query($query);
2187
-        if($result->num_rows() > 0){
2187
+        if ($result->num_rows() > 0) {
2188 2188
         $result = $result->result_array();
2189
-	  foreach ($result as $data){
2190
-	    if(!empty($data['id'])){
2191
-	      $str.=$this->get_subreseller_info($data['id']);
2189
+	  foreach ($result as $data) {
2190
+	    if ( ! empty($data['id'])) {
2191
+	      $str .= $this->get_subreseller_info($data['id']);
2192 2192
 	    }
2193 2193
 	  }
2194 2194
 	}
2195 2195
 	return $str;
2196 2196
     }
2197
-    function get_parent_info($child_id,$parent_id){
2198
-        if(!empty($child_id)){
2199
-	  $str=$child_id.",";
2200
-        }else{
2201
-          $str=null;
2197
+    function get_parent_info($child_id, $parent_id) {
2198
+        if ( ! empty($child_id)) {
2199
+	  $str = $child_id.",";
2200
+        } else {
2201
+          $str = null;
2202 2202
         }
2203
-        if($child_id > 0){
2203
+        if ($child_id > 0) {
2204 2204
         $query = "select reseller_id from accounts where id = '$child_id'";
2205 2205
         $result = $this->CI->db->query($query);
2206
-        if($result->num_rows() > 0){
2206
+        if ($result->num_rows() > 0) {
2207 2207
         $parent_info = (array)$result->first_row();
2208
-	  if($parent_info['reseller_id'] != $parent_id){
2209
-	    $str.=$this->get_parent_info($parent_info['reseller_id'],$parent_id);
2208
+	  if ($parent_info['reseller_id'] != $parent_id) {
2209
+	    $str .= $this->get_parent_info($parent_info['reseller_id'], $parent_id);
2210 2210
 	  }
2211 2211
 	}
2212 2212
 	}
2213 2213
 	return $str;
2214 2214
     }
2215
-    function get_did_accountid($select,$table,$where){
2216
-      $accountinfo=$this->CI->session->userdata('accountinfo');
2217
-      $this->CI->db->where('note',$where);
2218
-      $this->CI->db->where('parent_id',$accountinfo['id']);
2215
+    function get_did_accountid($select, $table, $where) {
2216
+      $accountinfo = $this->CI->session->userdata('accountinfo');
2217
+      $this->CI->db->where('note', $where);
2218
+      $this->CI->db->where('parent_id', $accountinfo['id']);
2219 2219
       $this->CI->db->select('reseller_id');
2220
-      $reseller_pricing_result=$this->CI->db->get('reseller_pricing');
2221
-      $account_info=(array)$reseller_pricing_result->first_row();
2222
-      $account_name=$this->get_field_name_coma_new('first_name,last_name,number','accounts',$account_info['reseller_id']);
2220
+      $reseller_pricing_result = $this->CI->db->get('reseller_pricing');
2221
+      $account_info = (array)$reseller_pricing_result->first_row();
2222
+      $account_name = $this->get_field_name_coma_new('first_name,last_name,number', 'accounts', $account_info['reseller_id']);
2223 2223
       return $account_name;     
2224 2224
     }
2225 2225
 
2226
-    function get_status_new($select = "",$table = "",$status = "") {
2227
-      return ($status['status']==0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
2226
+    function get_status_new($select = "", $table = "", $status = "") {
2227
+      return ($status['status'] == 0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
2228 2228
     }
2229 2229
     
2230 2230
 }
Please login to merge, or discard this patch.
Braces   +56 added lines, -52 removed lines patch added patch discarded remove patch
@@ -22,8 +22,9 @@  discard block
 block discarded – undo
22 22
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 23
 ###############################################################################
24 24
 
25
-if (!defined('BASEPATH'))
25
+if (!defined('BASEPATH')) {
26 26
     exit('No direct script access allowed');
27
+}
27 28
 
28 29
 /**
29 30
  * Dynamically build forms for display
@@ -112,8 +113,9 @@  discard block
 block discarded – undo
112 113
             $flag = false;
113 114
             $uname = $this->random_string($length);
114 115
             $uname = strtolower($uname);
115
-            if (isset($default))
116
-                $uname = $default . $uname;
116
+            if (isset($default)) {
117
+                            $uname = $default . $uname;
118
+            }
117 119
             if (!in_array($uname, $number)) {
118 120
                 $where = array($field => $uname);
119 121
                 $acc_result = $this->CI->db_model->getSelect('Count(id) as count', $tablename, $where);
@@ -230,15 +232,14 @@  discard block
 block discarded – undo
230 232
       $accountinfo=$this->CI->session->userdata('accountinfo');
231 233
       if($did_info['accountid'] ==0 && $did_info['parent_id']==0){
232 234
 	$status='Not in use';
233
-      }
234
-      elseif($accountinfo['type'] !=1){
235
+      } elseif($accountinfo['type'] !=1){
235 236
 	if($did_info['accountid'] ==0 && $did_info['parent_id'] > 0){
236 237
 	  $status='Purchase by Reseller';
237 238
 	}
238 239
 	if($did_info['accountid'] > 0 && $did_info['parent_id'] == 0){
239 240
 	  $status='Purchase by Customer';
240 241
 	}
241
-      }else{
242
+      } else{
242 243
        $where_arr=array('note'=>$did_info['number'],"parent_id"=>$accountinfo['id']);
243 244
        $this->db->where($where);
244 245
        $this->CI->db->select('reseller_id,parent_id');
@@ -261,10 +262,9 @@  discard block
 block discarded – undo
261 262
         $did_info=(array)$this->CI->db->get('dids')->first_row();
262 263
         if($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']){
263 264
 	    $flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
264
-	}
265
-        else if($accountinfo['type']!=1 && $did_info['parent_id'] != $accountinfo['id']){
265
+	} else if($accountinfo['type']!=1 && $did_info['parent_id'] != $accountinfo['id']){
266 266
 	    $flag_status = "<a href='../did_list_release/" . $did_info['id'] . "' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
267
-        }else{
267
+        } else{
268 268
 	    $reseller_id= $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
269 269
 	    $where = array("note" => $did_info['number'],'parent_id'=>$reseller_id);
270 270
             $this->CI->db->where($where);
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	    $reseller_pricing_info=(array)$this->CI->db->get('reseller_pricing')->first_row();
273 273
 	    if (isset($reseller_pricing_info) && !empty($reseller_pricing_info)) {
274 274
 		  $flag_status="<a href='../did/did_reseller_edit/delete/".$reseller_pricing_info['id']."' title='Reliase' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
275
-	    }else{
275
+	    } else{
276 276
 	      $flag_status="<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
277 277
 	    }
278 278
         }
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
 	<label class="onoffswitch-label" for=switch'.$status["id"].'>
475 475
      	<span class="onoffswitch-inner"></span>
476 476
 	</label></div>';
477
-	}else{
477
+	} else{
478 478
 	$status_array = '<div style="width: 100%; text-align: -moz-center; padding: 0;"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id=switch'.$status['id'].' value='.$status['status'].' onclick="javascript:processForm('.$status['id'].','.$status['table'].')">
479 479
 	<label class="onoffswitch-label" for=switch'.$status["id"].'>
480 480
      	<span class="onoffswitch-inner"></span>
481 481
 	</label></div>';
482 482
 	}
483
-	}else{
483
+	} else{
484 484
 		return ($status == 0) ? "Active" : "Inactive";
485 485
 	}
486 486
 	return $status_array;
@@ -854,9 +854,9 @@  discard block
 block discarded – undo
854 854
             $rel = (isset($button_params->layout) && $button_params->layout != '')?"facebox_".$button_params->layout:"facebox";
855 855
             return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" rel="'.$rel.'" title="Edit" ="small"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
856 856
             
857
-        }else if(strpos($link,'customer_edit') !== false){
857
+        } else if(strpos($link,'customer_edit') !== false){
858 858
         return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
859
-        }else {
859
+        } else {
860 860
             return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
861 861
         }
862 862
     }
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
 			} else {
873 873
 				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" title="Edit">' . $field . '</a>&nbsp;';
874 874
 			}
875
-		}else{ 
875
+		} else{ 
876 876
 			if ($button_params->mode == 'popup') {
877 877
 				return '<a href="' . $link . '" style="cursor:pointer;color:#005298;" rel="facebox" title="Update">' . $field . '</a>&nbsp;';
878 878
 			} else {
@@ -897,14 +897,18 @@  discard block
 block discarded – undo
897 897
         $data=  explode("/",$url);
898 898
         $link = base_url() . $url . "" . $linkid;
899 899
         foreach($data as $key=>$value){
900
-            if($value == 'price_delete')
901
-                $flag = '1';
902
-            if($value == 'trunk_remove')
903
-                $flag='2';
904
-            if($value == 'customer_delete' ||$value =='provider_delete')
905
-                $flag='3';
906
-            if($value == 'reseller_delete')
907
-                $flag='4';
900
+            if($value == 'price_delete') {
901
+                            $flag = '1';
902
+            }
903
+            if($value == 'trunk_remove') {
904
+                            $flag='2';
905
+            }
906
+            if($value == 'customer_delete' ||$value =='provider_delete') {
907
+                            $flag='3';
908
+            }
909
+            if($value == 'reseller_delete') {
910
+                            $flag='4';
911
+            }
908 912
             }    
909 913
             if($flag=='1'){
910 914
                 $where=array('pricelist_id'=>$linkid,'deleted !=' =>'1');
@@ -914,8 +918,7 @@  discard block
 block discarded – undo
914 918
                     if($rategroup_cnt > 0 || $customer_cnt > 0 ){
915 919
                         
916 920
                         return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$rategroup_cnt.','.$customer_cnt.','.$linkid.',1);"><i class="fa fa-trash fa-fw"></i></a>';
917
-                    }
918
-                    else{
921
+                    } else{
919 922
                         return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
920 923
                     }
921 924
             }
@@ -924,8 +927,7 @@  discard block
 block discarded – undo
924 927
                 $trunk_cnt=$this->get_field_count('id','outbound_routes',$where);
925 928
                 if($trunk_cnt > 0){
926 929
                     return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_message('.$trunk_cnt.',null,'.$linkid.',2);"><i class="fa fa-trash fa-fw"></i></a>';
927
-                }
928
-                else{
930
+                } else{
929 931
                     return '<a href="' . $link . '" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();"><i class="fa fa-trash fa-fw"></i></a>';
930 932
                 }
931 933
             }
@@ -1054,7 +1056,7 @@  discard block
 block discarded – undo
1054 1056
         $message = str_replace("</p>", "", $message);
1055 1057
 		if(isset($accountinfo['refill_amount']) && $accountinfo['refill_amount']!= ""){
1056 1058
 			$refillamount = $accountinfo['refill_amount'];
1057
-		}else{
1059
+		} else{
1058 1060
 			$refillamount = "0";
1059 1061
 		}
1060 1062
 		
@@ -1133,9 +1135,9 @@  discard block
 block discarded – undo
1133 1135
              case 'email_add_did';
1134 1136
 				if(isset($accountinfo['did_maxchannels']) && $accountinfo['did_maxchannels']!= ""){
1135 1137
 					$accountinfo['did_maxchannels'] = $accountinfo['did_maxchannels'];
1136
-				}else if($accountinfo['did_maxchannels'] == "0"){
1138
+				} else if($accountinfo['did_maxchannels'] == "0"){
1137 1139
 							$accountinfo['did_maxchannels'] = "Unlimited";
1138
-				}else{
1140
+				} else{
1139 1141
 					$accountinfo['did_maxchannels'] = "Unlimited";
1140 1142
 				}
1141 1143
                 $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
@@ -1230,8 +1232,9 @@  discard block
 block discarded – undo
1230 1232
         $select = "concat($cnt_str) as $select_params[0] ";
1231 1233
         $drp_array = $this->CI->db_model->getSelect($select, $table, $where);
1232 1234
         $drp_array = $drp_array->result();
1233
-        if (isset($drp_array[0]))
1234
-            return $drp_array[0]->$select_params[0];
1235
+        if (isset($drp_array[0])) {
1236
+                    return $drp_array[0]->$select_params[0];
1237
+        }
1235 1238
     }
1236 1239
 
1237 1240
     /* 
@@ -1248,10 +1251,10 @@  discard block
 block discarded – undo
1248 1251
 	    if($select == 'debit'){
1249 1252
 		if($result[0]['item_type'] == 'POSTCHARG'){
1250 1253
 	            return $this->convert_to_currency('', '', $result[0]['debit']);
1251
-		}else{
1254
+		} else{
1252 1255
 	            return $this->convert_to_currency('', '', $result[0]['credit']);
1253 1256
 		}
1254
-	    }else{
1257
+	    } else{
1255 1258
 		   return $result[0][$select];
1256 1259
 	    }
1257 1260
         } else {
@@ -1603,7 +1606,7 @@  discard block
 block discarded – undo
1603 1606
         }
1604 1607
         if ($show_currency_flag){
1605 1608
           return $calculated_amount." ".$currency_info['user_currency']['currency'];
1606
-        }else{
1609
+        } else{
1607 1610
           return $calculated_amount;
1608 1611
         }
1609 1612
     }
@@ -1823,7 +1826,7 @@  discard block
 block discarded – undo
1823 1826
 	      if($data['type']==1){
1824 1827
 		  $this->reseller_delete_dependencies($data['id']);
1825 1828
 		  $this->subreseller_list($data['id']);
1826
-	      }else{
1829
+	      } else{
1827 1830
 		  $this->customer_delete_dependencies($data['id']);
1828 1831
 	      }
1829 1832
             }
@@ -1844,7 +1847,7 @@  discard block
 block discarded – undo
1844 1847
         $result=$this->CI->db->get($table_name);
1845 1848
         if($result->num_rows() > 0){
1846 1849
             return $result->result_array();
1847
-        }else{
1850
+        } else{
1848 1851
             return false;
1849 1852
         }
1850 1853
     }
@@ -1875,10 +1878,10 @@  discard block
 block discarded – undo
1875 1878
       $data["to_currency"] = Common_model::$global_config['system_config']['base_currency'];
1876 1879
       if($login_info['type'] == -1){
1877 1880
           $currency = $data["to_currency"];
1878
-      }elseif($login_info['type'] == 1){
1881
+      } elseif($login_info['type'] == 1){
1879 1882
 	  $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $login_info["currency_id"]);
1880 1883
           $currency = $accountdata["currency_id"];
1881
-      }else{
1884
+      } else{
1882 1885
           $currency = $accountdata["currency_id"];
1883 1886
       }
1884 1887
       $decimal_amount=Common_model::$global_config['system_config']['decimalpoints'];
@@ -2007,7 +2010,7 @@  discard block
 block discarded – undo
2007 2010
 
2008 2011
 		$ACCOUNT_DESCRIPTION .= '<td style="width:20%;font-size: 12px;color:#525252;font-family:arial; line-height: 22px;text-align:right;">'.$this->currency_decimal($this->CI->common_model->calculate_currency($charge_res['debit'])).'</td>';
2009 2012
 		$ACCOUNT_DESCRIPTION .= '</tr>';
2010
-	     }else{
2013
+	     } else{
2011 2014
             $cdrs_data = $this->CI->db_model->getSelect("sum(billseconds) as billseconds,count(*) as count", "cdrs", array("accountid" => $charge_res['accountid'],"calltype" => $charge_res['item_type']));
2012 2015
             $cdrs_result = $cdrs_data->result_array();
2013 2016
 	    if($cdrs_result[0]['count'] > 0 ){
@@ -2054,7 +2057,7 @@  discard block
 block discarded – undo
2054 2057
 
2055 2058
 	   }
2056 2059
 		$total_vat=$this->currency_decimal($this->CI->common_model->calculate_currency($total_vat));	
2057
-	}else{
2060
+	} else{
2058 2061
 /********harsh_308***********/
2059 2062
 		$ACCOUNT_TOTAL .= '<tr>';
2060 2063
 		$ACCOUNT_TOTAL .= '<td style="width:20%;font-size: 12px;color:#000;font-family:arial; line-height: 22px;"></td>';
@@ -2101,10 +2104,10 @@  discard block
 block discarded – undo
2101 2104
         $invoice_notes=$invoice_notes->result_array();
2102 2105
 	if(isset($invoice_notes[0]['notes'])){
2103 2106
 		$invoice_notes=$invoice_notes[0]['notes'];
2104
-	}else{
2107
+	} else{
2105 2108
 		if($invoice_notes[0]['invoice_note'] == '0' ){
2106 2109
 			$invoice_notes='THIS IS A 30 DAY ACCOUNT, SO PLEASE MAKE PAYMENT WITHIN THESE TERMS';
2107
-		}else{
2110
+		} else{
2108 2111
 			$invoice_notes=$invoice_notes[0]['invoice_note'];
2109 2112
 		}
2110 2113
 	}
@@ -2113,10 +2116,10 @@  discard block
 block discarded – undo
2113 2116
 	if (file_exists(getcwd()."/upload/".$invoice_config[0]['accountid']."_".$invoice_config[0]['logo'])) {
2114 2117
 		if($invoice_config[0]['logo'] != ''){
2115 2118
 			$content = str_replace("<LOGO>",base_url()."upload/".$invoice_config[0]['accountid']."_".$invoice_config[0]['logo'],$content);
2116
-		}else{
2119
+		} else{
2117 2120
 			$content = str_replace("<LOGO>",base_url().'/assets/images/logo.png',$content);
2118 2121
 		}
2119
-	}else{
2122
+	} else{
2120 2123
 		$content = str_replace("<LOGO>",base_url().'/assets/images/logo.png',$content);
2121 2124
 	}
2122 2125
 
@@ -2147,7 +2150,7 @@  discard block
 block discarded – undo
2147 2150
         $download_path = $invoicedata['invoice_prefix'].$invoicedata['invoiceid'].".pdf";
2148 2151
        
2149 2152
         $this->CI->html2pdf->Output($download_path,"D");        
2150
-       }else{
2153
+       } else{
2151 2154
         $current_dir = getcwd()."/invoices/";
2152 2155
         $dir_name = $accountdata["id"];
2153 2156
         if(!is_dir($current_dir.$dir_name)){
@@ -2170,16 +2173,17 @@  discard block
 block discarded – undo
2170 2173
         $select = "concat($cnt_str) as $select_params[2] ";
2171 2174
         $drp_array = $this->CI->db_model->getSelect($select, $table, $where);
2172 2175
         $drp_array = $drp_array->result();
2173
-        if (isset($drp_array[0]))
2174
-            return $drp_array[0]->$select_params[2];
2175
-	else
2176
-	   return 'Admin';
2176
+        if (isset($drp_array[0])) {
2177
+                    return $drp_array[0]->$select_params[2];
2178
+        } else {
2179
+		   return 'Admin';
2180
+	}
2177 2181
     }
2178 2182
     
2179 2183
     function get_subreseller_info($parent_id){
2180 2184
         if(!empty($parent_id)){
2181 2185
 	  $str=$parent_id.",";
2182
-        }else{
2186
+        } else{
2183 2187
           $str=null;
2184 2188
         }
2185 2189
         $query = "select id from accounts where reseller_id = '$parent_id' AND deleted =0 AND type=1";
@@ -2197,7 +2201,7 @@  discard block
 block discarded – undo
2197 2201
     function get_parent_info($child_id,$parent_id){
2198 2202
         if(!empty($child_id)){
2199 2203
 	  $str=$child_id.",";
2200
-        }else{
2204
+        } else{
2201 2205
           $str=null;
2202 2206
         }
2203 2207
         if($child_id > 0){
Please login to merge, or discard this patch.
web_interface/astpp/application/libraries/astpp/email_lib.php 4 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -91,6 +91,9 @@  discard block
 block discarded – undo
91 91
         return false;
92 92
     }
93 93
 
94
+    /**
95
+     * @param string $detail_type
96
+     */
94 97
     function get_info($id,$detail_type)
95 98
     {
96 99
 	$where = array('id' => $id);
@@ -183,6 +186,10 @@  discard block
 block discarded – undo
183 186
 		}
184 187
 	}
185 188
     }
189
+
190
+    /**
191
+     * @param string $attachment
192
+     */
186 193
     function mail_history($attachment)
187 194
     {
188 195
 		$send_mail_details = array('from'=>$this->from,
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -22,61 +22,61 @@  discard block
 block discarded – undo
22 22
 ###############################################################################
23 23
 
24 24
 if (!defined('BASEPATH'))
25
-    exit('No direct script access allowed');
25
+	exit('No direct script access allowed');
26 26
 
27 27
 /**
28 28
  * Dynamically build forms for display
29 29
  */
30 30
 class email_lib {
31 31
 
32
-    protected $CI; // codeigniter
33
-    public $email='';
34
-    public $smtp='';
35
-    public $smtp_host='';
36
-    public $smtp_user='';
37
-    public $smtp_pass='';
38
-    public $smtp_port='';
39
-    public $message='';
40
-    public $from='';
41
-    public $to='';
42
-    public $subject='';
43
-    public $company_name='';
44
-    public $company_website='';
45
-    public $account_id='';
32
+	protected $CI; // codeigniter
33
+	public $email='';
34
+	public $smtp='';
35
+	public $smtp_host='';
36
+	public $smtp_user='';
37
+	public $smtp_pass='';
38
+	public $smtp_port='';
39
+	public $message='';
40
+	public $from='';
41
+	public $to='';
42
+	public $subject='';
43
+	public $company_name='';
44
+	public $company_website='';
45
+	public $account_id='';
46 46
 
47
-    function __construct($library_name = '') {
47
+	function __construct($library_name = '') {
48 48
 
49
-        $this->CI = & get_instance();
50
-        $this->CI->load->model('db_model');
51
-        $this->CI->load->library('email');
52
-        $this->CI->load->library('session');
53
-    }
49
+		$this->CI = & get_instance();
50
+		$this->CI->load->model('db_model');
51
+		$this->CI->load->library('email');
52
+		$this->CI->load->library('session');
53
+	}
54 54
 
55
-    function get_email_settings()
56
-    {
55
+	function get_email_settings()
56
+	{
57 57
 		$where = array('group_title' =>'email');
58
-	        $query = $this->CI->db_model->getSelect("*", "system", $where);
59
-	        $query = $query->result_array();
58
+			$query = $this->CI->db_model->getSelect("*", "system", $where);
59
+			$query = $query->result_array();
60 60
 		foreach($query as $key=>$val){
61 61
 			$tempvar = strtolower($val['name']);
62 62
 			$this->$tempvar=$val['value'];
63 63
 		}
64
-    }
64
+	}
65 65
 
66
-    function get_template( $type)
67
-    {
66
+	function get_template( $type)
67
+	{
68 68
 	$where = array('name' => $type);
69
-        $query = $this->CI->db_model->getSelect("*", "default_templates", $where);
70
-        $query = $query->result();
71
-        $this->message = $query[0]->template;
72
-        $this->subject = $query[0]->subject;
73
-    }
69
+		$query = $this->CI->db_model->getSelect("*", "default_templates", $where);
70
+		$query = $query->result();
71
+		$this->message = $query[0]->template;
72
+		$this->subject = $query[0]->subject;
73
+	}
74 74
 
75
-    function get_account_info($accountid)
76
-    {
75
+	function get_account_info($accountid)
76
+	{
77 77
 	$where = array('id' => $accountid);
78
-        $query = $this->CI->db_model->getSelect("*", "accounts", $where);
79
-        $query = $query->result_array();
78
+		$query = $this->CI->db_model->getSelect("*", "accounts", $where);
79
+		$query = $query->result_array();
80 80
 	if(isset($query[0]['email']) && $query[0]['email']!=''){
81 81
 		$query[0]['currency_name']=$this->CI->common->get_field_name('currency', 'currency', $query[0]['currency_id']);
82 82
 		$query[0]['timezone_name']=$this->CI->common->get_field_name('gmtzone', 'timezone', $query[0]['timezone_id']);
@@ -88,26 +88,26 @@  discard block
 block discarded – undo
88 88
 		unset($query[0]['number']);
89 89
 		return $query[0];
90 90
 	}
91
-        return false;
92
-    }
91
+		return false;
92
+	}
93 93
 
94
-    function get_info($id,$detail_type)
95
-    {
94
+	function get_info($id,$detail_type)
95
+	{
96 96
 	$where = array('id' => $id);
97
-        $query = $this->CI->db_model->getSelect("*", $detail_type, $where);
98
-        $query = $query->result_array();
97
+		$query = $this->CI->db_model->getSelect("*", $detail_type, $where);
98
+		$query = $query->result_array();
99 99
 	if(isset($query[0]['accountid'])){
100 100
 		$query=$this->get_account_info($query [0]['accountid']);
101 101
 		return $query[0];
102 102
 	}
103 103
 	return false;
104
-    }
104
+	}
105 105
 
106
-    function get_admin_details()
107
-    {
106
+	function get_admin_details()
107
+	{
108 108
 	$where = array();
109
-        $query = $this->CI->db_model->getSelect("*", "invoice_conf", $where);
110
-        $query = $query->result();
109
+		$query = $this->CI->db_model->getSelect("*", "invoice_conf", $where);
110
+		$query = $query->result();
111 111
 	if(isset($query[0]->emailaddress) && $query[0]->emailaddress!=''){
112 112
 		$this->company_website=$query[0]->website;
113 113
 		$this->from=$query[0]->emailaddress;
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 		return true;
116 116
 	}
117 117
 	return false;
118
-    }
118
+	}
119 119
 
120
-    function build_template($template_type,$detail,$detail_type='') {
120
+	function build_template($template_type,$detail,$detail_type='') {
121 121
 	if(!is_array($template_type))
122 122
 		$this->get_template($template_type);
123 123
 	else{
@@ -162,29 +162,29 @@  discard block
 block discarded – undo
162 162
 		$this->subject = str_replace("#COMPANY_NAME#", $this->company_name, $this->subject);
163 163
 		switch ($template_type) {
164 164
 		  case 'email_add_user':
165
-		        $this->message = str_replace('#NUMBER#', $templateinfo['username'], $this->message);
166
-		        break;
165
+				$this->message = str_replace('#NUMBER#', $templateinfo['username'], $this->message);
166
+				break;
167 167
 		  case 'email_calling_card':
168
-		        $this->message = str_replace('#CARDNUMBER#', $templateinfo['cardnumber'], $this->message);
169
-		        break;
168
+				$this->message = str_replace('#CARDNUMBER#', $templateinfo['cardnumber'], $this->message);
169
+				break;
170 170
 		  case 'email_new_invoice';
171
-		        $this->message = str_replace('#AMOUNT#', $templateinfo['amount'], $this->message);
172
-		        $this->message = str_replace('#INVOICE_NUMBER#', $templateinfo['id'], $this->message);
173
-		        $this->subject = str_replace("#INVOICE_NUMBER#", $templateinfo['id'], $this->subject);
171
+				$this->message = str_replace('#AMOUNT#', $templateinfo['amount'], $this->message);
172
+				$this->message = str_replace('#INVOICE_NUMBER#', $templateinfo['id'], $this->message);
173
+				$this->subject = str_replace("#INVOICE_NUMBER#", $templateinfo['id'], $this->subject);
174 174
 			break;	
175 175
 		  case 'email_add_did';
176
-		        $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
177
-		        $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
176
+				$this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
177
+				$this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
178 178
 			break;	
179 179
 		  case 'email_remove_did';
180
-		        $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
181
-		        $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
180
+				$this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
181
+				$this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
182 182
 			break;	
183 183
 		}
184 184
 	}
185
-    }
186
-    function mail_history($attachment)
187
-    {
185
+	}
186
+	function mail_history($attachment)
187
+	{
188 188
 		$send_mail_details = array('from'=>$this->from,
189 189
 			   'to'=>$this->to,
190 190
 			   'subject'=>$this->subject,
@@ -195,15 +195,15 @@  discard block
 block discarded – undo
195 195
 			  );
196 196
 		$this->CI->db->insert('mail_details',$send_mail_details);
197 197
 		return $this->CI->db->insert_id();
198
-    }
199
-    function update_mail_history($id)
200
-    {
198
+	}
199
+	function update_mail_history($id)
200
+	{
201 201
 		$this->CI->db->where(array('id' => $id));
202 202
 		$send_mail_details = array('status'=>'0');
203 203
 		$this->CI->db->update('mail_details',$send_mail_details);
204
-    }
205
-    function set_email_paramenters($details)
206
-    {
204
+	}
205
+	function set_email_paramenters($details)
206
+	{
207 207
 		if(!is_array($details)){
208 208
 			$this->get_admin_details();
209 209
 			$where = array('id'=>$details);
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 		$this->to=$details['to'];
217 217
 		$this->subject=$details['subject'];
218 218
 		$this->account_id=$details['accountid'];
219
-    }
220
-    function get_smtp_details()
221
-    {
219
+	}
220
+	function get_smtp_details()
221
+	{
222 222
 	if($this->smtp_port=='' || $this->smtp_host=='' || $this->smtp_user=='' || $this->smtp_pass=='')exit;
223 223
 		$config['protocol'] = "smtp";
224 224
 		$config['smtp_host'] = $this->smtp_host;
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
 		$config['mailtype'] = "html";
230 230
 		$config['newline'] = "\r\n";
231 231
 		$this->CI->email->initialize($config);
232
-    }
232
+	}
233 233
 
234
-    function send_email($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) {
234
+	function send_email($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) {
235 235
 	$this->get_email_settings();
236 236
 	if(!$this->email){
237 237
 		if(!$resend){
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		}
242 242
 
243 243
 		if(!$brodcast)
244
-	        	$history_id=$this->mail_history($attachment);
244
+				$history_id=$this->mail_history($attachment);
245 245
 		else	
246 246
 			$history_id=$details['history_id'];
247 247
 		if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 
258 258
 			if($attachment!="")
259 259
 			{
260
-			        $attac_exp=explode(",",$attachment);
261
-		       	  	foreach($attac_exp as $key=>$value){
260
+					$attac_exp=explode(",",$attachment);
261
+			   	  	foreach($attac_exp as $key=>$value){
262 262
 			   		if($value != ''){
263
-			       	$this->CI->email->attach(getcwd()."/attachments/".$value);       	  	
263
+				   	$this->CI->email->attach(getcwd()."/attachments/".$value);       	  	
264 264
 				   	}
265 265
 				}
266 266
 			}
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
 			$this->update_mail_history($history_id);
270 270
 		}					
271 271
 	}
272
-    }
272
+	}
273 273
 /**
274 274
 ASTPP  3.0 
275 275
 Add For Signup Module
276 276
 **/
277
-    function send_mail($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) {
277
+	function send_mail($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) {
278 278
 	$this->get_email_settings();
279 279
 	if(!$this->email){
280 280
 		
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		}
286 286
 
287 287
 		if(!$brodcast)
288
-	        	$history_id=$this->mail_history($attachment);
288
+				$history_id=$this->mail_history($attachment);
289 289
 		else	
290 290
 			$history_id=$details['history_id'];
291 291
 		if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){
@@ -302,6 +302,6 @@  discard block
 block discarded – undo
302 302
 			$this->update_mail_history($history_id);
303 303
 		}					
304 304
 	}
305
-    }
305
+	}
306 306
 }
307 307
 
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 /**
@@ -30,19 +30,19 @@  discard block
 block discarded – undo
30 30
 class email_lib {
31 31
 
32 32
     protected $CI; // codeigniter
33
-    public $email='';
34
-    public $smtp='';
35
-    public $smtp_host='';
36
-    public $smtp_user='';
37
-    public $smtp_pass='';
38
-    public $smtp_port='';
39
-    public $message='';
40
-    public $from='';
41
-    public $to='';
42
-    public $subject='';
43
-    public $company_name='';
44
-    public $company_website='';
45
-    public $account_id='';
33
+    public $email = '';
34
+    public $smtp = '';
35
+    public $smtp_host = '';
36
+    public $smtp_user = '';
37
+    public $smtp_pass = '';
38
+    public $smtp_port = '';
39
+    public $message = '';
40
+    public $from = '';
41
+    public $to = '';
42
+    public $subject = '';
43
+    public $company_name = '';
44
+    public $company_website = '';
45
+    public $account_id = '';
46 46
 
47 47
     function __construct($library_name = '') {
48 48
 
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
 		$where = array('group_title' =>'email');
58 58
 	        $query = $this->CI->db_model->getSelect("*", "system", $where);
59 59
 	        $query = $query->result_array();
60
-		foreach($query as $key=>$val){
60
+		foreach ($query as $key=>$val) {
61 61
 			$tempvar = strtolower($val['name']);
62
-			$this->$tempvar=$val['value'];
62
+			$this->$tempvar = $val['value'];
63 63
 		}
64 64
     }
65 65
 
66
-    function get_template( $type)
66
+    function get_template($type)
67 67
     {
68 68
 	$where = array('name' => $type);
69 69
         $query = $this->CI->db_model->getSelect("*", "default_templates", $where);
@@ -77,27 +77,27 @@  discard block
 block discarded – undo
77 77
 	$where = array('id' => $accountid);
78 78
         $query = $this->CI->db_model->getSelect("*", "accounts", $where);
79 79
         $query = $query->result_array();
80
-	if(isset($query[0]['email']) && $query[0]['email']!=''){
81
-		$query[0]['currency_name']=$this->CI->common->get_field_name('currency', 'currency', $query[0]['currency_id']);
82
-		$query[0]['timezone_name']=$this->CI->common->get_field_name('gmtzone', 'timezone', $query[0]['timezone_id']);
83
-		$query[0]['country_name']=$this->CI->common->get_field_name('country', 'countrycode', $query[0]['country_id']);
84
-		$this->to=$query[0]['email'];
80
+	if (isset($query[0]['email']) && $query[0]['email'] != '') {
81
+		$query[0]['currency_name'] = $this->CI->common->get_field_name('currency', 'currency', $query[0]['currency_id']);
82
+		$query[0]['timezone_name'] = $this->CI->common->get_field_name('gmtzone', 'timezone', $query[0]['timezone_id']);
83
+		$query[0]['country_name'] = $this->CI->common->get_field_name('country', 'countrycode', $query[0]['country_id']);
84
+		$this->to = $query[0]['email'];
85 85
 		$this->account_id = $query[0]['id'];
86 86
 		unset($query[0]['id']);
87
-		$query[0]['username']=$query[0]['number'];
87
+		$query[0]['username'] = $query[0]['number'];
88 88
 		unset($query[0]['number']);
89 89
 		return $query[0];
90 90
 	}
91 91
         return false;
92 92
     }
93 93
 
94
-    function get_info($id,$detail_type)
94
+    function get_info($id, $detail_type)
95 95
     {
96 96
 	$where = array('id' => $id);
97 97
         $query = $this->CI->db_model->getSelect("*", $detail_type, $where);
98 98
         $query = $query->result_array();
99
-	if(isset($query[0]['accountid'])){
100
-		$query=$this->get_account_info($query [0]['accountid']);
99
+	if (isset($query[0]['accountid'])) {
100
+		$query = $this->get_account_info($query [0]['accountid']);
101 101
 		return $query[0];
102 102
 	}
103 103
 	return false;
@@ -108,47 +108,47 @@  discard block
 block discarded – undo
108 108
 	$where = array();
109 109
         $query = $this->CI->db_model->getSelect("*", "invoice_conf", $where);
110 110
         $query = $query->result();
111
-	if(isset($query[0]->emailaddress) && $query[0]->emailaddress!=''){
112
-		$this->company_website=$query[0]->website;
113
-		$this->from=$query[0]->emailaddress;
114
-		$this->company_name=$query[0]->company_name;
111
+	if (isset($query[0]->emailaddress) && $query[0]->emailaddress != '') {
112
+		$this->company_website = $query[0]->website;
113
+		$this->from = $query[0]->emailaddress;
114
+		$this->company_name = $query[0]->company_name;
115 115
 		return true;
116 116
 	}
117 117
 	return false;
118 118
     }
119 119
 
120
-    function build_template($template_type,$detail,$detail_type='') {
121
-	if(!is_array($template_type))
120
+    function build_template($template_type, $detail, $detail_type = '') {
121
+	if ( ! is_array($template_type))
122 122
 		$this->get_template($template_type);
123
-	else{
124
-		$this->message=$template_type['message'];
125
-		$this->subject=$template_type['subject'];
126
-		$template_type='';
123
+	else {
124
+		$this->message = $template_type['message'];
125
+		$this->subject = $template_type['subject'];
126
+		$template_type = '';
127 127
 	}
128
-	if(is_array($detail))
128
+	if (is_array($detail))
129 129
 	{
130
-		$templateinfo=$detail;
131
-		if(isset($detail['email'])){
132
-			$this->to=$detail['email'];
130
+		$templateinfo = $detail;
131
+		if (isset($detail['email'])) {
132
+			$this->to = $detail['email'];
133 133
 		}
134 134
 /*****
135 135
 ASTPP  3.0 
136 136
 Email test
137 137
 ****/
138
-		if(isset($templateinfo['number'])){	
139
-			$templateinfo['username']=$templateinfo['number'];
138
+		if (isset($templateinfo['number'])) {	
139
+			$templateinfo['username'] = $templateinfo['number'];
140 140
 		}
141 141
 
142 142
 /*************/
143
-		$this->account_id=$templateinfo['accountid'];
143
+		$this->account_id = $templateinfo['accountid'];
144 144
 		unset($templateinfo['number']);
145 145
 	}
146
-	else if(!is_array($detail) && $detail_type=='')
147
-		$templateinfo=$this->get_account_info($detail);
146
+	else if ( ! is_array($detail) && $detail_type == '')
147
+		$templateinfo = $this->get_account_info($detail);
148 148
 	else
149
-		$templateinfo=$this->get_info($detail,$detail_type);
149
+		$templateinfo = $this->get_info($detail, $detail_type);
150 150
 
151
-	if($this->get_admin_details() && is_array($templateinfo) && isset($templateinfo['first_name']) && $templateinfo['first_name']!=''){
151
+	if ($this->get_admin_details() && is_array($templateinfo) && isset($templateinfo['first_name']) && $templateinfo['first_name'] != '') {
152 152
 		$this->message = html_entity_decode($this->message);
153 153
 		$this->message = str_replace("#COMPANY_EMAIL#", $this->from, $this->message);
154 154
 		$this->message = str_replace("#COMPANY_NAME#", $this->company_name, $this->message);
@@ -193,33 +193,33 @@  discard block
 block discarded – undo
193 193
 			   'status'=>'1',
194 194
 			   'attachment'=>$attachment
195 195
 			  );
196
-		$this->CI->db->insert('mail_details',$send_mail_details);
196
+		$this->CI->db->insert('mail_details', $send_mail_details);
197 197
 		return $this->CI->db->insert_id();
198 198
     }
199 199
     function update_mail_history($id)
200 200
     {
201 201
 		$this->CI->db->where(array('id' => $id));
202 202
 		$send_mail_details = array('status'=>'0');
203
-		$this->CI->db->update('mail_details',$send_mail_details);
203
+		$this->CI->db->update('mail_details', $send_mail_details);
204 204
     }
205 205
     function set_email_paramenters($details)
206 206
     {
207
-		if(!is_array($details)){
207
+		if ( ! is_array($details)) {
208 208
 			$this->get_admin_details();
209 209
 			$where = array('id'=>$details);
210 210
 			$query = $this->CI->db_model->getSelect("*", "mail_details", $where);
211 211
 			$query = $query->result_array();
212
-			$details=$query[0];
212
+			$details = $query[0];
213 213
 		}
214
-		$this->message=$details['body'];
215
-		$this->from=$details['from'];
216
-		$this->to=$details['to'];
217
-		$this->subject=$details['subject'];
218
-		$this->account_id=$details['accountid'];
214
+		$this->message = $details['body'];
215
+		$this->from = $details['from'];
216
+		$this->to = $details['to'];
217
+		$this->subject = $details['subject'];
218
+		$this->account_id = $details['accountid'];
219 219
     }
220 220
     function get_smtp_details()
221 221
     {
222
-	if($this->smtp_port=='' || $this->smtp_host=='' || $this->smtp_user=='' || $this->smtp_pass=='')exit;
222
+	if ($this->smtp_port == '' || $this->smtp_host == '' || $this->smtp_user == '' || $this->smtp_pass == '')exit;
223 223
 		$config['protocol'] = "smtp";
224 224
 		$config['smtp_host'] = $this->smtp_host;
225 225
 		$config['smtp_port'] = $this->smtp_port;
@@ -231,21 +231,21 @@  discard block
 block discarded – undo
231 231
 		$this->CI->email->initialize($config);
232 232
     }
233 233
 
234
-    function send_email($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) {
234
+    function send_email($template_type, $details, $detail_type = '', $attachment = '', $resend = 0, $mass_mail = 0, $brodcast = 0) {
235 235
 	$this->get_email_settings();
236
-	if(!$this->email){
237
-		if(!$resend){
238
-			$this->build_template($template_type,$details,$detail_type);
239
-		}else{
236
+	if ( ! $this->email) {
237
+		if ( ! $resend) {
238
+			$this->build_template($template_type, $details, $detail_type);
239
+		} else {
240 240
 			$this->set_email_paramenters($details);
241 241
 		}
242 242
 
243
-		if(!$brodcast)
244
-	        	$history_id=$this->mail_history($attachment);
243
+		if ( ! $brodcast)
244
+	        	$history_id = $this->mail_history($attachment);
245 245
 		else	
246
-			$history_id=$details['history_id'];
247
-		if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){
248
-			if(!$this->smtp){
246
+			$history_id = $details['history_id'];
247
+		if (isset($this->from) && $this->from != '' && isset($this->to) && $this->to != '' && ! $mass_mail) {
248
+			if ( ! $this->smtp) {
249 249
 				$this->get_smtp_details();
250 250
 			}			
251 251
 			$this->CI->email->from($this->from, $this->company_name);
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 			eval("\$message = \"".$this->message."\";");
256 256
 			$this->CI->email->message($this->message);
257 257
 
258
-			if($attachment!="")
258
+			if ($attachment != "")
259 259
 			{
260
-			        $attac_exp=explode(",",$attachment);
261
-		       	  	foreach($attac_exp as $key=>$value){
262
-			   		if($value != ''){
260
+			        $attac_exp = explode(",", $attachment);
261
+		       	  	foreach ($attac_exp as $key=>$value) {
262
+			   		if ($value != '') {
263 263
 			       	$this->CI->email->attach(getcwd()."/attachments/".$value);       	  	
264 264
 				   	}
265 265
 				}
@@ -274,22 +274,22 @@  discard block
 block discarded – undo
274 274
 ASTPP  3.0 
275 275
 Add For Signup Module
276 276
 **/
277
-    function send_mail($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) {
277
+    function send_mail($template_type, $details, $detail_type = '', $attachment = '', $resend = 0, $mass_mail = 0, $brodcast = 0) {
278 278
 	$this->get_email_settings();
279
-	if(!$this->email){
279
+	if ( ! $this->email) {
280 280
 		
281
-		if(!$resend){
282
-			$this->build_template($template_type,$details,$detail_type);
283
-		}else{
281
+		if ( ! $resend) {
282
+			$this->build_template($template_type, $details, $detail_type);
283
+		} else {
284 284
 			$this->set_email_paramenters($details);
285 285
 		}
286 286
 
287
-		if(!$brodcast)
288
-	        	$history_id=$this->mail_history($attachment);
287
+		if ( ! $brodcast)
288
+	        	$history_id = $this->mail_history($attachment);
289 289
 		else	
290
-			$history_id=$details['history_id'];
291
-		if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){
292
-			if(!$this->smtp){
290
+			$history_id = $details['history_id'];
291
+		if (isset($this->from) && $this->from != '' && isset($this->to) && $this->to != '' && ! $mass_mail) {
292
+			if ( ! $this->smtp) {
293 293
 				$this->get_smtp_details();
294 294
 			}			
295 295
 			$this->CI->email->from($this->from, $this->company_name);
Please login to merge, or discard this patch.
Braces   +24 added lines, -19 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
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 29
  * Dynamically build forms for display
@@ -118,9 +119,9 @@  discard block
 block discarded – undo
118 119
     }
119 120
 
120 121
     function build_template($template_type,$detail,$detail_type='') {
121
-	if(!is_array($template_type))
122
-		$this->get_template($template_type);
123
-	else{
122
+	if(!is_array($template_type)) {
123
+			$this->get_template($template_type);
124
+	} else{
124 125
 		$this->message=$template_type['message'];
125 126
 		$this->subject=$template_type['subject'];
126 127
 		$template_type='';
@@ -142,11 +143,11 @@  discard block
 block discarded – undo
142 143
 /*************/
143 144
 		$this->account_id=$templateinfo['accountid'];
144 145
 		unset($templateinfo['number']);
146
+	} else if(!is_array($detail) && $detail_type=='') {
147
+			$templateinfo=$this->get_account_info($detail);
148
+	} else {
149
+			$templateinfo=$this->get_info($detail,$detail_type);
145 150
 	}
146
-	else if(!is_array($detail) && $detail_type=='')
147
-		$templateinfo=$this->get_account_info($detail);
148
-	else
149
-		$templateinfo=$this->get_info($detail,$detail_type);
150 151
 
151 152
 	if($this->get_admin_details() && is_array($templateinfo) && isset($templateinfo['first_name']) && $templateinfo['first_name']!=''){
152 153
 		$this->message = html_entity_decode($this->message);
@@ -219,7 +220,9 @@  discard block
 block discarded – undo
219 220
     }
220 221
     function get_smtp_details()
221 222
     {
222
-	if($this->smtp_port=='' || $this->smtp_host=='' || $this->smtp_user=='' || $this->smtp_pass=='')exit;
223
+	if($this->smtp_port=='' || $this->smtp_host=='' || $this->smtp_user=='' || $this->smtp_pass=='') {
224
+		exit;
225
+	}
223 226
 		$config['protocol'] = "smtp";
224 227
 		$config['smtp_host'] = $this->smtp_host;
225 228
 		$config['smtp_port'] = $this->smtp_port;
@@ -236,14 +239,15 @@  discard block
 block discarded – undo
236 239
 	if(!$this->email){
237 240
 		if(!$resend){
238 241
 			$this->build_template($template_type,$details,$detail_type);
239
-		}else{
242
+		} else{
240 243
 			$this->set_email_paramenters($details);
241 244
 		}
242 245
 
243
-		if(!$brodcast)
244
-	        	$history_id=$this->mail_history($attachment);
245
-		else	
246
-			$history_id=$details['history_id'];
246
+		if(!$brodcast) {
247
+			        	$history_id=$this->mail_history($attachment);
248
+		} else {
249
+					$history_id=$details['history_id'];
250
+		}
247 251
 		if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){
248 252
 			if(!$this->smtp){
249 253
 				$this->get_smtp_details();
@@ -280,14 +284,15 @@  discard block
 block discarded – undo
280 284
 		
281 285
 		if(!$resend){
282 286
 			$this->build_template($template_type,$details,$detail_type);
283
-		}else{
287
+		} else{
284 288
 			$this->set_email_paramenters($details);
285 289
 		}
286 290
 
287
-		if(!$brodcast)
288
-	        	$history_id=$this->mail_history($attachment);
289
-		else	
290
-			$history_id=$details['history_id'];
291
+		if(!$brodcast) {
292
+			        	$history_id=$this->mail_history($attachment);
293
+		} else {
294
+					$history_id=$details['history_id'];
295
+		}
291 296
 		if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){
292 297
 			if(!$this->smtp){
293 298
 				$this->get_smtp_details();
Please login to merge, or discard this patch.
web_interface/astpp/application/libraries/astpp/form.php 4 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -52,8 +52,6 @@
 block discarded – undo
52 52
 // __construct
53 53
     /**
54 54
      * adds raw html to the field array
55
-     * @param type $label
56
-     * @param type $field add
57 55
      */
58 56
     function check_permissions() {
59 57
         if ($this->CI->session->userdata('user_login') == TRUE) {
Please login to merge, or discard this patch.
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -22,182 +22,182 @@  discard block
 block discarded – undo
22 22
 ###############################################################################
23 23
 
24 24
 if (!defined('BASEPATH'))
25
-    exit('No direct script access allowed');
25
+	exit('No direct script access allowed');
26 26
 
27 27
 /**
28 28
  * Dynamically build forms for display
29 29
  */
30 30
 class Form {
31 31
 
32
-    protected $CI; // codeigniter
33
-    protected $fields = array();  // array of fields
34
-    protected $form_title = 'Form';
35
-    protected $form_id = 'form';
36
-    protected $form_action = '';
37
-    protected $form_class = '';
38
-    protected $hidden = array();
39
-    protected $multipart = FALSE; // default to standard form
40
-    protected $submit_button = 'Submit';
41
-    protected $after_button = '';
42
-    protected $rules = array(); // storage for validation rules
43
-
44
-    function __construct() {
45
-        $this->CI = & get_instance();
46
-        $this->CI->load->library('form_validation');
47
-        $this->CI->load->library('astpp/common');
48
-        $this->CI->load->model('db_model');
49
-        $this->check_permissions();
50
-    }
32
+	protected $CI; // codeigniter
33
+	protected $fields = array();  // array of fields
34
+	protected $form_title = 'Form';
35
+	protected $form_id = 'form';
36
+	protected $form_action = '';
37
+	protected $form_class = '';
38
+	protected $hidden = array();
39
+	protected $multipart = FALSE; // default to standard form
40
+	protected $submit_button = 'Submit';
41
+	protected $after_button = '';
42
+	protected $rules = array(); // storage for validation rules
43
+
44
+	function __construct() {
45
+		$this->CI = & get_instance();
46
+		$this->CI->load->library('form_validation');
47
+		$this->CI->load->library('astpp/common');
48
+		$this->CI->load->model('db_model');
49
+		$this->check_permissions();
50
+	}
51 51
 
52 52
 // __construct
53
-    /**
54
-     * adds raw html to the field array
55
-     * @param type $label
56
-     * @param type $field add
57
-     */
58
-    function check_permissions() {
59
-        if ($this->CI->session->userdata('user_login') == TRUE) {
60
-            $module_info = unserialize($this->CI->session->userdata("permited_modules"));
61
-            if($this->CI->session->userdata('userlevel_logintype')!= 0 && $this->CI->session->userdata('userlevel_logintype')!= 3){
62
-	    $module_info[]='dashboard';
63
-            }
64
-            $url = $this->CI->uri->uri_string;
65
-            $file_name = explode("/", $url);
66
-            if(isset($file_name['1']) ){
67
-	      $module = explode('_', $file_name['1']);
68
-            }else{
69
-              $module=$file_name;
70
-            }
71
-            if($this->CI->session->userdata('userlevel_logintype')==1 ){
53
+	/**
54
+	 * adds raw html to the field array
55
+	 * @param type $label
56
+	 * @param type $field add
57
+	 */
58
+	function check_permissions() {
59
+		if ($this->CI->session->userdata('user_login') == TRUE) {
60
+			$module_info = unserialize($this->CI->session->userdata("permited_modules"));
61
+			if($this->CI->session->userdata('userlevel_logintype')!= 0 && $this->CI->session->userdata('userlevel_logintype')!= 3){
62
+		$module_info[]='dashboard';
63
+			}
64
+			$url = $this->CI->uri->uri_string;
65
+			$file_name = explode("/", $url);
66
+			if(isset($file_name['1']) ){
67
+		  $module = explode('_', $file_name['1']);
68
+			}else{
69
+			  $module=$file_name;
70
+			}
71
+			if($this->CI->session->userdata('userlevel_logintype')==1 ){
72 72
 				$module_info[]='user';
73 73
 			}
74
-            if (in_array($module[0], $module_info)) {
75
-                if($this->CI->session->userdata('userlevel_logintype')== 0 && $module[0] == 'customer' && isset($file_name[1]) && $file_name[1] !='customer_transfer'){
76
-                     redirect(base_url() . 'user/user/');
77
-                }else{
78
-                   return true;
79
-                }
80
-            } else {
81
-                $this->CI->session->set_userdata('astpp_errormsg', 'You do not have permission to access this module..!');
82
-                if ($this->CI->session->userdata('userlevel_logintype') == '-1' || $this->CI->session->userdata('logintype') == '1') {
83
-                    redirect(base_url() . 'dashboard/');
84
-                } else {
85
-                    redirect(base_url() . 'user/user/');
86
-                }
87
-            }
88
-        } else {
89
-            redirect(base_url());
90
-        }
91
-    }
92
-
93
-    function build_form($fields_array, $values) {
94
-        $form_contents = '';
95
-        $form_contents.= '<div class="pop_md col-md-12 margin-t-10 padding-x-8">';
96
-        if(isset($fields_array['breadcrumb'])){
97
-            $form_contents.=form_breadcrumb($fields_array['breadcrumb']);
98
-            unset($fields_array['breadcrumb']);
99
-        }
100
-        $form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
101
-        unset($fields_array['forms']);
102
-        $button_array = array();
103
-        if (isset($fields_array['button_save']) || isset($fields_array['button_cancel']) || isset($fields_array['additional_button'])) {
104
-            $save = $fields_array['button_save'];
105
-            unset($fields_array['button_save']);
106
-            if (isset($fields_array['button_cancel'])) {
107
-                $cancel = $fields_array['button_cancel'];
108
-                unset($fields_array['button_cancel']);
109
-            }
110
-            if (isset($fields_array['additional_button'])) {
111
-                $additiopnal_button = $fields_array['additional_button'];
112
-                unset($fields_array['additional_button']);
113
-            }
114
-        }
115
-        if (isset($additiopnal_button)) {
116
-            $form_contents.= form_button(gettext($additiopnal_button));
117
-        }
118
-        $i = 0;
119
-        foreach ($fields_array as $fieldset_key => $form_fileds) {
120
-            if (count($fields_array) > 1) {
121
-                if ($i == 1 || $i == 3) {
122
-                    $form_contents.= '<div class="col-md-6 no-padding pull-right">';
123
-                    $form_contents.= '<div class="col-md-12 padding-x-4">';
124
-                } else {
125
-                    $form_contents.= '<div class="col-md-6 no-padding">';
126
-                    $form_contents.= '<div class="col-md-12 padding-x-4">';
127
-                }
128
-            } else {
129
-               $form_contents.= '<div class="col-md-12 no-padding">';
130
-                $form_contents.= '<div class="col-md-12 no-padding">';
131
-            }
132
-            $form_contents.= '<ul class="no-padding">';
133
-                $form_contents.= '<div class="col-md-12 no-padding">';
134
-            if ($i == 1 || $i == 3) {
135
-                $form_contents.= form_fieldset(gettext($fieldset_key));
136
-            } else {
137
-                $form_contents.= form_fieldset(gettext($fieldset_key));
138
-            }
139
-            foreach ($form_fileds as $fieldkey => $fieldvalue) {
140
-                $form_contents.= '<li class="col-md-12">';
141
-                if ($fieldvalue[1] == 'HIDDEN') {
142
-                    if (isset($this->CI->input->post))
143
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
144
-                    else
145
-                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
146
-                    $form_contents.= form_hidden($fieldvalue[2]['name'], $fieldvalue[2]['value']);
147
-                }else {
148
-		      $validation_arr=array();
149
-		      if($fieldvalue[1]=='INPUT'){
150
-		        if(!empty($fieldvalue[3])){
151
-		          $validation_arr=explode("|",$fieldvalue[3]);
152
-		        }
153
-		      }
154
-		      elseif($fieldvalue[2]=='SELECT'){
155
-
156
-		        if(is_array($fieldvalue[4])){
157
-		          $validation_arr=explode("|",$fieldvalue[4]['rules']);
158
-		        }else{
159
-		        $validation_arr=explode("|",$fieldvalue[4]);
160
-		        }
161
-		      }
162
-		      if(!empty($validation_arr)){
163
-		      $fieldvalue[0] = in_array('required',$validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
164
-		      $fieldvalue[0] = in_array('dropdown',$validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
165
-		      }
74
+			if (in_array($module[0], $module_info)) {
75
+				if($this->CI->session->userdata('userlevel_logintype')== 0 && $module[0] == 'customer' && isset($file_name[1]) && $file_name[1] !='customer_transfer'){
76
+					 redirect(base_url() . 'user/user/');
77
+				}else{
78
+				   return true;
79
+				}
80
+			} else {
81
+				$this->CI->session->set_userdata('astpp_errormsg', 'You do not have permission to access this module..!');
82
+				if ($this->CI->session->userdata('userlevel_logintype') == '-1' || $this->CI->session->userdata('logintype') == '1') {
83
+					redirect(base_url() . 'dashboard/');
84
+				} else {
85
+					redirect(base_url() . 'user/user/');
86
+				}
87
+			}
88
+		} else {
89
+			redirect(base_url());
90
+		}
91
+	}
92
+
93
+	function build_form($fields_array, $values) {
94
+		$form_contents = '';
95
+		$form_contents.= '<div class="pop_md col-md-12 margin-t-10 padding-x-8">';
96
+		if(isset($fields_array['breadcrumb'])){
97
+			$form_contents.=form_breadcrumb($fields_array['breadcrumb']);
98
+			unset($fields_array['breadcrumb']);
99
+		}
100
+		$form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
101
+		unset($fields_array['forms']);
102
+		$button_array = array();
103
+		if (isset($fields_array['button_save']) || isset($fields_array['button_cancel']) || isset($fields_array['additional_button'])) {
104
+			$save = $fields_array['button_save'];
105
+			unset($fields_array['button_save']);
106
+			if (isset($fields_array['button_cancel'])) {
107
+				$cancel = $fields_array['button_cancel'];
108
+				unset($fields_array['button_cancel']);
109
+			}
110
+			if (isset($fields_array['additional_button'])) {
111
+				$additiopnal_button = $fields_array['additional_button'];
112
+				unset($fields_array['additional_button']);
113
+			}
114
+		}
115
+		if (isset($additiopnal_button)) {
116
+			$form_contents.= form_button(gettext($additiopnal_button));
117
+		}
118
+		$i = 0;
119
+		foreach ($fields_array as $fieldset_key => $form_fileds) {
120
+			if (count($fields_array) > 1) {
121
+				if ($i == 1 || $i == 3) {
122
+					$form_contents.= '<div class="col-md-6 no-padding pull-right">';
123
+					$form_contents.= '<div class="col-md-12 padding-x-4">';
124
+				} else {
125
+					$form_contents.= '<div class="col-md-6 no-padding">';
126
+					$form_contents.= '<div class="col-md-12 padding-x-4">';
127
+				}
128
+			} else {
129
+			   $form_contents.= '<div class="col-md-12 no-padding">';
130
+				$form_contents.= '<div class="col-md-12 no-padding">';
131
+			}
132
+			$form_contents.= '<ul class="no-padding">';
133
+				$form_contents.= '<div class="col-md-12 no-padding">';
134
+			if ($i == 1 || $i == 3) {
135
+				$form_contents.= form_fieldset(gettext($fieldset_key));
136
+			} else {
137
+				$form_contents.= form_fieldset(gettext($fieldset_key));
138
+			}
139
+			foreach ($form_fileds as $fieldkey => $fieldvalue) {
140
+				$form_contents.= '<li class="col-md-12">';
141
+				if ($fieldvalue[1] == 'HIDDEN') {
142
+					if (isset($this->CI->input->post))
143
+						$fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
144
+					else
145
+						$fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
146
+					$form_contents.= form_hidden($fieldvalue[2]['name'], $fieldvalue[2]['value']);
147
+				}else {
148
+			  $validation_arr=array();
149
+			  if($fieldvalue[1]=='INPUT'){
150
+				if(!empty($fieldvalue[3])){
151
+				  $validation_arr=explode("|",$fieldvalue[3]);
152
+				}
153
+			  }
154
+			  elseif($fieldvalue[2]=='SELECT'){
155
+
156
+				if(is_array($fieldvalue[4])){
157
+				  $validation_arr=explode("|",$fieldvalue[4]['rules']);
158
+				}else{
159
+				$validation_arr=explode("|",$fieldvalue[4]);
160
+				}
161
+			  }
162
+			  if(!empty($validation_arr)){
163
+			  $fieldvalue[0] = in_array('required',$validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
164
+			  $fieldvalue[0] = in_array('dropdown',$validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
165
+			  }
166 166
  
167
-                    if (is_array($fieldvalue[1]) || (is_array($fieldvalue[2]) && isset($fieldvalue[2]['hidden']))) {
168
-                        $form_contents.= form_label(gettext($fieldvalue[0]), $fieldvalue[0], array('class' => 'col-md-3 no-padding add_settings'));
169
-                    } else {
170
-                        $form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "col-md-3 no-padding"));
171
-                    }
172
-                }
173
-                if ($fieldvalue[2] == 'SELECT' && !isset($fieldvalue[13])) {
174
-
175
-                /*
167
+					if (is_array($fieldvalue[1]) || (is_array($fieldvalue[2]) && isset($fieldvalue[2]['hidden']))) {
168
+						$form_contents.= form_label(gettext($fieldvalue[0]), $fieldvalue[0], array('class' => 'col-md-3 no-padding add_settings'));
169
+					} else {
170
+						$form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "col-md-3 no-padding"));
171
+					}
172
+				}
173
+				if ($fieldvalue[2] == 'SELECT' && !isset($fieldvalue[13])) {
174
+
175
+				/*
176 176
                  To make Drop down enabled disabled
177 177
                 */
178
-                 $extra =isset($fieldvalue[1]['extra']) ? $fieldvalue[1]['extra'] :'';
179
-                 /***************************/
180
-                    if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
181
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
182
-
183
-                        if (isset($this->CI->input->post)){
184
-                            $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
185
-                        }else{
186
-                            if (is_array($fieldvalue[1])) {
187
-                                $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
188
-                            } else {
189
-                                $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
190
-                            }
191
-                        }
192
-                        $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
193
-
194
-                        if ($fieldset_key ==  gettext('System Configuration Information') || ($fieldset_key == 'Billing Information'  && $fieldvalue[0] == 'Force Trunk') || ($fieldset_key == 'Card Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key == 'Billing Information' && $fieldvalue[0] == 'Account') || $fieldset_key == 'Freeswitch Devices' && $fieldvalue[0] == 'Rate Group' || ($fieldset_key== 'Origination Rate Add/Edit' && $fieldvalue[0] == 'Trunks' )||$fieldset_key== 'Billing Information' && $fieldvalue[0] == 'Rate Group'  || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Failover GW Name #1') || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Failover GW Name #2') || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key== 'Sip Devices' && $fieldvalue[0] == 'Sip Profile') || ($fieldset_key== 'Sip Devices' && $fieldvalue[0] == 'Account')) {
195
-                            $form_contents.=form_dropdown_all($fieldvalue[1], $drp_array, $fieldvalue['value'],$extra);
196
-                        } else {
197
-                            $form_contents.=form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'], $extra);
198
-                        }
199
-			            if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
200
-                        	if(is_array($fieldvalue[4])){
178
+				 $extra =isset($fieldvalue[1]['extra']) ? $fieldvalue[1]['extra'] :'';
179
+				 /***************************/
180
+					if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
181
+						$str = $fieldvalue[7] . "," . $fieldvalue[8];
182
+
183
+						if (isset($this->CI->input->post)){
184
+							$fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
185
+						}else{
186
+							if (is_array($fieldvalue[1])) {
187
+								$fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
188
+							} else {
189
+								$fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
190
+							}
191
+						}
192
+						$drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
193
+
194
+						if ($fieldset_key ==  gettext('System Configuration Information') || ($fieldset_key == 'Billing Information'  && $fieldvalue[0] == 'Force Trunk') || ($fieldset_key == 'Card Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key == 'Billing Information' && $fieldvalue[0] == 'Account') || $fieldset_key == 'Freeswitch Devices' && $fieldvalue[0] == 'Rate Group' || ($fieldset_key== 'Origination Rate Add/Edit' && $fieldvalue[0] == 'Trunks' )||$fieldset_key== 'Billing Information' && $fieldvalue[0] == 'Rate Group'  || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Failover GW Name #1') || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Failover GW Name #2') || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key== 'Sip Devices' && $fieldvalue[0] == 'Sip Profile') || ($fieldset_key== 'Sip Devices' && $fieldvalue[0] == 'Account')) {
195
+							$form_contents.=form_dropdown_all($fieldvalue[1], $drp_array, $fieldvalue['value'],$extra);
196
+						} else {
197
+							$form_contents.=form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'], $extra);
198
+						}
199
+						if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
200
+							if(is_array($fieldvalue[4])){
201 201
 								
202 202
 								if(isset($fieldvalue[1]['name'])){
203 203
 									$fieldvalue_pass=$fieldvalue[1]['name'];
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 									$fieldvalue_pass=$fieldvalue[1];
206 206
 								}
207 207
 								
208
-        				        $this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]['rules']);
209
-        				    }else{
208
+								$this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]['rules']);
209
+							}else{
210 210
 								
211 211
 								if(isset($fieldvalue[1]['name'])){
212 212
 									$fieldvalue_pass=$fieldvalue[1]['name'];
@@ -214,495 +214,495 @@  discard block
 block discarded – undo
214 214
 									$fieldvalue_pass=$fieldvalue[1];
215 215
 								}
216 216
 								
217
-        				       $this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]);
218
-        				    }   
219
-                        }
220
-                        $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
221
-                        $form_contents.= '<span class="popup_error error  no-padding" id="'.(gettext(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1])).'_error">
217
+							   $this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]);
218
+							}   
219
+						}
220
+						$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
221
+						$form_contents.= '<span class="popup_error error  no-padding" id="'.(gettext(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1])).'_error">
222 222
                         </span></div>';                         
223
-                    } else {
224
-                        if (isset($this->CI->input->post)) {
225
-                            $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
226
-                        } else {
227
-                            if (is_array($fieldvalue[1])) {
228
-                                $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
229
-                            } else {
230
-                                $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
231
-                            }
232
-                        }
233
-
234
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
235
-                        $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
236
-                        $form_contents.=form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'],$extra);
237
-                        if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
223
+					} else {
224
+						if (isset($this->CI->input->post)) {
225
+							$fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
226
+						} else {
227
+							if (is_array($fieldvalue[1])) {
228
+								$fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
229
+							} else {
230
+								$fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
231
+							}
232
+						}
233
+
234
+						$str = $fieldvalue[7] . "," . $fieldvalue[8];
235
+						$drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
236
+						$form_contents.=form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'],$extra);
237
+						if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
238 238
 			  $this->CI->form_validation->set_rules($fieldvalue[1], $fieldvalue[0], $fieldvalue[4]);
239
-                        }
240
-                        $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
241
-                        $form_contents.= '<span class="popup_error error  no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error">
239
+						}
240
+						$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
241
+						$form_contents.= '<span class="popup_error error  no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error">
242 242
                         </span></div>';                        
243
-                    }
244
-                } else if (isset($fieldvalue[13]) && $fieldvalue[13] != '') {
245
-
246
-                    /* For multi select code */
247
-                    $str = $fieldvalue[7] . "," . $fieldvalue[8];
248
-
249
-                    if (isset($this->CI->input->post))
250
-                        $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
251
-                    else
252
-                        $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
253
-
254
-                    $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
255
-                    if ($fieldset_key === 'System Configuration Information') {
256
-                        $form_contents.=form_dropdown_multiselect($fieldvalue[1], $drp_array, '');
257
-                    } else {
258
-                        $form_contents.=form_dropdown_multiselect($fieldvalue[1] . "[]", $drp_array, $fieldvalue['value']);
259
-                    }
260
-                    if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
243
+					}
244
+				} else if (isset($fieldvalue[13]) && $fieldvalue[13] != '') {
245
+
246
+					/* For multi select code */
247
+					$str = $fieldvalue[7] . "," . $fieldvalue[8];
248
+
249
+					if (isset($this->CI->input->post))
250
+						$fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
251
+					else
252
+						$fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
253
+
254
+					$drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
255
+					if ($fieldset_key === 'System Configuration Information') {
256
+						$form_contents.=form_dropdown_multiselect($fieldvalue[1], $drp_array, '');
257
+					} else {
258
+						$form_contents.=form_dropdown_multiselect($fieldvalue[1] . "[]", $drp_array, $fieldvalue['value']);
259
+					}
260
+					if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
261 261
 			$this->CI->form_validation->set_rules($fieldvalue[1], $fieldvalue[0], $fieldvalue[4]);
262
-                    }
263
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[1].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
264
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[1].'_error"></span></div>';                   
265
-                    /* End---------------------   For multi select code */
266
-                } else if ($fieldvalue[1] == 'INPUT') {
267
-
268
-
269
-                    if (isset($this->CI->input->post))
270
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? $fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
271
-                    else{
272
-                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
273
-                    }    
274
-                    $form_contents.= form_input($fieldvalue[2], 'readonly');
275
-                    if(isset($fieldvalue[6]) && !empty($fieldvalue[6])){
276
-                        $form_contents.=$fieldvalue[6];
277
-                    }    
278
-                    $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
279
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
280
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
262
+					}
263
+					$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[1].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
264
+					$form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[1].'_error"></span></div>';                   
265
+					/* End---------------------   For multi select code */
266
+				} else if ($fieldvalue[1] == 'INPUT') {
267
+
268
+
269
+					if (isset($this->CI->input->post))
270
+						$fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? $fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
271
+					else{
272
+						$fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
273
+					}    
274
+					$form_contents.= form_input($fieldvalue[2], 'readonly');
275
+					if(isset($fieldvalue[6]) && !empty($fieldvalue[6])){
276
+						$form_contents.=$fieldvalue[6];
277
+					}    
278
+					$this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
279
+					$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
280
+					$form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
281 281
                     </span></div>';
282
-                }
283
-                /* 
282
+				}
283
+				/* 
284 284
                  * Image upload from invoice configuration code.
285 285
                  */
286
-                else if ($fieldvalue[1] == 'IMAGE') {
287
-                    if (isset($this->CI->input->post))
288
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
286
+				else if ($fieldvalue[1] == 'IMAGE') {
287
+					if (isset($this->CI->input->post))
288
+						$fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
289 289
                        
290
-                    else
291
-                        $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
292
-                        $fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
293
-                    $form_contents.= form_image($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
294
-                    	 $form_contents.=@$fieldvalue[6];
295
-                    $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
296
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
297
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
290
+					else
291
+						$fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
292
+						$fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
293
+					$form_contents.= form_image($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
294
+						 $form_contents.=@$fieldvalue[6];
295
+					$this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
296
+					$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
297
+					$form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
298 298
                     </span></div>';
299
-                }
300
-                else if ($fieldvalue[1] == 'DEL_BUTTON') {
301
-                    if (isset($this->CI->input->post))
302
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
299
+				}
300
+				else if ($fieldvalue[1] == 'DEL_BUTTON') {
301
+					if (isset($this->CI->input->post))
302
+						$fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
303 303
                        
304
-                    else
305
-                        $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
306
-                        $fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
307
-                    $form_contents.= form_img_delete($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
308
-                    	 $form_contents.=@$fieldvalue[6];
309
-                    $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
310
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
311
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
304
+					else
305
+						$fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
306
+						$fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
307
+					$form_contents.= form_img_delete($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
308
+						 $form_contents.=@$fieldvalue[6];
309
+					$this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
310
+					$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
311
+					$form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
312 312
                     </span></div>';
313
-                }
314
-                /**********************************************************************************/
315
-                else if ($fieldvalue[1] == 'PASSWORD') {
316
-                    if (isset($this->CI->input->post))
317
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
318
-                    else
319
-                        $fieldvalue[2]['value'] = ($values) ?@$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
320
-                    $form_contents.= form_password($fieldvalue[2]);
321
-                    $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
322
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
323
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
313
+				}
314
+				/**********************************************************************************/
315
+				else if ($fieldvalue[1] == 'PASSWORD') {
316
+					if (isset($this->CI->input->post))
317
+						$fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
318
+					else
319
+						$fieldvalue[2]['value'] = ($values) ?@$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
320
+					$form_contents.= form_password($fieldvalue[2]);
321
+					$this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
322
+					$form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
323
+					$form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
324 324
                     </span></div>';
325
-                } else if ($fieldvalue[2] == 'CHECKBOX') {
326
-                    $OptionArray = array();
325
+				} else if ($fieldvalue[2] == 'CHECKBOX') {
326
+					$OptionArray = array();
327 327
 
328 328
 					if(isset($fieldvalue[7]) && $fieldvalue[7] != '')
329 329
 					$OptionArray = call_user_func_array(array($this->CI->common, $fieldvalue[7]), array($fieldvalue[6]));
330
-                    if (isset($this->CI->input->post)){
331
-                        $fieldvalue[3]['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[3]['value'] : $this->CI->input->post($fieldvalue[1]);
332
-                    }    
333
-                    else
334
-                    {
335
-                        $fieldvalue[3]['value'] = ($values) ? (isset($values[$fieldvalue[1]]) && $values[$fieldvalue[1]] ? 1: 0) : @$fieldvalue[3]['value'];
330
+					if (isset($this->CI->input->post)){
331
+						$fieldvalue[3]['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[3]['value'] : $this->CI->input->post($fieldvalue[1]);
332
+					}    
333
+					else
334
+					{
335
+						$fieldvalue[3]['value'] = ($values) ? (isset($values[$fieldvalue[1]]) && $values[$fieldvalue[1]] ? 1: 0) : @$fieldvalue[3]['value'];
336 336
 					}
337
-                    if ($fieldvalue[3]['value'] == "1") {
338
-                        $checked = true;
339
-                    } else {
340
-                        $checked = false;
341
-                    };
342
-                    if(isset($fieldvalue[3]['table_name']) && $fieldvalue[3]['table_name'] != ""){
337
+					if ($fieldvalue[3]['value'] == "1") {
338
+						$checked = true;
339
+					} else {
340
+						$checked = false;
341
+					};
342
+					if(isset($fieldvalue[3]['table_name']) && $fieldvalue[3]['table_name'] != ""){
343 343
 							
344 344
 						 $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'],$checked , $OptionArray);
345 345
 					}else{
346 346
 						 $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'],$checked ,$OptionArray);
347 347
 					}
348
-                } else if ($fieldvalue[1] == 'TEXTAREA') {
349
-
350
-                    if (isset($this->CI->input->post))
351
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
352
-                    else
353
-                        $fieldvalue[2]['value'] = ($values) ? $values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
354
-                    $form_contents.= form_textarea($fieldvalue[2]);
355
-                }
356
-                else if ($fieldvalue[2] == 'RADIO') {
357
-
358
-                    $form_contents.= form_radio($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
359
-                }
360
-                $form_contents.= '</li>';
361
-            }
348
+				} else if ($fieldvalue[1] == 'TEXTAREA') {
349
+
350
+					if (isset($this->CI->input->post))
351
+						$fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
352
+					else
353
+						$fieldvalue[2]['value'] = ($values) ? $values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
354
+					$form_contents.= form_textarea($fieldvalue[2]);
355
+				}
356
+				else if ($fieldvalue[2] == 'RADIO') {
357
+
358
+					$form_contents.= form_radio($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
359
+				}
360
+				$form_contents.= '</li>';
361
+			}
362 362
 
363
-            $form_contents.= '</ul>';
364
-            $form_contents.= '</div>';
365
-            $form_contents.= '</div>';
366
-            $i++;
367
-        }
363
+			$form_contents.= '</ul>';
364
+			$form_contents.= '</div>';
365
+			$form_contents.= '</div>';
366
+			$i++;
367
+		}
368 368
 
369
-        $form_contents.= '<center><div class="col-md-12 margin-t-20 margin-b-20">';
369
+		$form_contents.= '<center><div class="col-md-12 margin-t-20 margin-b-20">';
370 370
 
371
-        $form_contents.= form_button($save);
371
+		$form_contents.= form_button($save);
372 372
 
373 373
 	if (isset($cancel)) {
374
-            $form_contents.= form_button($cancel);
375
-        }
376
-        $form_contents.= '</center></div>';
377
-        $form_contents.= form_fieldset_close();
378
-        $form_contents.= form_close();
379
-        $form_contents.= '</div>';
380
-
381
-
382
-        return $form_contents;
383
-    }
384
-
385
-    function build_serach_form($fields_array) {
386
-        $form_contents = '';
387
-        $form_contents.= '<div>';
388
-        $form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
389
-        unset($fields_array['forms']);
390
-        $button_array = array();
374
+			$form_contents.= form_button($cancel);
375
+		}
376
+		$form_contents.= '</center></div>';
377
+		$form_contents.= form_fieldset_close();
378
+		$form_contents.= form_close();
379
+		$form_contents.= '</div>';
380
+
381
+
382
+		return $form_contents;
383
+	}
384
+
385
+	function build_serach_form($fields_array) {
386
+		$form_contents = '';
387
+		$form_contents.= '<div>';
388
+		$form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
389
+		unset($fields_array['forms']);
390
+		$button_array = array();
391 391
 	/*******
392 392
 	Batch Delete
393 393
 	*******/
394
-        if (isset($fields_array['button_search']) || isset($fields_array['button_reset']) || isset($fields_array['button_search_delete']) || isset($fields_array['display_in'])) {
395
-            $save = $fields_array['button_search'];
396
-            unset($fields_array['button_search']);
397
-            if ($fields_array['button_reset']) {
398
-                $cancel = $fields_array['button_reset'];
399
-                unset($fields_array['button_reset']);
400
-            }
401
-	    $button_search_delete='';
402
-            if (isset($fields_array['button_search_delete'])) {
403
-                $button_search_delete = $fields_array['button_search_delete'];
404
-                unset($fields_array['button_search_delete']);
405
-            }
406
-            if(isset($fields_array['display_in'])){
407
-	      $display_in=$fields_array['display_in'];
408
-	      unset($fields_array['display_in']);
409
-	    }
410
-        }
394
+		if (isset($fields_array['button_search']) || isset($fields_array['button_reset']) || isset($fields_array['button_search_delete']) || isset($fields_array['display_in'])) {
395
+			$save = $fields_array['button_search'];
396
+			unset($fields_array['button_search']);
397
+			if ($fields_array['button_reset']) {
398
+				$cancel = $fields_array['button_reset'];
399
+				unset($fields_array['button_reset']);
400
+			}
401
+		$button_search_delete='';
402
+			if (isset($fields_array['button_search_delete'])) {
403
+				$button_search_delete = $fields_array['button_search_delete'];
404
+				unset($fields_array['button_search_delete']);
405
+			}
406
+			if(isset($fields_array['display_in'])){
407
+		  $display_in=$fields_array['display_in'];
408
+		  unset($fields_array['display_in']);
409
+		}
410
+		}
411 411
 	/**************************/
412
-        $i = 1;
413
-        foreach ($fields_array as $fieldset_key => $form_fileds) {
414
-
415
-            $form_contents.= '<ul class="padding-15">';
416
-            $form_contents.= form_fieldset(gettext($fieldset_key),array('style' => 'font-weight:bold;'),"search");
417
-
418
-            foreach ($form_fileds as $fieldkey => $fieldvalue) {
419
-                if ($i == 0) {
420
-                    $form_contents.= '<li class="col-md-12">';
421
-                }
422
-                $form_contents.= '<div class="col-md-3 no-padding">';
423
-                if ($fieldvalue[1] == 'HIDDEN') {
424
-                    $form_contents.= form_hidden($fieldvalue[2], $fieldvalue[3]);
425
-                } else {
426
-                    $form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
427
-                }
428
-                if ($fieldvalue[1] == 'INPUT') {
429
-                    $form_contents.= form_input($fieldvalue[2]);
430
-                }
431
-
432
-
433
-                if ($fieldvalue[2] == 'SELECT' || $fieldvalue[5] == '1') {
412
+		$i = 1;
413
+		foreach ($fields_array as $fieldset_key => $form_fileds) {
414
+
415
+			$form_contents.= '<ul class="padding-15">';
416
+			$form_contents.= form_fieldset(gettext($fieldset_key),array('style' => 'font-weight:bold;'),"search");
417
+
418
+			foreach ($form_fileds as $fieldkey => $fieldvalue) {
419
+				if ($i == 0) {
420
+					$form_contents.= '<li class="col-md-12">';
421
+				}
422
+				$form_contents.= '<div class="col-md-3 no-padding">';
423
+				if ($fieldvalue[1] == 'HIDDEN') {
424
+					$form_contents.= form_hidden($fieldvalue[2], $fieldvalue[3]);
425
+				} else {
426
+					$form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
427
+				}
428
+				if ($fieldvalue[1] == 'INPUT') {
429
+					$form_contents.= form_input($fieldvalue[2]);
430
+				}
431
+
432
+
433
+				if ($fieldvalue[2] == 'SELECT' || $fieldvalue[5] == '1') {
434 434
 			  
435
-                    if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
436
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
435
+					if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
436
+						$str = $fieldvalue[7] . "," . $fieldvalue[8];
437 437
 
438
-                        $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
439
-                        $form_contents.=form_dropdown_all(gettext($fieldvalue[1]), $drp_array, '');
440
-                    } else {
438
+						$drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
439
+						$form_contents.=form_dropdown_all(gettext($fieldvalue[1]), $drp_array, '');
440
+					} else {
441 441
 
442
-                        if ($fieldvalue[1] == 'INPUT') {
443
-                            $fieldvalue[1] = $fieldvalue[6];
444
-                        }
442
+						if ($fieldvalue[1] == 'INPUT') {
443
+							$fieldvalue[1] = $fieldvalue[6];
444
+						}
445 445
 			
446
-                        $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
447
-                        $form_contents.=form_dropdown_all_search(gettext($fieldvalue[1]), $drp_array, '');
448
-                    }
449
-                } else if ($fieldvalue[1] == 'PASSWORD') {
450
-                    $form_contents.= form_password($fieldvalue[2]);
451
-                } else if ($fieldvalue[2] == 'CHECKBOX') {
452
-                    $form_contents.= form_checkbox(gettext($fieldvalue[1]), $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
453
-                }
454
-                $form_contents.= '</div>';
455
-                if ($i % 5 == 0) {
456
-                    $form_contents.= '</li>';
457
-                    $i = 0;
458
-                }
459
-                $i++;
460
-            }
461
-        }
462
-        $form_contents.= '<div class="col-md-12 margin-t-20 margin-b-20">';
463
-        $form_contents.= form_button($cancel);
464
-        $form_contents.= form_button($save);
465
-        if(!empty($display_in)){
466
-            $form_contents.="<div class='col-md-5 pull-right'>";
467
-            $form_contents.="<div class='col-md-3'></div>";
468
-            $extra_parameters['class']=$display_in['label_class'];
469
-            $extra_parameters['style']=$display_in['label_style'];
470
-            $form_contents.=form_label($display_in['content'], "",$extra_parameters);
471
-            $drp_array = call_user_func_array(array($this->CI->common,$display_in['function']),array());
472
-            $extra_parameters['class']=$display_in['dropdown_class'];
473
-            $extra_parameters['style']=$display_in['dropdown_style'];
474
-            $form_contents.=form_dropdown_all_search($display_in, $drp_array, '',$extra_parameters);
475
-            $form_contents.="</div>";
476
-        }
477
-        if(isset($button_search_delete) && $button_search_delete != ''){
446
+						$drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
447
+						$form_contents.=form_dropdown_all_search(gettext($fieldvalue[1]), $drp_array, '');
448
+					}
449
+				} else if ($fieldvalue[1] == 'PASSWORD') {
450
+					$form_contents.= form_password($fieldvalue[2]);
451
+				} else if ($fieldvalue[2] == 'CHECKBOX') {
452
+					$form_contents.= form_checkbox(gettext($fieldvalue[1]), $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
453
+				}
454
+				$form_contents.= '</div>';
455
+				if ($i % 5 == 0) {
456
+					$form_contents.= '</li>';
457
+					$i = 0;
458
+				}
459
+				$i++;
460
+			}
461
+		}
462
+		$form_contents.= '<div class="col-md-12 margin-t-20 margin-b-20">';
463
+		$form_contents.= form_button($cancel);
464
+		$form_contents.= form_button($save);
465
+		if(!empty($display_in)){
466
+			$form_contents.="<div class='col-md-5 pull-right'>";
467
+			$form_contents.="<div class='col-md-3'></div>";
468
+			$extra_parameters['class']=$display_in['label_class'];
469
+			$extra_parameters['style']=$display_in['label_style'];
470
+			$form_contents.=form_label($display_in['content'], "",$extra_parameters);
471
+			$drp_array = call_user_func_array(array($this->CI->common,$display_in['function']),array());
472
+			$extra_parameters['class']=$display_in['dropdown_class'];
473
+			$extra_parameters['style']=$display_in['dropdown_style'];
474
+			$form_contents.=form_dropdown_all_search($display_in, $drp_array, '',$extra_parameters);
475
+			$form_contents.="</div>";
476
+		}
477
+		if(isset($button_search_delete) && $button_search_delete != ''){
478 478
 	  $form_contents.= form_button($button_search_delete);
479
-        }
480
-        $form_contents.='<div class="col-md-12 no-padding margin-t-15" style="">
479
+		}
480
+		$form_contents.='<div class="col-md-12 no-padding margin-t-15" style="">
481 481
 		<div class="pull-right btn-close" id="global_clearsearch_filter">Close</div> 
482 482
 	</div>';
483
-        $form_contents.= '</ul>';        
484
-        $form_contents.= '</div>';
485
-        $form_contents.= form_fieldset_close();
486
-        $form_contents.= form_close();
487
-        $form_contents.= '</div>';
488
-
489
-        return $form_contents;
490
-    }
491
-    function build_batchupdate_form($fields_array) {
492
-        $form_contents = '';
493
-        $form_contents.= '<div >';
494
-        $form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
495
-        unset($fields_array['forms']);
496
-        $button_array = array();
497
-        if (isset($fields_array['button_search']) || isset($fields_array['button_reset'])) {
498
-            $save = $fields_array['button_search'];
499
-            unset($fields_array['button_search']);
500
-            if ($fields_array['button_reset']) {
501
-                $cancel = $fields_array['button_reset'];
502
-                unset($fields_array['button_reset']);
503
-            }
504
-        }
505
-        $i = 1;
506
-        foreach ($fields_array as $fieldset_key => $form_fileds) {
507
-
508
-            $form_contents.= '<ul>';
509
-            $form_contents.= form_fieldset(gettext($fieldset_key), array('style' => 'margin-left:-22px;font-weight:bold;'));
510
-            foreach ($form_fileds as $fieldkey => $fieldvalue) {
511
-                if ($i == 0) {
512
-                    $form_contents.= '<li>';
513
-                }
514
-                $form_contents.= '<div class="col-md-4 no-padding">';
515
-                if ($fieldvalue[1] == 'HIDDEN') {
516
-                    $form_contents.= form_hidden($fieldvalue[2], $fieldvalue[3]);
517
-                } else {
518
-                    $form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
519
-                }
520
-                if ($fieldvalue[2] == 'SELECT' || $fieldvalue[5] == '1') {
521
-                    if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
522
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
523
-                        if(is_array($fieldvalue[13])){
524
-                            $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[14]), array($fieldvalue[13]));
525
-                            $form_contents.=form_dropdown($fieldvalue[13], $drp_array, '');
526
-                        }
527
-                        /**
483
+		$form_contents.= '</ul>';        
484
+		$form_contents.= '</div>';
485
+		$form_contents.= form_fieldset_close();
486
+		$form_contents.= form_close();
487
+		$form_contents.= '</div>';
488
+
489
+		return $form_contents;
490
+	}
491
+	function build_batchupdate_form($fields_array) {
492
+		$form_contents = '';
493
+		$form_contents.= '<div >';
494
+		$form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
495
+		unset($fields_array['forms']);
496
+		$button_array = array();
497
+		if (isset($fields_array['button_search']) || isset($fields_array['button_reset'])) {
498
+			$save = $fields_array['button_search'];
499
+			unset($fields_array['button_search']);
500
+			if ($fields_array['button_reset']) {
501
+				$cancel = $fields_array['button_reset'];
502
+				unset($fields_array['button_reset']);
503
+			}
504
+		}
505
+		$i = 1;
506
+		foreach ($fields_array as $fieldset_key => $form_fileds) {
507
+
508
+			$form_contents.= '<ul>';
509
+			$form_contents.= form_fieldset(gettext($fieldset_key), array('style' => 'margin-left:-22px;font-weight:bold;'));
510
+			foreach ($form_fileds as $fieldkey => $fieldvalue) {
511
+				if ($i == 0) {
512
+					$form_contents.= '<li>';
513
+				}
514
+				$form_contents.= '<div class="col-md-4 no-padding">';
515
+				if ($fieldvalue[1] == 'HIDDEN') {
516
+					$form_contents.= form_hidden($fieldvalue[2], $fieldvalue[3]);
517
+				} else {
518
+					$form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
519
+				}
520
+				if ($fieldvalue[2] == 'SELECT' || $fieldvalue[5] == '1') {
521
+					if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
522
+						$str = $fieldvalue[7] . "," . $fieldvalue[8];
523
+						if(is_array($fieldvalue[13])){
524
+							$drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[14]), array($fieldvalue[13]));
525
+							$form_contents.=form_dropdown($fieldvalue[13], $drp_array, '');
526
+						}
527
+						/**
528 528
   		        ASTPP  3.0 
529 529
    		        Reseller Batch Update
530
-                        **/ 
531
-                        if($fieldvalue[10] == 'set_status'){
530
+						 **/ 
531
+						if($fieldvalue[10] == 'set_status'){
532 532
 			$drp_array =array('0'=>'Active','1'=>'Inactive');
533 533
 			}
534 534
 			/************************************************************/
535 535
 			else{
536
-                        $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));}
537
-                        $form_contents.=form_dropdown_all($fieldvalue[1], $drp_array, '');
538
-                    } else {
539
-                        if ($fieldvalue[1] == 'INPUT') {
540
-                            $drp_name = $fieldvalue[6];
541
-                        }
542
-                        $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
543
-                        $form_contents.=form_dropdown($drp_name, $drp_array, '');
544
-                    }
545
-                }
546
-                if ($fieldvalue[1] == 'INPUT') {
547
-                    $form_contents.= form_input($fieldvalue[2]);
548
-                } else if ($fieldvalue[2] == 'CHECKBOX') {
549
-                    $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
550
-                }
551
-                $form_contents.= '</div>';
552
-                if ($i % 5 == 0) {
553
-                    $form_contents.= '</li>';
554
-                    $i = 0;
555
-                }
556
-                $i++;
557
-            }
558
-        }
559
-
560
-        $form_contents.= '</ul>';
561
-        $form_contents.= '<div class="col-md-12 margin-t-20 margin-b-20">';
562
-
563
-        $form_contents.= form_button($cancel);
564
-        $form_contents.= form_button($save);
565
-        $form_contents.='<div class="col-md-12 no-padding margin-t-15" style="margin-bottom:10px; !important">
536
+						$drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));}
537
+						$form_contents.=form_dropdown_all($fieldvalue[1], $drp_array, '');
538
+					} else {
539
+						if ($fieldvalue[1] == 'INPUT') {
540
+							$drp_name = $fieldvalue[6];
541
+						}
542
+						$drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
543
+						$form_contents.=form_dropdown($drp_name, $drp_array, '');
544
+					}
545
+				}
546
+				if ($fieldvalue[1] == 'INPUT') {
547
+					$form_contents.= form_input($fieldvalue[2]);
548
+				} else if ($fieldvalue[2] == 'CHECKBOX') {
549
+					$form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
550
+				}
551
+				$form_contents.= '</div>';
552
+				if ($i % 5 == 0) {
553
+					$form_contents.= '</li>';
554
+					$i = 0;
555
+				}
556
+				$i++;
557
+			}
558
+		}
559
+
560
+		$form_contents.= '</ul>';
561
+		$form_contents.= '<div class="col-md-12 margin-t-20 margin-b-20">';
562
+
563
+		$form_contents.= form_button($cancel);
564
+		$form_contents.= form_button($save);
565
+		$form_contents.='<div class="col-md-12 no-padding margin-t-15" style="margin-bottom:10px; !important">
566 566
 						<div class="pull-right btn-close" id="global_clearbatchupdate_filter">Close</div></div>';
567
-        $form_contents.= form_fieldset_close();
568
-        $form_contents.= form_close();
569
-        $form_contents.= '</div>';
570
-        $form_contents.= '</div>';
571
-
572
-        return $form_contents;
573
-    }
574
-
575
-    function load_grid_config($count_all, $rp, $page) {
576
-        $json_data = array();
577
-        $config['total_rows'] = $count_all;
578
-        $config['per_page'] = $rp;
579
-
580
-        $page_no = $page;
581
-        $json_data["json_paging"]['page'] = $page_no;
582
-
583
-        $json_data["json_paging"]['total'] = $config['total_rows'];
584
-        $perpage = $config['per_page'];
585
-        $start = ($page_no - 1) * $perpage;
586
-        if ($start < 0)
587
-            $start = 0;
588
-        $json_data["paging"]['start'] = $start;
589
-        $json_data["paging"]['page_no'] = $perpage;
590
-        return $json_data;
591
-    }
592
-
593
-    function build_grid($query, $grid_fields) {
594
-        $jsn_tmp = array();
595
-        $json_data = array();
596
-        if ($query->num_rows > 0) {
597
-            foreach ($query->result_array() as $row) {
598
-            /*
567
+		$form_contents.= form_fieldset_close();
568
+		$form_contents.= form_close();
569
+		$form_contents.= '</div>';
570
+		$form_contents.= '</div>';
571
+
572
+		return $form_contents;
573
+	}
574
+
575
+	function load_grid_config($count_all, $rp, $page) {
576
+		$json_data = array();
577
+		$config['total_rows'] = $count_all;
578
+		$config['per_page'] = $rp;
579
+
580
+		$page_no = $page;
581
+		$json_data["json_paging"]['page'] = $page_no;
582
+
583
+		$json_data["json_paging"]['total'] = $config['total_rows'];
584
+		$perpage = $config['per_page'];
585
+		$start = ($page_no - 1) * $perpage;
586
+		if ($start < 0)
587
+			$start = 0;
588
+		$json_data["paging"]['start'] = $start;
589
+		$json_data["paging"]['page_no'] = $perpage;
590
+		return $json_data;
591
+	}
592
+
593
+	function build_grid($query, $grid_fields) {
594
+		$jsn_tmp = array();
595
+		$json_data = array();
596
+		if ($query->num_rows > 0) {
597
+			foreach ($query->result_array() as $row) {
598
+			/*
599 599
                 ASTPP  3.0 
600 600
                 For Edit on Account number or name
601 601
             */
602 602
 		$row_id = isset($row['id']) ? $row["id"]: '';
603 603
 /*****************************/
604
-                foreach ($grid_fields as $field_key => $field_arr) {
604
+				foreach ($grid_fields as $field_key => $field_arr) {
605 605
 /**
606 606
 ASTPP  3.0 
607 607
 For Edit on Account number or name
608 608
 **/
609
-		     $Actionkey = array_search(gettext('Action'), $this->CI->common->array_column($grid_fields,0));
609
+			 $Actionkey = array_search(gettext('Action'), $this->CI->common->array_column($grid_fields,0));
610 610
 /*********************************/
611
-                    if ($field_arr[2] != "") {
612
-                        if ($field_arr[3] != "") {
613
-                           if($field_arr[2]=="status"){
614
-                            $row['id'] = $row_id;
615
-                            $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
611
+					if ($field_arr[2] != "") {
612
+						if ($field_arr[3] != "") {
613
+						   if($field_arr[2]=="status"){
614
+							$row['id'] = $row_id;
615
+							$jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
616 616
 			   }else{
617
-                            $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
617
+							$jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
618 618
 			   }
619 619
 
620 620
 /**
621 621
 ASTPP  3.0 
622 622
 For Edit on Account number or name
623 623
 **/
624
-			    $row[$field_arr[2]] = $jsn_tmp[$field_key];
625
-            } if(array_search("EDITABLE", $field_arr)){
626
-			    $ActionArr = $grid_fields[$Actionkey];
627
-                if($ActionArr[5]->EDIT->url =="accounts/customer_edit/" || $ActionArr[5]->EDIT->url =="accounts/provider_edit/"){
628
-                   $ActionArr[5]->EDIT->url=$row['type']==0 ?  "accounts/customer_edit/"  : "accounts/provider_edit/";
629
-                }
630
-                if($ActionArr[5]->EDIT->url =="accounts/admin_edit/" || $ActionArr[5]->EDIT->url =="accounts/subadmin_edit/"){
631
-                   $ActionArr[5]->EDIT->url=$row['type']==4 ?  "accounts/subadmin_edit/"  : "accounts/admin_edit/";
632
-                }
633
-                $acctype = "";
634
-                if(isset($row["type"]) && ($row["type"] == '0' || $row["type"] == '1' || $row["type"] == '3')){
635
-                    $acctype = (isset($row["posttoexternal"]) && $row["posttoexternal"] != '')? "<span class='label label-default pull-right'>".$this->CI->common->get_account_type("","",$row["posttoexternal"])."</span>":"";
636
-                }
637
-
638
-                $fieldstr = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
639
-                if($acctype != ''){
640
-                    $jsn_tmp[$field_key] = $fieldstr."<br/>".$acctype;
641
-                }else{
642
-                    $jsn_tmp[$field_key] = $fieldstr;
643
-                }
624
+				$row[$field_arr[2]] = $jsn_tmp[$field_key];
625
+			} if(array_search("EDITABLE", $field_arr)){
626
+				$ActionArr = $grid_fields[$Actionkey];
627
+				if($ActionArr[5]->EDIT->url =="accounts/customer_edit/" || $ActionArr[5]->EDIT->url =="accounts/provider_edit/"){
628
+				   $ActionArr[5]->EDIT->url=$row['type']==0 ?  "accounts/customer_edit/"  : "accounts/provider_edit/";
629
+				}
630
+				if($ActionArr[5]->EDIT->url =="accounts/admin_edit/" || $ActionArr[5]->EDIT->url =="accounts/subadmin_edit/"){
631
+				   $ActionArr[5]->EDIT->url=$row['type']==4 ?  "accounts/subadmin_edit/"  : "accounts/admin_edit/";
632
+				}
633
+				$acctype = "";
634
+				if(isset($row["type"]) && ($row["type"] == '0' || $row["type"] == '1' || $row["type"] == '3')){
635
+					$acctype = (isset($row["posttoexternal"]) && $row["posttoexternal"] != '')? "<span class='label label-default pull-right'>".$this->CI->common->get_account_type("","",$row["posttoexternal"])."</span>":"";
636
+				}
637
+
638
+				$fieldstr = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
639
+				if($acctype != ''){
640
+					$jsn_tmp[$field_key] = $fieldstr."<br/>".$acctype;
641
+				}else{
642
+					$jsn_tmp[$field_key] = $fieldstr;
643
+				}
644 644
 			    
645 645
 
646 646
 /*********************************/
647
-		      }else {
648
-                            $jsn_tmp[$field_key] = $row[$field_arr[2]];
649
-                  }                  				
650
-            } else {
651
-                if ($field_arr[0] == gettext("Action")) {
652
-			    if(isset($field_arr[5]) && isset($field_arr[5]->EDIT) && isset($field_arr[5]->DELETE)){
647
+			  }else {
648
+							$jsn_tmp[$field_key] = $row[$field_arr[2]];
649
+				  }                  				
650
+			} else {
651
+				if ($field_arr[0] == gettext("Action")) {
652
+				if(isset($field_arr[5]) && isset($field_arr[5]->EDIT) && isset($field_arr[5]->DELETE)){
653 653
 		             
654
-		              if($field_arr[5]->EDIT->url == 'accounts/customer_edit/' || $field_arr[5]->EDIT->url == 'accounts/provider_edit/' || $field_arr[5]->DELETE->url == 'accounts/provider_delete/' ||$field_arr[5]->DELETE->url == 'accounts/customer_delete/'){
655
-		               if( $row['type'] == '0'|| strtolower($row['type']) == 'customer'){
656
-		                $field_arr[5]->EDIT->url ='accounts/customer_edit/';
657
-		                $field_arr[5]->DELETE->url ='accounts/customer_delete/';
658
-		               }
659
-		               if($row['type'] == 3 || strtolower($row['type']) == 'provider'){
660
-		                $field_arr[5]->EDIT->url ='accounts/provider_edit/';
661
-		                $field_arr[5]->DELETE->url ='accounts/provider_delete/';
662
-		               }
663
-		              }
664
-		              if($field_arr[5]->EDIT->url == 'accounts/admin_edit/' || $field_arr[5]->EDIT->url == 'accounts/subadmin_edit/' || $field_arr[5]->DELETE->url == 'accounts/admin_delete/' ||$field_arr[5]->DELETE->url == 'accounts/subadmin_delete/'){
665
-		               if($row['type'] == 2 || strtolower($row['type']) == 'administrator'){
666
-		                $field_arr[5]->EDIT->url ='accounts/admin_edit/';
667
-		                $field_arr[5]->DELETE->url ='accounts/admin_delete/';
668
-		               }
669
-		               if($row['type'] == 4 || strtolower($row['type']) == 'sub admin'){
670
-		                $field_arr[5]->EDIT->url ='accounts/subadmin_edit/';
671
-		                $field_arr[5]->DELETE->url ='accounts/subadmin_delete/';
672
-		               }
673
-		            }
654
+					  if($field_arr[5]->EDIT->url == 'accounts/customer_edit/' || $field_arr[5]->EDIT->url == 'accounts/provider_edit/' || $field_arr[5]->DELETE->url == 'accounts/provider_delete/' ||$field_arr[5]->DELETE->url == 'accounts/customer_delete/'){
655
+					   if( $row['type'] == '0'|| strtolower($row['type']) == 'customer'){
656
+						$field_arr[5]->EDIT->url ='accounts/customer_edit/';
657
+						$field_arr[5]->DELETE->url ='accounts/customer_delete/';
658
+					   }
659
+					   if($row['type'] == 3 || strtolower($row['type']) == 'provider'){
660
+						$field_arr[5]->EDIT->url ='accounts/provider_edit/';
661
+						$field_arr[5]->DELETE->url ='accounts/provider_delete/';
662
+					   }
663
+					  }
664
+					  if($field_arr[5]->EDIT->url == 'accounts/admin_edit/' || $field_arr[5]->EDIT->url == 'accounts/subadmin_edit/' || $field_arr[5]->DELETE->url == 'accounts/admin_delete/' ||$field_arr[5]->DELETE->url == 'accounts/subadmin_delete/'){
665
+					   if($row['type'] == 2 || strtolower($row['type']) == 'administrator'){
666
+						$field_arr[5]->EDIT->url ='accounts/admin_edit/';
667
+						$field_arr[5]->DELETE->url ='accounts/admin_delete/';
668
+					   }
669
+					   if($row['type'] == 4 || strtolower($row['type']) == 'sub admin'){
670
+						$field_arr[5]->EDIT->url ='accounts/subadmin_edit/';
671
+						$field_arr[5]->DELETE->url ='accounts/subadmin_delete/';
672
+					   }
673
+					}
674 674
 			   }
675 675
 /*
676 676
 ASTPP  3.0  
677 677
 For edit on account number or name
678 678
 */			   
679
-                            $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row_id);
680
-                            /****************************************************************************/
681
-                        }
682
-                        elseif($field_arr[0] == gettext("Profile Action"))
683
-                        {
684
-                           if(isset($field_arr[5]) && isset($field_arr[5]->START) && isset($field_arr[5]->STOP) && isset($field_arr[5]->RELOAD) && isset($field_arr[5]->RESCAN)){
685
-                            }
686
-                           $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
679
+							$jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row_id);
680
+							/****************************************************************************/
681
+						}
682
+						elseif($field_arr[0] == gettext("Profile Action"))
683
+						{
684
+						   if(isset($field_arr[5]) && isset($field_arr[5]->START) && isset($field_arr[5]->STOP) && isset($field_arr[5]->RELOAD) && isset($field_arr[5]->RESCAN)){
685
+							}
686
+						   $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
687 687
                         
688
-                        }
689
-                        else {
690
-                            $className = (isset($field_arr['9']) && $field_arr['9'] != '')?$field_arr['9']:"chkRefNos";
691
-                            $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace '.$className.'" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';                        }
692
-                    }
693
-                }
694
-                $json_data[] = array('cell' => $jsn_tmp);
695
-            }
696
-        }
697
-        return $json_data;
698
-    }
699
-
700
-     function build_json_grid($query, $grid_fields) {
701
-        $jsn_tmp = array();
702
-        $json_data = array();
703
-        foreach ($query as $row) {
704
-            foreach ($grid_fields as $field_key => $field_arr) {
705
-                $row_id = isset($row['id']) ? $row["id"]: '';
688
+						}
689
+						else {
690
+							$className = (isset($field_arr['9']) && $field_arr['9'] != '')?$field_arr['9']:"chkRefNos";
691
+							$jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace '.$className.'" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';                        }
692
+					}
693
+				}
694
+				$json_data[] = array('cell' => $jsn_tmp);
695
+			}
696
+		}
697
+		return $json_data;
698
+	}
699
+
700
+	 function build_json_grid($query, $grid_fields) {
701
+		$jsn_tmp = array();
702
+		$json_data = array();
703
+		foreach ($query as $row) {
704
+			foreach ($grid_fields as $field_key => $field_arr) {
705
+				$row_id = isset($row['id']) ? $row["id"]: '';
706 706
 /**
707 707
 ASTPP  3.0 
708 708
 For Edit on Account number or name
@@ -710,44 +710,44 @@  discard block
 block discarded – undo
710 710
 		$Actionkey = array_search('Action',$this->CI->common->array_column($grid_fields,0)); 
711 711
 /*******************************/
712 712
 
713
-                if ($field_arr[2] != "") {
714
-                    if ($field_arr[3] != "") {
715
-                         if($field_arr[2]=="status"){
716
-                            $row['id'] = $row_id;
717
-                            $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
713
+				if ($field_arr[2] != "") {
714
+					if ($field_arr[3] != "") {
715
+						 if($field_arr[2]=="status"){
716
+							$row['id'] = $row_id;
717
+							$jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
718 718
 						 }else{
719
-                            $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
719
+							$jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
720 720
 						 }
721 721
 /**
722 722
 ASTPP  3.0 
723 723
 For Edit on Account number or name
724 724
 **/
725 725
  			$row[$field_arr[2]] = $jsn_tmp[$field_key];
726
-                      } if(array_search("EDITABLE", $field_arr)){
727
-			    $ActionArr = $grid_fields[$Actionkey];
728
-                if($ActionArr[5]->EDIT->url =="accounts/customer_edit/" || $ActionArr[5]->EDIT->url =="accounts/provider_edit/"){
729
-                   $ActionArr[5]->EDIT->url=$row['type']==0 ?  "accounts/customer_edit/"  : "accounts/provider_edit/";
730
-                }
731
-                if($ActionArr[5]->EDIT->url =="accounts/admin_edit/" || $ActionArr[5]->EDIT->url =="accounts/subadmin_edit/"){
732
-                   $ActionArr[5]->EDIT->url=$row['type']==4 ?  "accounts/subadmin_edit/"  : "accounts/admin_edit/";
733
-                }
734
-			    $jsn_tmp[$field_key] = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
726
+					  } if(array_search("EDITABLE", $field_arr)){
727
+				$ActionArr = $grid_fields[$Actionkey];
728
+				if($ActionArr[5]->EDIT->url =="accounts/customer_edit/" || $ActionArr[5]->EDIT->url =="accounts/provider_edit/"){
729
+				   $ActionArr[5]->EDIT->url=$row['type']==0 ?  "accounts/customer_edit/"  : "accounts/provider_edit/";
730
+				}
731
+				if($ActionArr[5]->EDIT->url =="accounts/admin_edit/" || $ActionArr[5]->EDIT->url =="accounts/subadmin_edit/"){
732
+				   $ActionArr[5]->EDIT->url=$row['type']==4 ?  "accounts/subadmin_edit/"  : "accounts/admin_edit/";
733
+				}
734
+				$jsn_tmp[$field_key] = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
735 735
 /*******************************/
736
-		    }else {
737
-                        $jsn_tmp[$field_key] = isset($row[$field_arr[2]]) ? $row[$field_arr[2]] : "";
738
-                    }
739
-                } else {
740
-                    if ($field_arr[0] == "Action") {
741
-                        $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
742
-                    }
743
-		      else {
744
-                            $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace chkRefNos" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';
745
-                        }
746
-                }
747
-            }
748
-            $json_data[] = array('cell' => $jsn_tmp);
749
-        }
750
-        return $json_data;
751
-    }
736
+			}else {
737
+						$jsn_tmp[$field_key] = isset($row[$field_arr[2]]) ? $row[$field_arr[2]] : "";
738
+					}
739
+				} else {
740
+					if ($field_arr[0] == "Action") {
741
+						$jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
742
+					}
743
+			  else {
744
+							$jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace chkRefNos" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';
745
+						}
746
+				}
747
+			}
748
+			$json_data[] = array('cell' => $jsn_tmp);
749
+		}
750
+		return $json_data;
751
+	}
752 752
 
753 753
 }
Please login to merge, or discard this patch.
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 /**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 class Form {
31 31
 
32 32
     protected $CI; // codeigniter
33
-    protected $fields = array();  // array of fields
33
+    protected $fields = array(); // array of fields
34 34
     protected $form_title = 'Form';
35 35
     protected $form_id = 'form';
36 36
     protected $form_action = '';
@@ -58,31 +58,31 @@  discard block
 block discarded – undo
58 58
     function check_permissions() {
59 59
         if ($this->CI->session->userdata('user_login') == TRUE) {
60 60
             $module_info = unserialize($this->CI->session->userdata("permited_modules"));
61
-            if($this->CI->session->userdata('userlevel_logintype')!= 0 && $this->CI->session->userdata('userlevel_logintype')!= 3){
62
-	    $module_info[]='dashboard';
61
+            if ($this->CI->session->userdata('userlevel_logintype') != 0 && $this->CI->session->userdata('userlevel_logintype') != 3) {
62
+	    $module_info[] = 'dashboard';
63 63
             }
64 64
             $url = $this->CI->uri->uri_string;
65 65
             $file_name = explode("/", $url);
66
-            if(isset($file_name['1']) ){
66
+            if (isset($file_name['1'])) {
67 67
 	      $module = explode('_', $file_name['1']);
68
-            }else{
69
-              $module=$file_name;
68
+            } else {
69
+              $module = $file_name;
70 70
             }
71
-            if($this->CI->session->userdata('userlevel_logintype')==1 ){
72
-				$module_info[]='user';
71
+            if ($this->CI->session->userdata('userlevel_logintype') == 1) {
72
+				$module_info[] = 'user';
73 73
 			}
74 74
             if (in_array($module[0], $module_info)) {
75
-                if($this->CI->session->userdata('userlevel_logintype')== 0 && $module[0] == 'customer' && isset($file_name[1]) && $file_name[1] !='customer_transfer'){
76
-                     redirect(base_url() . 'user/user/');
77
-                }else{
75
+                if ($this->CI->session->userdata('userlevel_logintype') == 0 && $module[0] == 'customer' && isset($file_name[1]) && $file_name[1] != 'customer_transfer') {
76
+                     redirect(base_url().'user/user/');
77
+                } else {
78 78
                    return true;
79 79
                 }
80 80
             } else {
81 81
                 $this->CI->session->set_userdata('astpp_errormsg', 'You do not have permission to access this module..!');
82 82
                 if ($this->CI->session->userdata('userlevel_logintype') == '-1' || $this->CI->session->userdata('logintype') == '1') {
83
-                    redirect(base_url() . 'dashboard/');
83
+                    redirect(base_url().'dashboard/');
84 84
                 } else {
85
-                    redirect(base_url() . 'user/user/');
85
+                    redirect(base_url().'user/user/');
86 86
                 }
87 87
             }
88 88
         } else {
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 
93 93
     function build_form($fields_array, $values) {
94 94
         $form_contents = '';
95
-        $form_contents.= '<div class="pop_md col-md-12 margin-t-10 padding-x-8">';
96
-        if(isset($fields_array['breadcrumb'])){
97
-            $form_contents.=form_breadcrumb($fields_array['breadcrumb']);
95
+        $form_contents .= '<div class="pop_md col-md-12 margin-t-10 padding-x-8">';
96
+        if (isset($fields_array['breadcrumb'])) {
97
+            $form_contents .= form_breadcrumb($fields_array['breadcrumb']);
98 98
             unset($fields_array['breadcrumb']);
99 99
         }
100
-        $form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
100
+        $form_contents .= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
101 101
         unset($fields_array['forms']);
102 102
         $button_array = array();
103 103
         if (isset($fields_array['button_save']) || isset($fields_array['button_cancel']) || isset($fields_array['additional_button'])) {
@@ -113,76 +113,76 @@  discard block
 block discarded – undo
113 113
             }
114 114
         }
115 115
         if (isset($additiopnal_button)) {
116
-            $form_contents.= form_button(gettext($additiopnal_button));
116
+            $form_contents .= form_button(gettext($additiopnal_button));
117 117
         }
118 118
         $i = 0;
119 119
         foreach ($fields_array as $fieldset_key => $form_fileds) {
120 120
             if (count($fields_array) > 1) {
121 121
                 if ($i == 1 || $i == 3) {
122
-                    $form_contents.= '<div class="col-md-6 no-padding pull-right">';
123
-                    $form_contents.= '<div class="col-md-12 padding-x-4">';
122
+                    $form_contents .= '<div class="col-md-6 no-padding pull-right">';
123
+                    $form_contents .= '<div class="col-md-12 padding-x-4">';
124 124
                 } else {
125
-                    $form_contents.= '<div class="col-md-6 no-padding">';
126
-                    $form_contents.= '<div class="col-md-12 padding-x-4">';
125
+                    $form_contents .= '<div class="col-md-6 no-padding">';
126
+                    $form_contents .= '<div class="col-md-12 padding-x-4">';
127 127
                 }
128 128
             } else {
129
-               $form_contents.= '<div class="col-md-12 no-padding">';
130
-                $form_contents.= '<div class="col-md-12 no-padding">';
129
+               $form_contents .= '<div class="col-md-12 no-padding">';
130
+                $form_contents .= '<div class="col-md-12 no-padding">';
131 131
             }
132
-            $form_contents.= '<ul class="no-padding">';
133
-                $form_contents.= '<div class="col-md-12 no-padding">';
132
+            $form_contents .= '<ul class="no-padding">';
133
+                $form_contents .= '<div class="col-md-12 no-padding">';
134 134
             if ($i == 1 || $i == 3) {
135
-                $form_contents.= form_fieldset(gettext($fieldset_key));
135
+                $form_contents .= form_fieldset(gettext($fieldset_key));
136 136
             } else {
137
-                $form_contents.= form_fieldset(gettext($fieldset_key));
137
+                $form_contents .= form_fieldset(gettext($fieldset_key));
138 138
             }
139 139
             foreach ($form_fileds as $fieldkey => $fieldvalue) {
140
-                $form_contents.= '<li class="col-md-12">';
140
+                $form_contents .= '<li class="col-md-12">';
141 141
                 if ($fieldvalue[1] == 'HIDDEN') {
142 142
                     if (isset($this->CI->input->post))
143
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
143
+                        $fieldvalue[2]['value'] = ( ! $this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
144 144
                     else
145
-                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
146
-                    $form_contents.= form_hidden($fieldvalue[2]['name'], $fieldvalue[2]['value']);
147
-                }else {
148
-		      $validation_arr=array();
149
-		      if($fieldvalue[1]=='INPUT'){
150
-		        if(!empty($fieldvalue[3])){
151
-		          $validation_arr=explode("|",$fieldvalue[3]);
145
+                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : '') : (isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] : '');
146
+                    $form_contents .= form_hidden($fieldvalue[2]['name'], $fieldvalue[2]['value']);
147
+                } else {
148
+		      $validation_arr = array();
149
+		      if ($fieldvalue[1] == 'INPUT') {
150
+		        if ( ! empty($fieldvalue[3])) {
151
+		          $validation_arr = explode("|", $fieldvalue[3]);
152 152
 		        }
153 153
 		      }
154
-		      elseif($fieldvalue[2]=='SELECT'){
154
+		      elseif ($fieldvalue[2] == 'SELECT') {
155 155
 
156
-		        if(is_array($fieldvalue[4])){
157
-		          $validation_arr=explode("|",$fieldvalue[4]['rules']);
158
-		        }else{
159
-		        $validation_arr=explode("|",$fieldvalue[4]);
156
+		        if (is_array($fieldvalue[4])) {
157
+		          $validation_arr = explode("|", $fieldvalue[4]['rules']);
158
+		        } else {
159
+		        $validation_arr = explode("|", $fieldvalue[4]);
160 160
 		        }
161 161
 		      }
162
-		      if(!empty($validation_arr)){
163
-		      $fieldvalue[0] = in_array('required',$validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
164
-		      $fieldvalue[0] = in_array('dropdown',$validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
162
+		      if ( ! empty($validation_arr)) {
163
+		      $fieldvalue[0] = in_array('required', $validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
164
+		      $fieldvalue[0] = in_array('dropdown', $validation_arr) ? $fieldvalue[0]."<span style='color:black;'> *</span>" : $fieldvalue[0];
165 165
 		      }
166 166
  
167 167
                     if (is_array($fieldvalue[1]) || (is_array($fieldvalue[2]) && isset($fieldvalue[2]['hidden']))) {
168
-                        $form_contents.= form_label(gettext($fieldvalue[0]), $fieldvalue[0], array('class' => 'col-md-3 no-padding add_settings'));
168
+                        $form_contents .= form_label(gettext($fieldvalue[0]), $fieldvalue[0], array('class' => 'col-md-3 no-padding add_settings'));
169 169
                     } else {
170
-                        $form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "col-md-3 no-padding"));
170
+                        $form_contents .= form_label(gettext($fieldvalue[0]), "", array("class" => "col-md-3 no-padding"));
171 171
                     }
172 172
                 }
173
-                if ($fieldvalue[2] == 'SELECT' && !isset($fieldvalue[13])) {
173
+                if ($fieldvalue[2] == 'SELECT' && ! isset($fieldvalue[13])) {
174 174
 
175 175
                 /*
176 176
                  To make Drop down enabled disabled
177 177
                 */
178
-                 $extra =isset($fieldvalue[1]['extra']) ? $fieldvalue[1]['extra'] :'';
178
+                 $extra = isset($fieldvalue[1]['extra']) ? $fieldvalue[1]['extra'] : '';
179 179
                  /***************************/
180 180
                     if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
181
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
181
+                        $str = $fieldvalue[7].",".$fieldvalue[8];
182 182
 
183
-                        if (isset($this->CI->input->post)){
184
-                            $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
185
-                        }else{
183
+                        if (isset($this->CI->input->post)) {
184
+                            $fieldvalue['value'] = ( ! $this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
185
+                        } else {
186 186
                             if (is_array($fieldvalue[1])) {
187 187
                                 $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
188 188
                             } else {
@@ -191,38 +191,38 @@  discard block
 block discarded – undo
191 191
                         }
192 192
                         $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
193 193
 
194
-                        if ($fieldset_key ==  gettext('System Configuration Information') || ($fieldset_key == 'Billing Information'  && $fieldvalue[0] == 'Force Trunk') || ($fieldset_key == 'Card Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key == 'Billing Information' && $fieldvalue[0] == 'Account') || $fieldset_key == 'Freeswitch Devices' && $fieldvalue[0] == 'Rate Group' || ($fieldset_key== 'Origination Rate Add/Edit' && $fieldvalue[0] == 'Trunks' )||$fieldset_key== 'Billing Information' && $fieldvalue[0] == 'Rate Group'  || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Failover GW Name #1') || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Failover GW Name #2') || ($fieldset_key== 'Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key== 'Sip Devices' && $fieldvalue[0] == 'Sip Profile') || ($fieldset_key== 'Sip Devices' && $fieldvalue[0] == 'Account')) {
195
-                            $form_contents.=form_dropdown_all($fieldvalue[1], $drp_array, $fieldvalue['value'],$extra);
194
+                        if ($fieldset_key == gettext('System Configuration Information') || ($fieldset_key == 'Billing Information' && $fieldvalue[0] == 'Force Trunk') || ($fieldset_key == 'Card Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key == 'Billing Information' && $fieldvalue[0] == 'Account') || $fieldset_key == 'Freeswitch Devices' && $fieldvalue[0] == 'Rate Group' || ($fieldset_key == 'Origination Rate Add/Edit' && $fieldvalue[0] == 'Trunks') || $fieldset_key == 'Billing Information' && $fieldvalue[0] == 'Rate Group' || ($fieldset_key == 'Information' && $fieldvalue[0] == 'Failover GW Name #1') || ($fieldset_key == 'Information' && $fieldvalue[0] == 'Failover GW Name #2') || ($fieldset_key == 'Information' && $fieldvalue[0] == 'Rate Group') || ($fieldset_key == 'Sip Devices' && $fieldvalue[0] == 'Sip Profile') || ($fieldset_key == 'Sip Devices' && $fieldvalue[0] == 'Account')) {
195
+                            $form_contents .= form_dropdown_all($fieldvalue[1], $drp_array, $fieldvalue['value'], $extra);
196 196
                         } else {
197
-                            $form_contents.=form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'], $extra);
197
+                            $form_contents .= form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'], $extra);
198 198
                         }
199
-			            if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
200
-                        	if(is_array($fieldvalue[4])){
199
+			            if (isset($fieldvalue[4]) && $fieldvalue[4] != '') {
200
+                        	if (is_array($fieldvalue[4])) {
201 201
 								
202
-								if(isset($fieldvalue[1]['name'])){
203
-									$fieldvalue_pass=$fieldvalue[1]['name'];
204
-								}else{
205
-									$fieldvalue_pass=$fieldvalue[1];
202
+								if (isset($fieldvalue[1]['name'])) {
203
+									$fieldvalue_pass = $fieldvalue[1]['name'];
204
+								} else {
205
+									$fieldvalue_pass = $fieldvalue[1];
206 206
 								}
207 207
 								
208 208
         				        $this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]['rules']);
209
-        				    }else{
209
+        				    } else {
210 210
 								
211
-								if(isset($fieldvalue[1]['name'])){
212
-									$fieldvalue_pass=$fieldvalue[1]['name'];
213
-								}else{
214
-									$fieldvalue_pass=$fieldvalue[1];
211
+								if (isset($fieldvalue[1]['name'])) {
212
+									$fieldvalue_pass = $fieldvalue[1]['name'];
213
+								} else {
214
+									$fieldvalue_pass = $fieldvalue[1];
215 215
 								}
216 216
 								
217 217
         				       $this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]);
218 218
         				    }   
219 219
                         }
220
-                        $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
221
-                        $form_contents.= '<span class="popup_error error  no-padding" id="'.(gettext(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1])).'_error">
220
+                        $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1]) ? $fieldvalue[1]['name'] : $fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
221
+                        $form_contents .= '<span class="popup_error error  no-padding" id="'.(gettext(is_array($fieldvalue[1]) ? $fieldvalue[1]['name'] : $fieldvalue[1])).'_error">
222 222
                         </span></div>';                         
223 223
                     } else {
224 224
                         if (isset($this->CI->input->post)) {
225
-                            $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
225
+                            $fieldvalue['value'] = ( ! $this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
226 226
                         } else {
227 227
                             if (is_array($fieldvalue[1])) {
228 228
                                 $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
@@ -231,53 +231,53 @@  discard block
 block discarded – undo
231 231
                             }
232 232
                         }
233 233
 
234
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
234
+                        $str = $fieldvalue[7].",".$fieldvalue[8];
235 235
                         $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
236
-                        $form_contents.=form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'],$extra);
237
-                        if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
236
+                        $form_contents .= form_dropdown($fieldvalue[1], $drp_array, $fieldvalue['value'], $extra);
237
+                        if (isset($fieldvalue[4]) && $fieldvalue[4] != '') {
238 238
 			  $this->CI->form_validation->set_rules($fieldvalue[1], $fieldvalue[0], $fieldvalue[4]);
239 239
                         }
240
-                        $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
241
-                        $form_contents.= '<span class="popup_error error  no-padding" id="'.(is_array($fieldvalue[1])?$fieldvalue[1]['name']:$fieldvalue[1]).'_error">
240
+                        $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.(is_array($fieldvalue[1]) ? $fieldvalue[1]['name'] : $fieldvalue[1]).'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
241
+                        $form_contents .= '<span class="popup_error error  no-padding" id="'.(is_array($fieldvalue[1]) ? $fieldvalue[1]['name'] : $fieldvalue[1]).'_error">
242 242
                         </span></div>';                        
243 243
                     }
244 244
                 } else if (isset($fieldvalue[13]) && $fieldvalue[13] != '') {
245 245
 
246 246
                     /* For multi select code */
247
-                    $str = $fieldvalue[7] . "," . $fieldvalue[8];
247
+                    $str = $fieldvalue[7].",".$fieldvalue[8];
248 248
 
249 249
                     if (isset($this->CI->input->post))
250
-                        $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
250
+                        $fieldvalue['value'] = ( ! $this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
251 251
                     else
252 252
                         $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
253 253
 
254 254
                     $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
255 255
                     if ($fieldset_key === 'System Configuration Information') {
256
-                        $form_contents.=form_dropdown_multiselect($fieldvalue[1], $drp_array, '');
256
+                        $form_contents .= form_dropdown_multiselect($fieldvalue[1], $drp_array, '');
257 257
                     } else {
258
-                        $form_contents.=form_dropdown_multiselect($fieldvalue[1] . "[]", $drp_array, $fieldvalue['value']);
258
+                        $form_contents .= form_dropdown_multiselect($fieldvalue[1]."[]", $drp_array, $fieldvalue['value']);
259 259
                     }
260
-                    if(isset($fieldvalue[4]) && $fieldvalue[4] != ''){
260
+                    if (isset($fieldvalue[4]) && $fieldvalue[4] != '') {
261 261
 			$this->CI->form_validation->set_rules($fieldvalue[1], $fieldvalue[0], $fieldvalue[4]);
262 262
                     }
263
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[1].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
264
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[1].'_error"></span></div>';                   
263
+                    $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[1].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
264
+                    $form_contents .= '<span class="popup_error error  no-padding" id="'.$fieldvalue[1].'_error"></span></div>';                   
265 265
                     /* End---------------------   For multi select code */
266 266
                 } else if ($fieldvalue[1] == 'INPUT') {
267 267
 
268 268
 
269 269
                     if (isset($this->CI->input->post))
270
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? $fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
271
-                    else{
272
-                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
270
+                        $fieldvalue[2]['value'] = ( ! $this->CI->input->post($fieldvalue[2]['name'])) ? $fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
271
+                    else {
272
+                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : '') : (isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] : '');
273 273
                     }    
274
-                    $form_contents.= form_input($fieldvalue[2], 'readonly');
275
-                    if(isset($fieldvalue[6]) && !empty($fieldvalue[6])){
276
-                        $form_contents.=$fieldvalue[6];
274
+                    $form_contents .= form_input($fieldvalue[2], 'readonly');
275
+                    if (isset($fieldvalue[6]) && ! empty($fieldvalue[6])) {
276
+                        $form_contents .= $fieldvalue[6];
277 277
                     }    
278 278
                     $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
279
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
280
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
279
+                    $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
280
+                    $form_contents .= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
281 281
                     </span></div>';
282 282
                 }
283 283
                 /* 
@@ -285,98 +285,98 @@  discard block
 block discarded – undo
285 285
                  */
286 286
                 else if ($fieldvalue[1] == 'IMAGE') {
287 287
                     if (isset($this->CI->input->post))
288
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
288
+                        $fieldvalue[2]['value'] = ( ! $this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
289 289
                        
290 290
                     else
291 291
                         $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
292 292
                         $fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
293
-                    $form_contents.= form_image($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
294
-                    	 $form_contents.=@$fieldvalue[6];
293
+                    $form_contents .= form_image($fieldvalue[2], 'readonly', $fieldvalue[2]['style']);
294
+                    	 $form_contents .= @$fieldvalue[6];
295 295
                     $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
296
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
297
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
296
+                    $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
297
+                    $form_contents .= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
298 298
                     </span></div>';
299 299
                 }
300 300
                 else if ($fieldvalue[1] == 'DEL_BUTTON') {
301 301
                     if (isset($this->CI->input->post))
302
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
302
+                        $fieldvalue[2]['value'] = ( ! $this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
303 303
                        
304 304
                     else
305 305
                         $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
306 306
                         $fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
307
-                    $form_contents.= form_img_delete($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
308
-                    	 $form_contents.=@$fieldvalue[6];
307
+                    $form_contents .= form_img_delete($fieldvalue[2], 'readonly', $fieldvalue[2]['style']);
308
+                    	 $form_contents .= @$fieldvalue[6];
309 309
                     $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
310
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
311
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
310
+                    $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
311
+                    $form_contents .= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
312 312
                     </span></div>';
313 313
                 }
314 314
                 /**********************************************************************************/
315 315
                 else if ($fieldvalue[1] == 'PASSWORD') {
316 316
                     if (isset($this->CI->input->post))
317
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
317
+                        $fieldvalue[2]['value'] = ( ! $this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
318 318
                     else
319
-                        $fieldvalue[2]['value'] = ($values) ?@$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
320
-                    $form_contents.= form_password($fieldvalue[2]);
319
+                        $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
320
+                    $form_contents .= form_password($fieldvalue[2]);
321 321
                     $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
322
-                    $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
323
-                    $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
322
+                    $form_contents .= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
323
+                    $form_contents .= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
324 324
                     </span></div>';
325 325
                 } else if ($fieldvalue[2] == 'CHECKBOX') {
326 326
                     $OptionArray = array();
327 327
 
328
-					if(isset($fieldvalue[7]) && $fieldvalue[7] != '')
328
+					if (isset($fieldvalue[7]) && $fieldvalue[7] != '')
329 329
 					$OptionArray = call_user_func_array(array($this->CI->common, $fieldvalue[7]), array($fieldvalue[6]));
330
-                    if (isset($this->CI->input->post)){
331
-                        $fieldvalue[3]['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[3]['value'] : $this->CI->input->post($fieldvalue[1]);
330
+                    if (isset($this->CI->input->post)) {
331
+                        $fieldvalue[3]['value'] = ( ! $this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[3]['value'] : $this->CI->input->post($fieldvalue[1]);
332 332
                     }    
333 333
                     else
334 334
                     {
335
-                        $fieldvalue[3]['value'] = ($values) ? (isset($values[$fieldvalue[1]]) && $values[$fieldvalue[1]] ? 1: 0) : @$fieldvalue[3]['value'];
335
+                        $fieldvalue[3]['value'] = ($values) ? (isset($values[$fieldvalue[1]]) && $values[$fieldvalue[1]] ? 1 : 0) : @$fieldvalue[3]['value'];
336 336
 					}
337 337
                     if ($fieldvalue[3]['value'] == "1") {
338 338
                         $checked = true;
339 339
                     } else {
340 340
                         $checked = false;
341 341
                     };
342
-                    if(isset($fieldvalue[3]['table_name']) && $fieldvalue[3]['table_name'] != ""){
342
+                    if (isset($fieldvalue[3]['table_name']) && $fieldvalue[3]['table_name'] != "") {
343 343
 							
344
-						 $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'],$checked , $OptionArray);
345
-					}else{
346
-						 $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'],$checked ,$OptionArray);
344
+						 $form_contents .= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'], $checked, $OptionArray);
345
+					} else {
346
+						 $form_contents .= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'], $checked, $OptionArray);
347 347
 					}
348 348
                 } else if ($fieldvalue[1] == 'TEXTAREA') {
349 349
 
350 350
                     if (isset($this->CI->input->post))
351
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
351
+                        $fieldvalue[2]['value'] = ( ! $this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
352 352
                     else
353 353
                         $fieldvalue[2]['value'] = ($values) ? $values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
354
-                    $form_contents.= form_textarea($fieldvalue[2]);
354
+                    $form_contents .= form_textarea($fieldvalue[2]);
355 355
                 }
356 356
                 else if ($fieldvalue[2] == 'RADIO') {
357 357
 
358
-                    $form_contents.= form_radio($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
358
+                    $form_contents .= form_radio($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
359 359
                 }
360
-                $form_contents.= '</li>';
360
+                $form_contents .= '</li>';
361 361
             }
362 362
 
363
-            $form_contents.= '</ul>';
364
-            $form_contents.= '</div>';
365
-            $form_contents.= '</div>';
363
+            $form_contents .= '</ul>';
364
+            $form_contents .= '</div>';
365
+            $form_contents .= '</div>';
366 366
             $i++;
367 367
         }
368 368
 
369
-        $form_contents.= '<center><div class="col-md-12 margin-t-20 margin-b-20">';
369
+        $form_contents .= '<center><div class="col-md-12 margin-t-20 margin-b-20">';
370 370
 
371
-        $form_contents.= form_button($save);
371
+        $form_contents .= form_button($save);
372 372
 
373 373
 	if (isset($cancel)) {
374
-            $form_contents.= form_button($cancel);
374
+            $form_contents .= form_button($cancel);
375 375
         }
376
-        $form_contents.= '</center></div>';
377
-        $form_contents.= form_fieldset_close();
378
-        $form_contents.= form_close();
379
-        $form_contents.= '</div>';
376
+        $form_contents .= '</center></div>';
377
+        $form_contents .= form_fieldset_close();
378
+        $form_contents .= form_close();
379
+        $form_contents .= '</div>';
380 380
 
381 381
 
382 382
         return $form_contents;
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 
385 385
     function build_serach_form($fields_array) {
386 386
         $form_contents = '';
387
-        $form_contents.= '<div>';
388
-        $form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
387
+        $form_contents .= '<div>';
388
+        $form_contents .= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
389 389
         unset($fields_array['forms']);
390 390
         $button_array = array();
391 391
 	/*******
@@ -398,13 +398,13 @@  discard block
 block discarded – undo
398 398
                 $cancel = $fields_array['button_reset'];
399 399
                 unset($fields_array['button_reset']);
400 400
             }
401
-	    $button_search_delete='';
401
+	    $button_search_delete = '';
402 402
             if (isset($fields_array['button_search_delete'])) {
403 403
                 $button_search_delete = $fields_array['button_search_delete'];
404 404
                 unset($fields_array['button_search_delete']);
405 405
             }
406
-            if(isset($fields_array['display_in'])){
407
-	      $display_in=$fields_array['display_in'];
406
+            if (isset($fields_array['display_in'])) {
407
+	      $display_in = $fields_array['display_in'];
408 408
 	      unset($fields_array['display_in']);
409 409
 	    }
410 410
         }
@@ -412,31 +412,31 @@  discard block
 block discarded – undo
412 412
         $i = 1;
413 413
         foreach ($fields_array as $fieldset_key => $form_fileds) {
414 414
 
415
-            $form_contents.= '<ul class="padding-15">';
416
-            $form_contents.= form_fieldset(gettext($fieldset_key),array('style' => 'font-weight:bold;'),"search");
415
+            $form_contents .= '<ul class="padding-15">';
416
+            $form_contents .= form_fieldset(gettext($fieldset_key), array('style' => 'font-weight:bold;'), "search");
417 417
 
418 418
             foreach ($form_fileds as $fieldkey => $fieldvalue) {
419 419
                 if ($i == 0) {
420
-                    $form_contents.= '<li class="col-md-12">';
420
+                    $form_contents .= '<li class="col-md-12">';
421 421
                 }
422
-                $form_contents.= '<div class="col-md-3 no-padding">';
422
+                $form_contents .= '<div class="col-md-3 no-padding">';
423 423
                 if ($fieldvalue[1] == 'HIDDEN') {
424
-                    $form_contents.= form_hidden($fieldvalue[2], $fieldvalue[3]);
424
+                    $form_contents .= form_hidden($fieldvalue[2], $fieldvalue[3]);
425 425
                 } else {
426
-                    $form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
426
+                    $form_contents .= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
427 427
                 }
428 428
                 if ($fieldvalue[1] == 'INPUT') {
429
-                    $form_contents.= form_input($fieldvalue[2]);
429
+                    $form_contents .= form_input($fieldvalue[2]);
430 430
                 }
431 431
 
432 432
 
433 433
                 if ($fieldvalue[2] == 'SELECT' || $fieldvalue[5] == '1') {
434 434
 			  
435 435
                     if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
436
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
436
+                        $str = $fieldvalue[7].",".$fieldvalue[8];
437 437
 
438 438
                         $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
439
-                        $form_contents.=form_dropdown_all(gettext($fieldvalue[1]), $drp_array, '');
439
+                        $form_contents .= form_dropdown_all(gettext($fieldvalue[1]), $drp_array, '');
440 440
                     } else {
441 441
 
442 442
                         if ($fieldvalue[1] == 'INPUT') {
@@ -444,54 +444,54 @@  discard block
 block discarded – undo
444 444
                         }
445 445
 			
446 446
                         $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
447
-                        $form_contents.=form_dropdown_all_search(gettext($fieldvalue[1]), $drp_array, '');
447
+                        $form_contents .= form_dropdown_all_search(gettext($fieldvalue[1]), $drp_array, '');
448 448
                     }
449 449
                 } else if ($fieldvalue[1] == 'PASSWORD') {
450
-                    $form_contents.= form_password($fieldvalue[2]);
450
+                    $form_contents .= form_password($fieldvalue[2]);
451 451
                 } else if ($fieldvalue[2] == 'CHECKBOX') {
452
-                    $form_contents.= form_checkbox(gettext($fieldvalue[1]), $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
452
+                    $form_contents .= form_checkbox(gettext($fieldvalue[1]), $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
453 453
                 }
454
-                $form_contents.= '</div>';
454
+                $form_contents .= '</div>';
455 455
                 if ($i % 5 == 0) {
456
-                    $form_contents.= '</li>';
456
+                    $form_contents .= '</li>';
457 457
                     $i = 0;
458 458
                 }
459 459
                 $i++;
460 460
             }
461 461
         }
462
-        $form_contents.= '<div class="col-md-12 margin-t-20 margin-b-20">';
463
-        $form_contents.= form_button($cancel);
464
-        $form_contents.= form_button($save);
465
-        if(!empty($display_in)){
466
-            $form_contents.="<div class='col-md-5 pull-right'>";
467
-            $form_contents.="<div class='col-md-3'></div>";
468
-            $extra_parameters['class']=$display_in['label_class'];
469
-            $extra_parameters['style']=$display_in['label_style'];
470
-            $form_contents.=form_label($display_in['content'], "",$extra_parameters);
471
-            $drp_array = call_user_func_array(array($this->CI->common,$display_in['function']),array());
472
-            $extra_parameters['class']=$display_in['dropdown_class'];
473
-            $extra_parameters['style']=$display_in['dropdown_style'];
474
-            $form_contents.=form_dropdown_all_search($display_in, $drp_array, '',$extra_parameters);
475
-            $form_contents.="</div>";
462
+        $form_contents .= '<div class="col-md-12 margin-t-20 margin-b-20">';
463
+        $form_contents .= form_button($cancel);
464
+        $form_contents .= form_button($save);
465
+        if ( ! empty($display_in)) {
466
+            $form_contents .= "<div class='col-md-5 pull-right'>";
467
+            $form_contents .= "<div class='col-md-3'></div>";
468
+            $extra_parameters['class'] = $display_in['label_class'];
469
+            $extra_parameters['style'] = $display_in['label_style'];
470
+            $form_contents .= form_label($display_in['content'], "", $extra_parameters);
471
+            $drp_array = call_user_func_array(array($this->CI->common, $display_in['function']), array());
472
+            $extra_parameters['class'] = $display_in['dropdown_class'];
473
+            $extra_parameters['style'] = $display_in['dropdown_style'];
474
+            $form_contents .= form_dropdown_all_search($display_in, $drp_array, '', $extra_parameters);
475
+            $form_contents .= "</div>";
476 476
         }
477
-        if(isset($button_search_delete) && $button_search_delete != ''){
478
-	  $form_contents.= form_button($button_search_delete);
477
+        if (isset($button_search_delete) && $button_search_delete != '') {
478
+	  $form_contents .= form_button($button_search_delete);
479 479
         }
480
-        $form_contents.='<div class="col-md-12 no-padding margin-t-15" style="">
480
+        $form_contents .= '<div class="col-md-12 no-padding margin-t-15" style="">
481 481
 		<div class="pull-right btn-close" id="global_clearsearch_filter">Close</div> 
482 482
 	</div>';
483
-        $form_contents.= '</ul>';        
484
-        $form_contents.= '</div>';
485
-        $form_contents.= form_fieldset_close();
486
-        $form_contents.= form_close();
487
-        $form_contents.= '</div>';
483
+        $form_contents .= '</ul>';        
484
+        $form_contents .= '</div>';
485
+        $form_contents .= form_fieldset_close();
486
+        $form_contents .= form_close();
487
+        $form_contents .= '</div>';
488 488
 
489 489
         return $form_contents;
490 490
     }
491 491
     function build_batchupdate_form($fields_array) {
492 492
         $form_contents = '';
493
-        $form_contents.= '<div >';
494
-        $form_contents.= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
493
+        $form_contents .= '<div >';
494
+        $form_contents .= form_open($fields_array['forms'][0], $fields_array['forms'][1]);
495 495
         unset($fields_array['forms']);
496 496
         $button_array = array();
497 497
         if (isset($fields_array['button_search']) || isset($fields_array['button_reset'])) {
@@ -505,69 +505,69 @@  discard block
 block discarded – undo
505 505
         $i = 1;
506 506
         foreach ($fields_array as $fieldset_key => $form_fileds) {
507 507
 
508
-            $form_contents.= '<ul>';
509
-            $form_contents.= form_fieldset(gettext($fieldset_key), array('style' => 'margin-left:-22px;font-weight:bold;'));
508
+            $form_contents .= '<ul>';
509
+            $form_contents .= form_fieldset(gettext($fieldset_key), array('style' => 'margin-left:-22px;font-weight:bold;'));
510 510
             foreach ($form_fileds as $fieldkey => $fieldvalue) {
511 511
                 if ($i == 0) {
512
-                    $form_contents.= '<li>';
512
+                    $form_contents .= '<li>';
513 513
                 }
514
-                $form_contents.= '<div class="col-md-4 no-padding">';
514
+                $form_contents .= '<div class="col-md-4 no-padding">';
515 515
                 if ($fieldvalue[1] == 'HIDDEN') {
516
-                    $form_contents.= form_hidden($fieldvalue[2], $fieldvalue[3]);
516
+                    $form_contents .= form_hidden($fieldvalue[2], $fieldvalue[3]);
517 517
                 } else {
518
-                    $form_contents.= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
518
+                    $form_contents .= form_label(gettext($fieldvalue[0]), "", array("class" => "search_label col-md-12 no-padding"));
519 519
                 }
520 520
                 if ($fieldvalue[2] == 'SELECT' || $fieldvalue[5] == '1') {
521 521
                     if ($fieldvalue[7] != '' && $fieldvalue[8] != '') {
522
-                        $str = $fieldvalue[7] . "," . $fieldvalue[8];
523
-                        if(is_array($fieldvalue[13])){
522
+                        $str = $fieldvalue[7].",".$fieldvalue[8];
523
+                        if (is_array($fieldvalue[13])) {
524 524
                             $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[14]), array($fieldvalue[13]));
525
-                            $form_contents.=form_dropdown($fieldvalue[13], $drp_array, '');
525
+                            $form_contents .= form_dropdown($fieldvalue[13], $drp_array, '');
526 526
                         }
527 527
                         /**
528 528
   		        ASTPP  3.0 
529 529
    		        Reseller Batch Update
530 530
                         **/ 
531
-                        if($fieldvalue[10] == 'set_status'){
532
-			$drp_array =array('0'=>'Active','1'=>'Inactive');
531
+                        if ($fieldvalue[10] == 'set_status') {
532
+			$drp_array = array('0'=>'Active', '1'=>'Inactive');
533 533
 			}
534 534
 			/************************************************************/
535
-			else{
536
-                        $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));}
537
-                        $form_contents.=form_dropdown_all($fieldvalue[1], $drp_array, '');
535
+			else {
536
+                        $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12])); }
537
+                        $form_contents .= form_dropdown_all($fieldvalue[1], $drp_array, '');
538 538
                     } else {
539 539
                         if ($fieldvalue[1] == 'INPUT') {
540 540
                             $drp_name = $fieldvalue[6];
541 541
                         }
542 542
                         $drp_array = call_user_func_array(array($this->CI->common, $fieldvalue[10]), array($fieldvalue[9]));
543
-                        $form_contents.=form_dropdown($drp_name, $drp_array, '');
543
+                        $form_contents .= form_dropdown($drp_name, $drp_array, '');
544 544
                     }
545 545
                 }
546 546
                 if ($fieldvalue[1] == 'INPUT') {
547
-                    $form_contents.= form_input($fieldvalue[2]);
547
+                    $form_contents .= form_input($fieldvalue[2]);
548 548
                 } else if ($fieldvalue[2] == 'CHECKBOX') {
549
-                    $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
549
+                    $form_contents .= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
550 550
                 }
551
-                $form_contents.= '</div>';
551
+                $form_contents .= '</div>';
552 552
                 if ($i % 5 == 0) {
553
-                    $form_contents.= '</li>';
553
+                    $form_contents .= '</li>';
554 554
                     $i = 0;
555 555
                 }
556 556
                 $i++;
557 557
             }
558 558
         }
559 559
 
560
-        $form_contents.= '</ul>';
561
-        $form_contents.= '<div class="col-md-12 margin-t-20 margin-b-20">';
560
+        $form_contents .= '</ul>';
561
+        $form_contents .= '<div class="col-md-12 margin-t-20 margin-b-20">';
562 562
 
563
-        $form_contents.= form_button($cancel);
564
-        $form_contents.= form_button($save);
565
-        $form_contents.='<div class="col-md-12 no-padding margin-t-15" style="margin-bottom:10px; !important">
563
+        $form_contents .= form_button($cancel);
564
+        $form_contents .= form_button($save);
565
+        $form_contents .= '<div class="col-md-12 no-padding margin-t-15" style="margin-bottom:10px; !important">
566 566
 						<div class="pull-right btn-close" id="global_clearbatchupdate_filter">Close</div></div>';
567
-        $form_contents.= form_fieldset_close();
568
-        $form_contents.= form_close();
569
-        $form_contents.= '</div>';
570
-        $form_contents.= '</div>';
567
+        $form_contents .= form_fieldset_close();
568
+        $form_contents .= form_close();
569
+        $form_contents .= '</div>';
570
+        $form_contents .= '</div>';
571 571
 
572 572
         return $form_contents;
573 573
     }
@@ -599,21 +599,21 @@  discard block
 block discarded – undo
599 599
                 ASTPP  3.0 
600 600
                 For Edit on Account number or name
601 601
             */
602
-		$row_id = isset($row['id']) ? $row["id"]: '';
602
+		$row_id = isset($row['id']) ? $row["id"] : '';
603 603
 /*****************************/
604 604
                 foreach ($grid_fields as $field_key => $field_arr) {
605 605
 /**
606 606
 ASTPP  3.0 
607 607
 For Edit on Account number or name
608 608
 **/
609
-		     $Actionkey = array_search(gettext('Action'), $this->CI->common->array_column($grid_fields,0));
609
+		     $Actionkey = array_search(gettext('Action'), $this->CI->common->array_column($grid_fields, 0));
610 610
 /*********************************/
611 611
                     if ($field_arr[2] != "") {
612 612
                         if ($field_arr[3] != "") {
613
-                           if($field_arr[2]=="status"){
613
+                           if ($field_arr[2] == "status") {
614 614
                             $row['id'] = $row_id;
615 615
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
616
-			   }else{
616
+			   } else {
617 617
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
618 618
 			   }
619 619
 
@@ -622,53 +622,53 @@  discard block
 block discarded – undo
622 622
 For Edit on Account number or name
623 623
 **/
624 624
 			    $row[$field_arr[2]] = $jsn_tmp[$field_key];
625
-            } if(array_search("EDITABLE", $field_arr)){
625
+            } if (array_search("EDITABLE", $field_arr)) {
626 626
 			    $ActionArr = $grid_fields[$Actionkey];
627
-                if($ActionArr[5]->EDIT->url =="accounts/customer_edit/" || $ActionArr[5]->EDIT->url =="accounts/provider_edit/"){
628
-                   $ActionArr[5]->EDIT->url=$row['type']==0 ?  "accounts/customer_edit/"  : "accounts/provider_edit/";
627
+                if ($ActionArr[5]->EDIT->url == "accounts/customer_edit/" || $ActionArr[5]->EDIT->url == "accounts/provider_edit/") {
628
+                   $ActionArr[5]->EDIT->url = $row['type'] == 0 ? "accounts/customer_edit/" : "accounts/provider_edit/";
629 629
                 }
630
-                if($ActionArr[5]->EDIT->url =="accounts/admin_edit/" || $ActionArr[5]->EDIT->url =="accounts/subadmin_edit/"){
631
-                   $ActionArr[5]->EDIT->url=$row['type']==4 ?  "accounts/subadmin_edit/"  : "accounts/admin_edit/";
630
+                if ($ActionArr[5]->EDIT->url == "accounts/admin_edit/" || $ActionArr[5]->EDIT->url == "accounts/subadmin_edit/") {
631
+                   $ActionArr[5]->EDIT->url = $row['type'] == 4 ? "accounts/subadmin_edit/" : "accounts/admin_edit/";
632 632
                 }
633 633
                 $acctype = "";
634
-                if(isset($row["type"]) && ($row["type"] == '0' || $row["type"] == '1' || $row["type"] == '3')){
635
-                    $acctype = (isset($row["posttoexternal"]) && $row["posttoexternal"] != '')? "<span class='label label-default pull-right'>".$this->CI->common->get_account_type("","",$row["posttoexternal"])."</span>":"";
634
+                if (isset($row["type"]) && ($row["type"] == '0' || $row["type"] == '1' || $row["type"] == '3')) {
635
+                    $acctype = (isset($row["posttoexternal"]) && $row["posttoexternal"] != '') ? "<span class='label label-default pull-right'>".$this->CI->common->get_account_type("", "", $row["posttoexternal"])."</span>" : "";
636 636
                 }
637 637
 
638
-                $fieldstr = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
639
-                if($acctype != ''){
638
+                $fieldstr = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT, $row[$field_arr[2]], $row["id"]);
639
+                if ($acctype != '') {
640 640
                     $jsn_tmp[$field_key] = $fieldstr."<br/>".$acctype;
641
-                }else{
641
+                } else {
642 642
                     $jsn_tmp[$field_key] = $fieldstr;
643 643
                 }
644 644
 			    
645 645
 
646 646
 /*********************************/
647
-		      }else {
647
+		      } else {
648 648
                             $jsn_tmp[$field_key] = $row[$field_arr[2]];
649 649
                   }                  				
650 650
             } else {
651 651
                 if ($field_arr[0] == gettext("Action")) {
652
-			    if(isset($field_arr[5]) && isset($field_arr[5]->EDIT) && isset($field_arr[5]->DELETE)){
652
+			    if (isset($field_arr[5]) && isset($field_arr[5]->EDIT) && isset($field_arr[5]->DELETE)) {
653 653
 		             
654
-		              if($field_arr[5]->EDIT->url == 'accounts/customer_edit/' || $field_arr[5]->EDIT->url == 'accounts/provider_edit/' || $field_arr[5]->DELETE->url == 'accounts/provider_delete/' ||$field_arr[5]->DELETE->url == 'accounts/customer_delete/'){
655
-		               if( $row['type'] == '0'|| strtolower($row['type']) == 'customer'){
656
-		                $field_arr[5]->EDIT->url ='accounts/customer_edit/';
657
-		                $field_arr[5]->DELETE->url ='accounts/customer_delete/';
654
+		              if ($field_arr[5]->EDIT->url == 'accounts/customer_edit/' || $field_arr[5]->EDIT->url == 'accounts/provider_edit/' || $field_arr[5]->DELETE->url == 'accounts/provider_delete/' || $field_arr[5]->DELETE->url == 'accounts/customer_delete/') {
655
+		               if ($row['type'] == '0' || strtolower($row['type']) == 'customer') {
656
+		                $field_arr[5]->EDIT->url = 'accounts/customer_edit/';
657
+		                $field_arr[5]->DELETE->url = 'accounts/customer_delete/';
658 658
 		               }
659
-		               if($row['type'] == 3 || strtolower($row['type']) == 'provider'){
660
-		                $field_arr[5]->EDIT->url ='accounts/provider_edit/';
661
-		                $field_arr[5]->DELETE->url ='accounts/provider_delete/';
659
+		               if ($row['type'] == 3 || strtolower($row['type']) == 'provider') {
660
+		                $field_arr[5]->EDIT->url = 'accounts/provider_edit/';
661
+		                $field_arr[5]->DELETE->url = 'accounts/provider_delete/';
662 662
 		               }
663 663
 		              }
664
-		              if($field_arr[5]->EDIT->url == 'accounts/admin_edit/' || $field_arr[5]->EDIT->url == 'accounts/subadmin_edit/' || $field_arr[5]->DELETE->url == 'accounts/admin_delete/' ||$field_arr[5]->DELETE->url == 'accounts/subadmin_delete/'){
665
-		               if($row['type'] == 2 || strtolower($row['type']) == 'administrator'){
666
-		                $field_arr[5]->EDIT->url ='accounts/admin_edit/';
667
-		                $field_arr[5]->DELETE->url ='accounts/admin_delete/';
664
+		              if ($field_arr[5]->EDIT->url == 'accounts/admin_edit/' || $field_arr[5]->EDIT->url == 'accounts/subadmin_edit/' || $field_arr[5]->DELETE->url == 'accounts/admin_delete/' || $field_arr[5]->DELETE->url == 'accounts/subadmin_delete/') {
665
+		               if ($row['type'] == 2 || strtolower($row['type']) == 'administrator') {
666
+		                $field_arr[5]->EDIT->url = 'accounts/admin_edit/';
667
+		                $field_arr[5]->DELETE->url = 'accounts/admin_delete/';
668 668
 		               }
669
-		               if($row['type'] == 4 || strtolower($row['type']) == 'sub admin'){
670
-		                $field_arr[5]->EDIT->url ='accounts/subadmin_edit/';
671
-		                $field_arr[5]->DELETE->url ='accounts/subadmin_delete/';
669
+		               if ($row['type'] == 4 || strtolower($row['type']) == 'sub admin') {
670
+		                $field_arr[5]->EDIT->url = 'accounts/subadmin_edit/';
671
+		                $field_arr[5]->DELETE->url = 'accounts/subadmin_delete/';
672 672
 		               }
673 673
 		            }
674 674
 			   }
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
                             $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row_id);
680 680
                             /****************************************************************************/
681 681
                         }
682
-                        elseif($field_arr[0] == gettext("Profile Action"))
682
+                        elseif ($field_arr[0] == gettext("Profile Action"))
683 683
                         {
684
-                           if(isset($field_arr[5]) && isset($field_arr[5]->START) && isset($field_arr[5]->STOP) && isset($field_arr[5]->RELOAD) && isset($field_arr[5]->RESCAN)){
684
+                           if (isset($field_arr[5]) && isset($field_arr[5]->START) && isset($field_arr[5]->STOP) && isset($field_arr[5]->RELOAD) && isset($field_arr[5]->RESCAN)) {
685 685
                             }
686 686
                            $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
687 687
                         
688 688
                         }
689 689
                         else {
690
-                            $className = (isset($field_arr['9']) && $field_arr['9'] != '')?$field_arr['9']:"chkRefNos";
691
-                            $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace '.$className.'" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';                        }
690
+                            $className = (isset($field_arr['9']) && $field_arr['9'] != '') ? $field_arr['9'] : "chkRefNos";
691
+                            $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id='.$row['id'].' class="ace '.$className.'" onclick="clickchkbox('.$row['id'].')" value='.$row['id'].'><lable class="lbl"></lable>'; }
692 692
                     }
693 693
                 }
694 694
                 $json_data[] = array('cell' => $jsn_tmp);
@@ -702,20 +702,20 @@  discard block
 block discarded – undo
702 702
         $json_data = array();
703 703
         foreach ($query as $row) {
704 704
             foreach ($grid_fields as $field_key => $field_arr) {
705
-                $row_id = isset($row['id']) ? $row["id"]: '';
705
+                $row_id = isset($row['id']) ? $row["id"] : '';
706 706
 /**
707 707
 ASTPP  3.0 
708 708
 For Edit on Account number or name
709 709
 **/
710
-		$Actionkey = array_search('Action',$this->CI->common->array_column($grid_fields,0)); 
710
+		$Actionkey = array_search('Action', $this->CI->common->array_column($grid_fields, 0)); 
711 711
 /*******************************/
712 712
 
713 713
                 if ($field_arr[2] != "") {
714 714
                     if ($field_arr[3] != "") {
715
-                         if($field_arr[2]=="status"){
715
+                         if ($field_arr[2] == "status") {
716 716
                             $row['id'] = $row_id;
717 717
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
718
-						 }else{
718
+						 } else {
719 719
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
720 720
 						 }
721 721
 /**
@@ -723,17 +723,17 @@  discard block
 block discarded – undo
723 723
 For Edit on Account number or name
724 724
 **/
725 725
  			$row[$field_arr[2]] = $jsn_tmp[$field_key];
726
-                      } if(array_search("EDITABLE", $field_arr)){
726
+                      } if (array_search("EDITABLE", $field_arr)) {
727 727
 			    $ActionArr = $grid_fields[$Actionkey];
728
-                if($ActionArr[5]->EDIT->url =="accounts/customer_edit/" || $ActionArr[5]->EDIT->url =="accounts/provider_edit/"){
729
-                   $ActionArr[5]->EDIT->url=$row['type']==0 ?  "accounts/customer_edit/"  : "accounts/provider_edit/";
728
+                if ($ActionArr[5]->EDIT->url == "accounts/customer_edit/" || $ActionArr[5]->EDIT->url == "accounts/provider_edit/") {
729
+                   $ActionArr[5]->EDIT->url = $row['type'] == 0 ? "accounts/customer_edit/" : "accounts/provider_edit/";
730 730
                 }
731
-                if($ActionArr[5]->EDIT->url =="accounts/admin_edit/" || $ActionArr[5]->EDIT->url =="accounts/subadmin_edit/"){
732
-                   $ActionArr[5]->EDIT->url=$row['type']==4 ?  "accounts/subadmin_edit/"  : "accounts/admin_edit/";
731
+                if ($ActionArr[5]->EDIT->url == "accounts/admin_edit/" || $ActionArr[5]->EDIT->url == "accounts/subadmin_edit/") {
732
+                   $ActionArr[5]->EDIT->url = $row['type'] == 4 ? "accounts/subadmin_edit/" : "accounts/admin_edit/";
733 733
                 }
734
-			    $jsn_tmp[$field_key] = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
734
+			    $jsn_tmp[$field_key] = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT, $row[$field_arr[2]], $row["id"]);
735 735
 /*******************************/
736
-		    }else {
736
+		    } else {
737 737
                         $jsn_tmp[$field_key] = isset($row[$field_arr[2]]) ? $row[$field_arr[2]] : "";
738 738
                     }
739 739
                 } else {
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
                         $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
742 742
                     }
743 743
 		      else {
744
-                            $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace chkRefNos" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';
744
+                            $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id='.$row['id'].' class="ace chkRefNos" onclick="clickchkbox('.$row['id'].')" value='.$row['id'].'><lable class="lbl"></lable>';
745 745
                         }
746 746
                 }
747 747
             }
Please login to merge, or discard this patch.
Braces   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
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 29
  * Dynamically build forms for display
@@ -65,7 +66,7 @@  discard block
 block discarded – undo
65 66
             $file_name = explode("/", $url);
66 67
             if(isset($file_name['1']) ){
67 68
 	      $module = explode('_', $file_name['1']);
68
-            }else{
69
+            } else{
69 70
               $module=$file_name;
70 71
             }
71 72
             if($this->CI->session->userdata('userlevel_logintype')==1 ){
@@ -74,7 +75,7 @@  discard block
 block discarded – undo
74 75
             if (in_array($module[0], $module_info)) {
75 76
                 if($this->CI->session->userdata('userlevel_logintype')== 0 && $module[0] == 'customer' && isset($file_name[1]) && $file_name[1] !='customer_transfer'){
76 77
                      redirect(base_url() . 'user/user/');
77
-                }else{
78
+                } else{
78 79
                    return true;
79 80
                 }
80 81
             } else {
@@ -139,23 +140,23 @@  discard block
 block discarded – undo
139 140
             foreach ($form_fileds as $fieldkey => $fieldvalue) {
140 141
                 $form_contents.= '<li class="col-md-12">';
141 142
                 if ($fieldvalue[1] == 'HIDDEN') {
142
-                    if (isset($this->CI->input->post))
143
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
144
-                    else
145
-                        $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
143
+                    if (isset($this->CI->input->post)) {
144
+                                            $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
145
+                    } else {
146
+                                            $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
147
+                    }
146 148
                     $form_contents.= form_hidden($fieldvalue[2]['name'], $fieldvalue[2]['value']);
147
-                }else {
149
+                } else {
148 150
 		      $validation_arr=array();
149 151
 		      if($fieldvalue[1]=='INPUT'){
150 152
 		        if(!empty($fieldvalue[3])){
151 153
 		          $validation_arr=explode("|",$fieldvalue[3]);
152 154
 		        }
153
-		      }
154
-		      elseif($fieldvalue[2]=='SELECT'){
155
+		      } elseif($fieldvalue[2]=='SELECT'){
155 156
 
156 157
 		        if(is_array($fieldvalue[4])){
157 158
 		          $validation_arr=explode("|",$fieldvalue[4]['rules']);
158
-		        }else{
159
+		        } else{
159 160
 		        $validation_arr=explode("|",$fieldvalue[4]);
160 161
 		        }
161 162
 		      }
@@ -182,7 +183,7 @@  discard block
 block discarded – undo
182 183
 
183 184
                         if (isset($this->CI->input->post)){
184 185
                             $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
185
-                        }else{
186
+                        } else{
186 187
                             if (is_array($fieldvalue[1])) {
187 188
                                 $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]['name']] : @$fieldvalue[1];
188 189
                             } else {
@@ -201,16 +202,16 @@  discard block
 block discarded – undo
201 202
 								
202 203
 								if(isset($fieldvalue[1]['name'])){
203 204
 									$fieldvalue_pass=$fieldvalue[1]['name'];
204
-								}else{
205
+								} else{
205 206
 									$fieldvalue_pass=$fieldvalue[1];
206 207
 								}
207 208
 								
208 209
         				        $this->CI->form_validation->set_rules($fieldvalue_pass, $fieldvalue[0], $fieldvalue[4]['rules']);
209
-        				    }else{
210
+        				    } else{
210 211
 								
211 212
 								if(isset($fieldvalue[1]['name'])){
212 213
 									$fieldvalue_pass=$fieldvalue[1]['name'];
213
-								}else{
214
+								} else{
214 215
 									$fieldvalue_pass=$fieldvalue[1];
215 216
 								}
216 217
 								
@@ -246,10 +247,11 @@  discard block
 block discarded – undo
246 247
                     /* For multi select code */
247 248
                     $str = $fieldvalue[7] . "," . $fieldvalue[8];
248 249
 
249
-                    if (isset($this->CI->input->post))
250
-                        $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
251
-                    else
252
-                        $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
250
+                    if (isset($this->CI->input->post)) {
251
+                                            $fieldvalue['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[1] : $this->CI->input->post($fieldvalue[1]);
252
+                    } else {
253
+                                            $fieldvalue['value'] = ($values) ? @$values[$fieldvalue[1]] : @$fieldvalue[1];
254
+                    }
253 255
 
254 256
                     $drp_array = call_user_func_array(array($this->CI->db_model, $fieldvalue[10]), array($str, $fieldvalue[9], $fieldvalue[11], $fieldvalue[12]));
255 257
                     if ($fieldset_key === 'System Configuration Information') {
@@ -266,9 +268,9 @@  discard block
 block discarded – undo
266 268
                 } else if ($fieldvalue[1] == 'INPUT') {
267 269
 
268 270
 
269
-                    if (isset($this->CI->input->post))
270
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? $fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
271
-                    else{
271
+                    if (isset($this->CI->input->post)) {
272
+                                            $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? $fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
273
+                    } else{
272 274
                         $fieldvalue[2]['value'] = ($values) ? (isset($values[$fieldvalue[2]['name']]) ? $values[$fieldvalue[2]['name']] : ''):(isset($fieldvalue[2]['value']) ? $fieldvalue[2]['value'] :'');
273 275
                     }    
274 276
                     $form_contents.= form_input($fieldvalue[2], 'readonly');
@@ -284,11 +286,11 @@  discard block
 block discarded – undo
284 286
                  * Image upload from invoice configuration code.
285 287
                  */
286 288
                 else if ($fieldvalue[1] == 'IMAGE') {
287
-                    if (isset($this->CI->input->post))
288
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
289
-                       
290
-                    else
291
-                        $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
289
+                    if (isset($this->CI->input->post)) {
290
+                                            $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
291
+                    } else {
292
+                                            $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
293
+                    }
292 294
                         $fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
293 295
                     $form_contents.= form_image($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
294 296
                     	 $form_contents.=@$fieldvalue[6];
@@ -296,13 +298,12 @@  discard block
 block discarded – undo
296 298
                     $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
297 299
                     $form_contents.= '<span class="popup_error error  no-padding" id="'.$fieldvalue[2]['name'].'_error">
298 300
                     </span></div>';
299
-                }
300
-                else if ($fieldvalue[1] == 'DEL_BUTTON') {
301
-                    if (isset($this->CI->input->post))
302
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
303
-                       
304
-                    else
305
-                        $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
301
+                } else if ($fieldvalue[1] == 'DEL_BUTTON') {
302
+                    if (isset($this->CI->input->post)) {
303
+                                            $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
304
+                    } else {
305
+                                            $fieldvalue[2]['value'] = ($values) ? @$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
306
+                    }
306 307
                         $fieldvalue[2]['style'] = isset($fieldvalue[2]['style']) ? $fieldvalue[2]['style'] : "";
307 308
                     $form_contents.= form_img_delete($fieldvalue[2], 'readonly',$fieldvalue[2]['style']);
308 309
                     	 $form_contents.=@$fieldvalue[6];
@@ -313,10 +314,11 @@  discard block
 block discarded – undo
313 314
                 }
314 315
                 /**********************************************************************************/
315 316
                 else if ($fieldvalue[1] == 'PASSWORD') {
316
-                    if (isset($this->CI->input->post))
317
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
318
-                    else
319
-                        $fieldvalue[2]['value'] = ($values) ?@$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
317
+                    if (isset($this->CI->input->post)) {
318
+                                            $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
319
+                    } else {
320
+                                            $fieldvalue[2]['value'] = ($values) ?@$values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
321
+                    }
320 322
                     $form_contents.= form_password($fieldvalue[2]);
321 323
                     $this->CI->form_validation->set_rules($fieldvalue[2]['name'], $fieldvalue[0], $fieldvalue[3]);
322 324
                     $form_contents.= '<div class="tooltips error_div pull-left no-padding" id="'.$fieldvalue[2]['name'].'_error_div" ><i style="color:#D95C5C; padding-left: 3px; padding-top: 10px;" class="fa fa-exclamation-triangle"></i>';
@@ -325,12 +327,12 @@  discard block
 block discarded – undo
325 327
                 } else if ($fieldvalue[2] == 'CHECKBOX') {
326 328
                     $OptionArray = array();
327 329
 
328
-					if(isset($fieldvalue[7]) && $fieldvalue[7] != '')
329
-					$OptionArray = call_user_func_array(array($this->CI->common, $fieldvalue[7]), array($fieldvalue[6]));
330
+					if(isset($fieldvalue[7]) && $fieldvalue[7] != '') {
331
+										$OptionArray = call_user_func_array(array($this->CI->common, $fieldvalue[7]), array($fieldvalue[6]));
332
+					}
330 333
                     if (isset($this->CI->input->post)){
331 334
                         $fieldvalue[3]['value'] = (!$this->CI->input->post($fieldvalue[1])) ? @$fieldvalue[3]['value'] : $this->CI->input->post($fieldvalue[1]);
332
-                    }    
333
-                    else
335
+                    } else
334 336
                     {
335 337
                         $fieldvalue[3]['value'] = ($values) ? (isset($values[$fieldvalue[1]]) && $values[$fieldvalue[1]] ? 1: 0) : @$fieldvalue[3]['value'];
336 338
 					}
@@ -342,18 +344,18 @@  discard block
 block discarded – undo
342 344
                     if(isset($fieldvalue[3]['table_name']) && $fieldvalue[3]['table_name'] != ""){
343 345
 							
344 346
 						 $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'],$checked , $OptionArray);
345
-					}else{
347
+					} else{
346 348
 						 $form_contents.= form_checkbox($fieldvalue[1], $fieldvalue[3]['value'],$checked ,$OptionArray);
347 349
 					}
348 350
                 } else if ($fieldvalue[1] == 'TEXTAREA') {
349 351
 
350
-                    if (isset($this->CI->input->post))
351
-                        $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
352
-                    else
353
-                        $fieldvalue[2]['value'] = ($values) ? $values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
352
+                    if (isset($this->CI->input->post)) {
353
+                                            $fieldvalue[2]['value'] = (!$this->CI->input->post($fieldvalue[2]['name'])) ? @$fieldvalue[2]['value'] : $this->CI->input->post($fieldvalue[2]['name']);
354
+                    } else {
355
+                                            $fieldvalue[2]['value'] = ($values) ? $values[$fieldvalue[2]['name']] : @$fieldvalue[2]['value'];
356
+                    }
354 357
                     $form_contents.= form_textarea($fieldvalue[2]);
355
-                }
356
-                else if ($fieldvalue[2] == 'RADIO') {
358
+                } else if ($fieldvalue[2] == 'RADIO') {
357 359
 
358 360
                     $form_contents.= form_radio($fieldvalue[1], $fieldvalue[3]['value'], $fieldvalue[3]['checked']);
359 361
                 }
@@ -583,8 +585,9 @@  discard block
 block discarded – undo
583 585
         $json_data["json_paging"]['total'] = $config['total_rows'];
584 586
         $perpage = $config['per_page'];
585 587
         $start = ($page_no - 1) * $perpage;
586
-        if ($start < 0)
587
-            $start = 0;
588
+        if ($start < 0) {
589
+                    $start = 0;
590
+        }
588 591
         $json_data["paging"]['start'] = $start;
589 592
         $json_data["paging"]['page_no'] = $perpage;
590 593
         return $json_data;
@@ -613,7 +616,7 @@  discard block
 block discarded – undo
613 616
                            if($field_arr[2]=="status"){
614 617
                             $row['id'] = $row_id;
615 618
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
616
-			   }else{
619
+			   } else{
617 620
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
618 621
 			   }
619 622
 
@@ -638,13 +641,13 @@  discard block
 block discarded – undo
638 641
                 $fieldstr = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
639 642
                 if($acctype != ''){
640 643
                     $jsn_tmp[$field_key] = $fieldstr."<br/>".$acctype;
641
-                }else{
644
+                } else{
642 645
                     $jsn_tmp[$field_key] = $fieldstr;
643 646
                 }
644 647
 			    
645 648
 
646 649
 /*********************************/
647
-		      }else {
650
+		      } else {
648 651
                             $jsn_tmp[$field_key] = $row[$field_arr[2]];
649 652
                   }                  				
650 653
             } else {
@@ -678,15 +681,13 @@  discard block
 block discarded – undo
678 681
 */			   
679 682
                             $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row_id);
680 683
                             /****************************************************************************/
681
-                        }
682
-                        elseif($field_arr[0] == gettext("Profile Action"))
684
+                        } elseif($field_arr[0] == gettext("Profile Action"))
683 685
                         {
684 686
                            if(isset($field_arr[5]) && isset($field_arr[5]->START) && isset($field_arr[5]->STOP) && isset($field_arr[5]->RELOAD) && isset($field_arr[5]->RESCAN)){
685 687
                             }
686 688
                            $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
687 689
                         
688
-                        }
689
-                        else {
690
+                        } else {
690 691
                             $className = (isset($field_arr['9']) && $field_arr['9'] != '')?$field_arr['9']:"chkRefNos";
691 692
                             $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace '.$className.'" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';                        }
692 693
                     }
@@ -715,7 +716,7 @@  discard block
 block discarded – undo
715 716
                          if($field_arr[2]=="status"){
716 717
                             $row['id'] = $row_id;
717 718
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row));
718
-						 }else{
719
+						 } else{
719 720
                             $jsn_tmp[$field_key] = call_user_func_array(array($this->CI->common, $field_arr[5]), array($field_arr[3], $field_arr[4], $row[$field_arr[2]]));
720 721
 						 }
721 722
 /**
@@ -733,14 +734,13 @@  discard block
 block discarded – undo
733 734
                 }
734 735
 			    $jsn_tmp[$field_key] = $this->CI->common->build_custome_edit_button($ActionArr[5]->EDIT,$row[$field_arr[2]],$row["id"]);
735 736
 /*******************************/
736
-		    }else {
737
+		    } else {
737 738
                         $jsn_tmp[$field_key] = isset($row[$field_arr[2]]) ? $row[$field_arr[2]] : "";
738 739
                     }
739 740
                 } else {
740 741
                     if ($field_arr[0] == "Action") {
741 742
                         $jsn_tmp[$field_key] = $this->CI->common->get_action_buttons($field_arr[5], $row["id"]);
742
-                    }
743
-		      else {
743
+                    } else {
744 744
                             $jsn_tmp[$field_key] = '<input type="checkbox" name="chkAll" id=' . $row['id'] . ' class="ace chkRefNos" onclick="clickchkbox(' . $row['id'] . ')" value=' . $row['id'] . '><lable class="lbl"></lable>';
745 745
                         }
746 746
                 }
Please login to merge, or discard this patch.