Freeswitch::fssipprofile_action()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 5
nop 2
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
###############################################################################
4
# ASTPP - Open Source VoIP Billing Solution
5
#
6
# Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
7
# Samir Doshi <[email protected]>
8
# ASTPP Version 3.0 and above
9
# License https://www.gnu.org/licenses/agpl-3.0.html
10
#
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU Affero General Public License as
13
# published by the Free Software Foundation, either version 3 of the
14
# License, or (at your option) any later version.
15
# 
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
# GNU Affero General Public License for more details.
20
# 
21
# You should have received a copy of the GNU Affero General Public License
22
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
###############################################################################
24
25
class Freeswitch extends MX_Controller {
26
27 View Code Duplication
	function Freeswitch() {
28
		parent::__construct();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (__construct() instead of Freeswitch()). Are you sure this is correct? If so, you might want to change this to $this->__construct().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
29
30
		$this->load->helper('template_inheritance');
31
32
		$this->load->library('session');
33
		$this->load->library("freeswitch_form");
34
		$this->load->library('astpp/form');
35
		$this->load->library('freeswitch_lib');
36
		$this->load->model('freeswitch_model');
37
38
		if ($this->session->userdata('user_login') == FALSE)
39
			redirect(base_url() . '/astpp/login');
40
	}
41
42
	function fssipdevices_add($type = "") {
43
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
44
		 $account_data = $this->session->userdata("accountinfo");
45
		$data['flag'] = 'create';
46
		$data['page_title'] = 'Create SIP Device';
47
	   if($account_data['type'] == '-1'  || $account_data['type'] == '1')
48
	   {
49
			$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($type), '');
50
			$this->load->view('view_freeswitch_add_edit', $data);
51 View Code Duplication
		} else {
52
			$data['form'] = $this->form->build_form($this->freeswitch_form->get_freeswith_form_fields(), '');
53
			$this->load->view('view_freeswitch_customer_add_edit', $data);
54
		}        
55
	}
56
	function customer_fssipdevices_add($accountid) {
57
	 $data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
58
	 $account_data = $this->session->userdata("accountinfo");
59
		$data['page_title'] = 'Create SIP Device';
60
		$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($accountid),"");
61
		if($account_data['type'] == '-1'  || $account_data['type'] == '1')
62
		{
63
			$this->load->view('view_freeswitch_add_edit', $data);
64
		}else{
65
			$this->load->view('view_freeswitch_customer_add_edit', $data);
66
		}
67
	}
68
69
	function fssipdevices_edit($edit_id = '') {
70
		$data['page_title'] = 'Edit SIP Device';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
71
		$account_data = $this->session->userdata("accountinfo");
72
		$where = array('id' => $edit_id);
73
		$account = $this->freeswitch_model->get_edited_data($edit_id);
74
		if($account_data['type'] == '-1')
75
		{
76
			$data['form'] = $this->form->build_form($this->freeswitch_form->get_freeswith_form_fields($edit_id), $account);
77
			$this->load->view('view_freeswitch_add_edit', $data);
78 View Code Duplication
		}else{
79
		 $data['form'] = $this->form->build_form($this->freeswitch_form->get_freeswith_form_fields($edit_id), $account);
80
		$this->load->view('view_freeswitch_customer_add_edit', $data);
81
		}
82
	}
83
84
	function customer_fssipdevices_edit($edit_id, $accountid) {
85
	 $data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
86
	  $account_data = $this->session->userdata("accountinfo");
87
		$data['page_title'] = 'Edit SIP device';
88
		$where = array('id' => $edit_id);
89
		$account = $this->freeswitch_model->get_edited_data($edit_id);
90
		  if($account_data['type'] == '-1' || $account_data['type'] == '1')
91
		{
92
		$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($accountid,$edit_id), $account);
93
		$this->load->view('view_freeswitch_add_edit', $data);
94
		}else{
95
        
96
		$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($accountid,$edit_id), $account);
97
		$this->load->view('view_freeswitch_customer_add_edit', $data);
98
		}
99
	}
100
    
101 View Code Duplication
	function fsgateway_search() {
102
		$ajax_search = $this->input->post('ajax_search', 0);
103
        
104
		if ($this->input->post('advance_search', TRUE) == 1) {
105
			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
106
			$action = $this->input->post();
107
			unset($action['action']);
108
			unset($action['advance_search']);
109
			$this->session->set_userdata('fsgateway_list_search', $action);
110
		}
111
		if (@$ajax_search != 1) {
112
			redirect(base_url() . 'freeswitch/fsgateway/');
113
		}
114
	}
115 View Code Duplication
	function fssipprofile_search() {
116
		$ajax_search = $this->input->post('ajax_search', 0);
117
        
118
		if ($this->input->post('advance_search', TRUE) == 1) {
119
			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
120
			$action = $this->input->post();
121
			unset($action['action']);
122
			unset($action['advance_search']);
123
			$this->session->set_userdata('fssipprofile_list_search', $action);
124
		}
125
		if (@$ajax_search != 1) {
126
			redirect(base_url() . 'freeswitch/fssipprofile/');
127
		}
128
	}
129
	function fssipdevices_clearsearchfilter() {
130
		$this->session->set_userdata('advance_search', 0);
131
		$this->session->set_userdata('account_search', "");
132
	}
133
	function fsgateway_clearsearchfilter() {
134
		$this->session->set_userdata('advance_search', 0);
135
		$this->session->set_userdata('account_search', "");
136
	}
137
	function fssipprofile_clearsearchfilter() {
138
		$this->session->set_userdata('advance_search', 0);
139
		$this->session->set_userdata('account_search', "");
140
	}
141 View Code Duplication
	function fssipdevices_save($user_flg = false) {
142
		$add_array = $this->input->post();
143
		if (!$user_flg) {
144
			$data['form'] = $this->form->build_form($this->freeswitch_form->get_freeswith_form_fields($add_array['id']), $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
145
		} else {
146
			$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($add_array["accountcode"],$add_array['id']),  $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
147
		}
148
		if ($add_array['id'] != '') {
149
			$data['page_title'] = 'Freeswitch SIP Devices';
150
			if ($this->form_validation->run() == FALSE) {
151
				$data['validation_errors'] = validation_errors();
152
				echo $data['validation_errors'];
153
				exit;
154
			} else {
155
				$this->freeswitch_model->edit_freeswith($add_array, $add_array['id']);
156
				echo json_encode(array("SUCCESS"=> "SIP Device Updated Successfully!"));
157
				exit;
158
			}
159
		} else {
160
			$data['page_title'] = 'Create Freeswitch SIP Devices';
161
			if ($this->form_validation->run() == FALSE) {
162
				$data['validation_errors'] = validation_errors();
163
				echo $data['validation_errors'];
164
				exit;
165
			} else {
166
				$this->freeswitch_model->add_freeswith($add_array);
167
				echo json_encode(array("SUCCESS"=> "SIP Device Added Successfully!"));
168
				exit;
169
			}
170
		}
171
	}
172 View Code Duplication
	function customer_fssipdevices_save($user_flg = false) {
173
		$add_array = $this->input->post();      
174
		if (!$user_flg) {
175
			$data['form'] = $this->form->build_form($this->freeswitch_form->get_freeswith_form_fields(), $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
176
		} else {
177
			$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($add_array["accountcode"],$add_array['id']), $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
178
		}
179
		if ($add_array['id'] != '') {
180
			$data['page_title'] = 'Edit Freeswitch SIP Devices';
181
			if ($this->form_validation->run() == FALSE) {
182
				$data['validation_errors'] = validation_errors();
183
				echo $data['validation_errors'];
184
				exit;
185
			} else {
186
				$this->freeswitch_model->edit_freeswith($add_array, $add_array['id']);
187
				echo json_encode(array("SUCCESS"=> "SIP Device Updated Successfully!"));
188
				exit;
189
			}
190
		} else {
191
			$data['page_title'] = 'Create Freeswitch SIP Devices';
192
			if ($this->form_validation->run() == FALSE) {
193
				$data['validation_errors'] = validation_errors();
194
				echo $data['validation_errors'];
195
				exit;
196
			} else {
197
				$this->freeswitch_model->add_freeswith($add_array);
198
				echo json_encode(array("SUCCESS"=> "SIP Device Added Successfully!"));
199
				exit;
200
			}
201
		}
202
	}
203
	function user_fssipdevices_save($user_flg = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_flg is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
204
		$add_array = $this->input->post();
205
		$data['form'] = $this->form->build_form($this->freeswitch_form->fsdevice_form_fields_for_customer($add_array["accountcode"],$add_array['id']), $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
206
		if ($add_array['id'] != '') {
207
			$data['page_title'] = 'Edit Freeswitch SIP Devices';
208
			if ($this->form_validation->run() == FALSE) {
209
				$data['validation_errors'] = validation_errors();
210
				echo $data['validation_errors'];
211
				exit;
212
			} else {
213
				$this->freeswitch_model->edit_freeswith($add_array, $add_array['id']);
214
				echo json_encode(array("SUCCESS"=> "SIP Device Updated Successfully!"));
215
				exit;
216
			}
217
		}else{
218
			$data['page_title'] = 'Create Freeswitch SIP Devices';
219
			if ($this->form_validation->run() == FALSE) {
220
				$data['validation_errors'] = validation_errors();
221
				echo $data['validation_errors'];
222
				exit;
223
			} else {
224
		$sip_profile_id=$this->common->get_field_name('id','sip_profiles',array('name'=>'default'));
225
				$this->freeswitch_model->add_freeswith($add_array);
226
				echo json_encode(array("SUCCESS"=> "SIP Device Added Successfully!"));
227
				exit;
228
			}
229
		}
230
	}
231
232 View Code Duplication
	function fssipdevices_search() {
233
		$ajax_search = $this->input->post('ajax_search', 0);
234
		if ($this->input->post('advance_search', TRUE) == 1) {
235
			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
236
			$action = $this->input->post();
237
			unset($action['action']);
238
			unset($action['advance_search']);
239
			$this->session->set_userdata('fssipdevices_list_search', $action);
240
		}
241
		if (@$ajax_search != 1) {
242
			redirect(base_url() . 'freeswitch/fssipdevices/');
243
		}
244
	}
245
246
247 View Code Duplication
	function fssipdevices() {
248
		$data['page_title'] = 'SIP Devices';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
249
		$data['search_flag'] = true;
250
		$this->session->set_userdata('advance_search', 0);
251
		$data['grid_fields'] = $this->freeswitch_form->build_system_list_for_admin();
252
		$data["grid_buttons"] = $this->freeswitch_form->build_grid_buttons();
253
		$data['form_search'] = $this->form->build_serach_form($this->freeswitch_form->get_sipdevice_search_form());
254
		$this->load->view('view_freeswitch_sip_devices_list', $data);
255
	}
256
257
/******
258
ASTPP 3.0
259
Admin side show voicemail details
260
******/
261
	function fssipdevices_json() {
262
		$json_data = array();
263
		$count_all = $this->freeswitch_model->fs_retrieve_sip_user(false);
264
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
265
		$json_data = $paging_data["json_paging"];
266
		$query = $this->freeswitch_model->fs_retrieve_sip_user(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
267
		foreach ($query as $key => $value) {
268
	$path_true = base_url().'/assets/images/true.png';
269
	$path_false = base_url().'/assets/images/false.png';
270
	if($value['voicemail_enabled'] == 'true'){
271
		$voicemail_enabled ='<img src='.$path_true.' style="height:20px;width:20px;" title="Enable">';
272
	} else{
273
		$voicemail_enabled ='<img src='.$path_false.' style="height:20px;width:20px;" title="Disable">';
274
	}
275
		$json_data['rows'][] = array('cell' => array(
276
			'<input type="checkbox" name="chkAll" id=' . $value['id'] . ' class="ace chkRefNos" onclick="clickchkbox(' . $value['id'] . ')" value=' . $value['id'] . '><lable class="lbl"></lable>',
277
			"<a href='/freeswitch/fssipdevices_edit/".$value['id']."' style='cursor:pointer;color:#005298;' rel='facebox_medium' title='username'>".$value['username']."</a>",
278
/**************************/
279
					$value['password'],
280
					$this->common->get_field_name('name', '`sip_profiles', array('id' => $value['sip_profile_id'])),
281
					$this->common->get_field_name_coma_new('first_name,last_name,number', 'accounts', array('0' => $value['accountid'])),
282
					$value['effective_caller_id_name'],
283
					$value['effective_caller_id_number'],
284
					 $voicemail_enabled ,
285
					 $this->common->get_status('status', 'sip_devices',$value),
286
					$this->common->convert_GMT_to('','',$value['creation_date']),
287
					$this->common->convert_GMT_to('','',$value['last_modified_date']),                
288
					$this->get_action_buttons_fssipdevices($value['id'])
289
					));
290
		}
291
		echo json_encode($json_data);
292
	}
293 View Code Duplication
	function fssipdevices_delete_multiple() {
294
		$ids = $this->input->post("selected_ids", true);
295
		$where = "id IN ($ids)";
296
		$this->db->where($where);
297
		echo $this->db->delete("sip_devices");
298
	}
299
300 View Code Duplication
	function user_fssipdevices_delete_multiple() {
301
		$ids = $this->input->post("selected_ids", true);
302
		$where = "id IN ($ids)";
303
		$this->db->where($where);
304
		$this->db->delete("sip_devices");
305
		echo TRUE;
306
	}
307 View Code Duplication
	function customer_fssipdevices_delete_multiple(){
308
		$ids = $this->input->post("selected_ids", true);
309
		$where = "id IN ($ids)";
310
		$this->db->where($where);
311
		$this->db->delete("sip_devices");
312
		echo TRUE;
313
	}
314
315
/******
316
ASTPP 3.0
317
Customer side show voice mail detials
318
******/
319
	function customer_fssipdevices_json($accountid,$entity_type='') {
320
		$json_data = array();
321
		$count_all = $this->freeswitch_model->get_sipdevices_list(false, $accountid,$entity_type);
322
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
323
		$json_data = $paging_data["json_paging"];
324
		$devices_result = array();
325
		$query = $this->freeswitch_model->get_sipdevices_list(true, $accountid,$entity_type, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
326
		foreach ($query as $key => $value) {
327
	$path_true = base_url().'/assets/images/true.png';
328
	$path_false = base_url().'/assets/images/false.png';
329
	$voicemail_enabled = $value['voicemail_enabled'] == 'true'? '<img src='.$path_true.' style="height:20px;width:20px;" title="Enable">' : '<img src='.$path_false.' style="height:20px;width:20px;" title="Disable">';
330
		$json_data['rows'][] = array('cell' => array(
331
			'<input type="checkbox" name="chkAll" id="'.$value['id'].'" class="ace chkRefNos" onclick="clickchkbox('.$value['id'].')" value=' .$value['id'].'><lable class="lbl"></lable>',
332
					$value['username'],
333
					$value['password'],
334
					$this->common->get_field_name('name', '`sip_profiles', array('id' => $value['sip_profile_id'])),
335
					$value['effective_caller_id_name'],
336
					$value['effective_caller_id_number'],
337
					$voicemail_enabled,
338
					$this->common->get_status('status', 'sip_devices',$value),
339
					$this->common->convert_GMT_to('','',$value['creation_date']),
340
					$this->common->convert_GMT_to('','',$value['last_modified_date']),
341
					$this->get_action_fssipdevices_buttons($value['id'], $value['accountid'],$entity_type)
342
					));
343
		}//exit;
344
		echo json_encode($json_data);
345
	}
346
/****************************/
347
	function get_action_fssipdevices_buttons($id, $accountid,$entity_type='') {
348
		$ret_url = '';
349
		if ($this->session->userdata("logintype") == '0'||$this->session->userdata("logintype") == '3') {
350
			$ret_url = '<a href="'. base_url() .'user/user_fssipdevices_action/edit/' . $id . '/' . $accountid . '/" class="btn btn-royelblue btn-sm"  rel="facebox_medium" title="Edit">&nbsp;<i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
351
			$ret_url .= '<a href="'. base_url() .'user/user_fssipdevices_action/delete/' . $id . '/' . $accountid . '/" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();">&nbsp;<i class="fa fa-trash fa-fw"></i></a>';
352
		} else {
353
			$ret_url = '<a href="'. base_url() .'accounts/'.$entity_type.'_fssipdevices_action/edit/' . $id . '/' . $accountid . '/" class="btn btn-royelblue btn-sm"  rel="facebox_medium" title="Edit">&nbsp;<i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
354
			$ret_url .= '<a href="'. base_url() .'accounts/'.$entity_type.'_fssipdevices_action/delete/' . $id . '/' . $accountid . '/" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();">&nbsp;<i class="fa fa-trash fa-fw"></i></a>';
355
		}
356
		return $ret_url;
357
	}
358
359 View Code Duplication
	function fssipdevices_delete($id) {
360
		$this->freeswitch_model->delete_freeswith_devices($id);
361
		$this->session->set_flashdata('astpp_notification', 'SIP Device Removed Successfully!');
362
		redirect(base_url() . 'freeswitch/fssipdevices/');
363
		exit;
364
	}
365
366
	function get_action_buttons_fssipdevices($id) {
367
368
		$ret_url = '';
369
		$ret_url = '<a href="'. base_url() .'freeswitch/fssipdevices_edit/' . $id . '/" class="btn btn-royelblue btn-sm"  rel="facebox_medium" title="Edit">&nbsp;<i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;';
370
		$ret_url .= '<a href="'. base_url() .'freeswitch/fssipdevices_delete/' . $id . '/" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();">&nbsp;<i class="fa fa-trash fa-fw"></i></a>';
371
		return $ret_url;
372
	}
373
374
	function livecall_report() {
375
376
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
377
		$data['page_title'] = 'Live Call Report';
378
		$this->load->view('view_fs_livecall_report', $data);
379
	}
380
381
	function livecall_report_json() {
382
		$command = "api show channels";
383
		$response = $this->freeswitch_model->reload_live_freeswitch($command);
384
		$calls = array();
385
		$calls_final = array();
386
		$data_header = array();
387
		$k = 0;
388
			$data = explode("\n",$response);
389
			for ($i = 0; $i < count($data) - 2; $i++) {
390
				if (trim($data[$i]) != '') {
391
					if (count($data_header) ==0 || substr($data[$i],0,4) == "uuid") {
392
						$data_header = explode(",", $data[$i]);
393
					} else {
394
						$data_call = explode(",", $data[$i]);
395
						for ($j = 0; $j < count($data_call); $j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
396
							$calls[$k][@$data_header[$j]] = @$data_call[$j];
397
							$calls_final[@$calls[$k]['uuid']] = @$calls[$k];
398
						}
399
						$k++;
400
					}
401
				}
402
			}
403
		$json_data = array();
404
		$count = 0;
405
		foreach ($calls as $key => $value) {
406
			if (isset($value['state']) && $value['state'] == 'CS_EXCHANGE_MEDIA') {
407
				$calls[$i]['application'] = $calls_final[$value['call_uuid']]['application'];
408
				$calls[$i]['application_data'] = $calls_final[$value['call_uuid']]['application_data'];
409
				$json_data['rows'][] = array('cell' => array(
410
						$value['created'],
411
						$value['cid_name'],
412
						$value['cid_num'],
413
						$value['ip_addr'],
414
						$value['dest'],
415
						$calls[$i]['application_data'],
416
						$value['read_codec'],
417
						$value['write_codec'],
418
						$value['callstate'],
419
						date("H:i:s", strtotime(date("Y-m-d H:i:s")) - $value['created_epoch'])
420
						));
421
				$count++;
422
			} else {
423
				unset($calls[$i]);
424
			}
425
		}
426
	$json_data['page'] = 1;
427
		$json_data['total'] = $count;
428
		echo json_encode($json_data);
429
	}
430
431 View Code Duplication
	function fsgateway() {
432
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
433
		$data['page_title'] = 'Gateways';
434
	$data['search_flag'] = true;
435
		$this->session->set_userdata('advance_search', 0);
436
		$data['grid_fields'] = $this->freeswitch_form->build_fsgateway_list_for_admin();
437
		$data["grid_buttons"] = $this->freeswitch_form->build_fdgateway_grid_buttons();
438
	  	$data['form_search']=$this->form->build_serach_form($this->freeswitch_form->get_gateway_search_form());
439
		$this->load->view('view_fsgateway_list', $data);
440
	}
441
442
	function fsgateway_json() {
443
			   $json_data = array();
444
445
		$count_all = $this->freeswitch_model->get_gateway_list(false);
446
447
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
448
		$json_data = $paging_data["json_paging"];
449
		$gateway_data = array();
450
		$query = $this->freeswitch_model->get_gateway_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
451
		$gateway_result = array();
452
		if ($query->num_rows > 0) {
453
			$query = $query->result_array();
454
			foreach ($query as $key => $query_value) {
455
$gateway_data=array();
456
$tmp=null;
457
				foreach ($query_value as $gateway_key => $gateway_val) {
458
					if ($gateway_key != "gateway_data") {
459
						$gateway_data[$gateway_key] = $gateway_val;
460
					} else {
461
						$tmp = (array) json_decode($gateway_val);
462
					}
463
				}
464
						$gateway_result[$key] = array_merge($gateway_data, $tmp);
465
			}
466
		}
467
468
		$grid_fields = json_decode($this->freeswitch_form->build_fsgateway_list_for_admin());
469
		$json_data['rows'] = $this->form->build_json_grid($gateway_result, $grid_fields);
470
		echo json_encode($json_data);
471
	}
472
473 View Code Duplication
	function fsgateway_add() {
474
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
475
		$data['flag'] = 'create';
476
		$data['page_title'] = 'Create Gateway';
477
		$data['form'] = $this->form->build_form($this->freeswitch_form->get_gateway_form_fields(), '');
478
		$this->load->view('view_fsgateway_add', $data);
479
	}
480
481
	function fsgateway_edit($edit_id = '') {
482
		$data['page_title'] = ' Edit Gateway';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
483
		$where = array('id' => $edit_id);
484
		$query = $this->db_model->getSelect("*", "gateways", $where);
485
		$query = $query->result_array();
486
		$gateway_result = array();
487
		foreach ($query as $key => $query_value) {
488
			foreach ($query_value as $gateway_key => $gatewau_val) {
489
  			$gateway_data["status"] = isset($query_value["status"])?$query_value["status"]:"";
0 ignored issues
show
Coding Style Comprehensibility introduced by
$gateway_data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $gateway_data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
490
				if ($gateway_key != "gateway_data") {
491
					$gateway_data[$gateway_key] = $gatewau_val;
0 ignored issues
show
Bug introduced by
The variable $gateway_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
492
				}else if($gateway_key == "status") {
493
					$gateway_data[$gateway_key] = $gatewau_val;
494
				} 
495
				 /**
496
                 ASTPP 3.0 
497
                 put one variable with the name of dialplan variable 
498
				  **/ 
499
				else if($gateway_key == "dialplan_variable") {
500
					$gateway_data[$gateway_key] = $gatewau_val;
501
				} 
502
				/****************************************************/
503
				else {
504
					$tmp = (array) json_decode($gatewau_val);
505
					$gateway_result = array_merge($gateway_data, $tmp);
506
				}
507
			}
508
		}
509
		/**
510
        ASTPP  3.0 
511
        put one variable with the name of dialplan variable 
512
		 **/
513
		if(!empty($gateway_data['dialplan_variable']) && $gateway_data['dialplan_variable'] != ''){
514
		 $gateway_result['dialplan_variable']  = $gateway_data['dialplan_variable'];
515
		 }else{
516
		 $gateway_result['dialplan_variable'] = '';
517
		 }
518
		 /**********************************************************************************************/
519
		$data['form'] = $this->form->build_form($this->freeswitch_form->get_gateway_form_fields(), $gateway_result);
520
		$this->load->view('view_fsgateway_add', $data);
521
	}
522
523
	function fsgateway_save() {
524
		$gateway_data = $this->input->post();
525
		$data['form'] = $this->form->build_form($this->freeswitch_form->get_gateway_form_fields(), $gateway_data);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
526
		$insert_arr = array();
527
		$gateway_arr = array();
528
		$insert_arr['dialplan_variable'] ="";
529
		foreach ($gateway_data as $key => $gateway_value) {
530
			if ($gateway_value != "") {
531
				if ($key == "sip_profile_id") {
532
					$insert_arr['sip_profile_id'] = $gateway_data["sip_profile_id"];
533
				} else if ($key == "name") {
534
					$insert_arr['name'] = $gateway_data["name"];
535
				} else if ($key == "sip_profile_id") {
536
					$insert_arr['sip_profile_id'] = $gateway_data["sip_profile_id"];
537
				}
538
				/**
539
                ASTPP  3.0 
540
                put one variable with the name of dialplan variable 
541
				 **/ 
542
				else if ($key == "dialplan_variable") {
543
					$insert_arr['dialplan_variable'] = $gateway_data["dialplan_variable"];
544
				}
545
				/*********************************************************************/
546
				else if($key == "status") {
547
					$insert_arr[$key] = $gateway_data["status"];
548
				}  else {
549
					if ($key != "id") {
550
						$gateway_arr[$key] = $gateway_value;
551
					}
552
				}
553
			}
554
		}
555
556
		$insert_arr["gateway_data"] = json_encode($gateway_arr);
557
558
		if ($gateway_data['id'] != '') {
559
			$data['page_title'] = 'Edit Gateway Details';
560
			if ($this->form_validation->run() == FALSE) {
561
				$data['validation_errors'] = validation_errors();
562
				echo $data['validation_errors'];
563
				exit;
564
			} else {
565
		if ( preg_match('/\s/',$insert_arr['name']) )
566
		{
567
		  echo json_encode(array("name_error"=> "Gateway name must not have any space."));
568
		  exit;
569
		}
570
		/*
571
		ASTPP  3.0 
572
		gateway last modified date
573
		*/
574
		$insert_arr['last_modified_date']=gmdate('Y-m-d H:i:s');
575
		/*************************************************/
576
				$update = $this->db->update("gateways", $insert_arr, array('id' => $gateway_data['id']));
577
				if ($update) {
578
					$profile_name = $this->common->get_field_name('name', 'sip_profiles', $insert_arr['sip_profile_id']);
579
			$sip_ip = $this->common->get_field_name('sip_ip', 'sip_profiles', $insert_arr['sip_profile_id']);
580
					$cmd = "api sofia profile ".$profile_name." killgw '".$insert_arr['name']."' ";
581
					$this->freeswitch_model->reload_freeswitch($cmd,$sip_ip);
582
583
					$cmd2 = "api sofia profile " . $profile_name . " rescan reloadacl reloadxml";
584
					$this->freeswitch_model->reload_freeswitch($cmd2,$sip_ip);
585
				}
586
				echo json_encode(array("SUCCESS"=> $insert_arr['name']." Gateway Updated Successfully!"));
587
				exit;
588
			}
589
		} else {
590
			$data['page_title'] = 'Create Gateway Details';
591
			if ($this->form_validation->run() == FALSE) {
592
				$data['validation_errors'] = validation_errors();
593
				echo $data['validation_errors'];
594
				exit;
595
			} else {
596
		if ( preg_match('/\s/',$insert_arr['name']) )
597
		{
598
		  echo json_encode(array("name_error"=> "Gateway name must not have any space."));
599
		  exit;
600
		}
601
			$insert_arr['created_date']=gmdate('Y-m-d H:i:s'); 
602
				$insert = $this->db->insert("gateways", $insert_arr);
603
				if ($insert) {
604
					$profile_name = $this->common->get_field_name('name', 'sip_profiles', $insert_arr['sip_profile_id']);
605
			$sip_ip = $this->common->get_field_name('sip_ip', 'sip_profiles', $insert_arr['sip_profile_id']);
606
					$cmd = "api sofia profile " . $profile_name . " rescan reloadacl reloadxml";
607
					$this->freeswitch_model->reload_freeswitch($cmd,$sip_ip);
608
				}
609
				echo json_encode(array("SUCCESS"=> $insert_arr['name']." Gateway Added Successfully!"));
610
				exit;
611
			}
612
		}
613
	}
614
615
	function fsgateway_delete($gateway_id) {
616
		$delete = $this->db_model->delete("gateways", array("id" => $gateway_id));
617
		if ($delete) {
618
			$profile_id = $this->common->get_field_name('sip_profile_id', 'gateways', $gateway_id);
619
			$profile_name = $this->common->get_field_name('name', 'sip_profiles', $profile_id);
620
		$sip_ip = $this->common->get_field_name('sip_ip', 'sip_profiles', $profile_id);
621
			$gateway_name = $this->common->get_field_name('name', 'gateways', $gateway_id);
622
			$cmd = "api sofia profile " . $profile_name . " killgw " . $gateway_name . " reloadxml";
623
			$this->freeswitch_model->reload_freeswitch($cmd,$sip_ip);
624
		}
625
626
		$this->session->set_flashdata('astpp_notification', 'Gateway Removed Successfully!');
627
		redirect(base_url() . 'freeswitch/fsgateway/');
628
	}
629
630
	function fsgateway_delete_multiple() {
631
		$ids = $this->input->post("selected_ids", true);
632
		$where = "id IN ($ids)";
633
		$this->db->where($where);
634
		echo $this->db->delete("gateways");
635
	}
636
637
	function fssipprofile() {
638
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
639
		$data['page_title'] = 'SIP Profile';
640
	$data['search_flag'] = true;
641
		$this->session->set_userdata('advance_search', 0);
642
		$data['grid_fields'] = $this->freeswitch_form->build_fssipprofile_list_for_admin();
643
		$data["grid_buttons"] = $this->freeswitch_form->build_fssipprofile_grid_buttons();
644
	$data['form_search']=$this->form->build_serach_form($this->freeswitch_form->get_sipprofile_search_form());
645
	$data['button_name']="Add Setting";
646
	//$data['form_search'] = $this->form->build_serach_form($this->trunk_form->get_trunk_search_form());
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
647
		$this->load->view('view_fssipprofile_list', $data);
648
	}
649
650
	function fssipprofile_delete_multiple() {
651
		$ids = $this->input->post("selected_ids", true);
652
		$where = "id IN ($ids)";
653
		$this->db->where($where);
654
		echo $this->db->delete("sip_profiles");
655
	}
656
657
	function fssipprofile_json() {
658
		$json_data = array();
659
		$count_all = $this->freeswitch_model->get_sipprofile_list(false);
660
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
661
		$json_data = $paging_data["json_paging"];
662
		$gateway_data = array();
663
		$query = $this->freeswitch_model->get_sipprofile_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
664
		$grid_fields = json_decode($this->freeswitch_form->build_fssipprofile_list_for_admin());
665
		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
666
667
		echo json_encode($json_data);
668
	}
669
	function fssipprofile_params_json($edited_id)
670
	{
671
	$json_data = array();
672
		$gateway_data = array();
673
	$where = array('id' => $edited_id);
674
		$query = $this->db_model->getSelect("*", "sip_profiles", $where);
675
		$query = $query->result_array();
676
		$gateway_result = array();
677
		$i=0;
678
		foreach ($query as $key => $query_value) {
679
			foreach ($query_value as $gateway_key => $gatewau_val) {
680
		  if($gateway_key != 'id' && $gateway_key != 'name' && $gateway_key != 'sip_ip' && $gateway_key != 'sip_port'){
681
				if ($gateway_key != "profile_data") {
682
					$gateway_data[$gateway_key] = $gatewau_val;
683
				} else {
684
					$tmp = (array) json_decode($gatewau_val);
685
					$gateway_result = array_merge($gateway_data, $tmp);
686
				}
687
	}
688
	  }
689
	}
690
		 $paging_data = $this->form->load_grid_config(count($gateway_result), $_GET['rp'], $_GET['page']);
691
		 $json_data = $paging_data["json_paging"];
692
    
693
	  foreach ($gateway_result as $key => $value) {
694
	  $json_data['rows'][] = array('cell' => array(
695
		  $key,
696
		  $value,
697
		  array('<a href="/freeswitch/fssipprofile_edit/'.$edited_id.'/edit/' . $key .'/" class="btn btn-royelblue btn-sm"  title="Edit">&nbsp;<i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;<a href="/freeswitch/fssipprofile_delete_params/'.$edited_id.'/' . $key .'/" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();">&nbsp;<i class="fa fa-trash fa-fw"></i></a>')
698
		  ));
699
  }
700
		echo json_encode($json_data);
701
	}
702
	 function fssipprofile_action($button_name,$id) {
703
		$where = array('id' => $id);
704
		$query = $this->db_model->getSelect("*", "sip_profiles", $where);
705
		$query = $query->result_array();
706
		$where = array('sip_profile_id' => $id);
707
		if($button_name == "start")
708
		{ 
709
		   $cmd = "api sofia profile " . trim($query[0]['name']) ." start"; 
710
		}
711
		elseif($button_name == "stop")
712
		{
713
			$cmd= "api sofia profile stop";
714
		}
715
		elseif($button_name == "reload")
716
		{
717
			$cmd = "api reloadxml";
718
		}
719
		elseif($button_name == "rescan")
720
		{
721
			$cmd = "api sofia profile " . trim($query[0]['name']) . " rescan";
722
		}
723
        
724
		$this->freeswitch_model->reload_freeswitch($cmd);
0 ignored issues
show
Bug introduced by
The variable $cmd does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
725
	redirect(base_url() . 'freeswitch/fssipprofile/');   
726
	}
727
	 function fssipprofile_add($add='') {
728
     
729
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
730
		$data['flag'] = 'create';
731
		$data['page_title'] = 'Create SIP Profile';
732
		$sipprofile_data = $this->input->post();
733
		 $sipprofile_data['status']=$sipprofile_data['sipstatus'];
734
		$data['button_name']="Add Setting";
735
		if($add == 'add')
736
		{
737
          
738
	  unset($sipprofile_data['action']);
739
	   unset($sipprofile_data['sipstatus']);
740
	  $insert_data=$sipprofile_data;
741
	  
742 View Code Duplication
	  if($sipprofile_data['name'] == '' || $sipprofile_data['sip_ip'] =='' || $sipprofile_data['sip_port'] =='')
743
	  {
744
		  $this->session->set_flashdata('astpp_notification', 'Please enter All profile value!');
745
		  redirect(base_url() . 'freeswitch/fssipprofile_add/');
746
		  exit;
747
	  }
748 View Code Duplication
	  if(preg_match('/\s/',$sipprofile_data['name']))
749
	  {
750
		$this->session->set_flashdata('astpp_notification', 'SIP Profile name must not have any space!');
751
 		redirect(base_url() . 'freeswitch/fssipprofile_add/');
752
 		exit;
753
	  }
754 View Code Duplication
	  if(!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $sipprofile_data['sip_ip']))
755
	  {
756
		$this->session->set_flashdata('astpp_notification', 'SIP IP must be proper!');
757
 		redirect(base_url() . 'freeswitch/fssipprofile_add/');
758
 		exit;
759
	  }
760
	  $sipprofile_data['id']='';
761
	  $check_authentication = $this->freeswitch_model->profile_authentication($sipprofile_data);
762
	  if ($check_authentication->num_rows == 0) {
763
	      
764
		  $sipprofile_data['created_date']=gmdate('Y-m-d H:i:s');
765
		 /** Version 2.1
766
		  * Purpose : Set default data for new created profile
767
		  **/
768
 		  $sipprofile_data['profile_data'] = $this->common->sip_profile_date();
769
		  /**====================================================================*/
770
		  $insert = $this->db->insert("sip_profiles", $sipprofile_data);
771
772
		}
773
		else {
774
					$this->session->set_flashdata('astpp_notification', 'Duplicate SIP IP OR Port found it must be unique!');
775
			redirect(base_url() . 'freeswitch/fssipprofile_add/');
776
		}
777
		$this->session->set_flashdata('astpp_errormsg', 'SIP Profile Added Successfully!');
778
		redirect(base_url() . 'freeswitch/fssipprofile/');
779
		}
780
	
781
		if($add == 'edit')
782
		{
783
	  $check_authentication = $this->freeswitch_model->profile_authentication($sipprofile_data);
784
		unset($sipprofile_data['action']);
785
		unset($sipprofile_data['sipstatus']);
786
		$insert_arr = $sipprofile_data;
787
			if ($check_authentication->num_rows == 0) {
788
			$insert_arr['last_modified_date']=gmdate("Y-m-d H:i:s");
789
					$update = $this->db->update("sip_profiles", $insert_arr, array('id' => $sipprofile_data['id']));
790
					$this->session->set_flashdata('astpp_errormsg', $sipprofile_data['name']." SIP Profile Updated Successfully!");
791
					redirect(base_url() . 'freeswitch/fssipprofile/');   
792
					exit;
793
				} else {
794
					$this->session->set_flashdata('astpp_notification', 'Duplicate SIP IP OR Port found it must be unique!');
795
			redirect(base_url() . 'freeswitch/fssipprofile/');
796
				}
797
	  redirect(base_url() . 'freeswitch/fssipprofile/');   
798
		}
799
		$this->load->view('view_fssipprofile_add', $data);
800
	}
801
802
803
	function fssipprofile_edit($edit_id = '',$type='',$name_prams='') {
804
		$data['page_title'] = 'Edit SIP Profile';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
805
		  $sipprofile_data = $this->input->post();
806
		if(!$edit_id)
807
		{
808
	  $edit_id=$sipprofile_data['id'];
809
		}
810
		$where = array('id' => $edit_id);
811
		$query = $this->db_model->getSelect("*", "sip_profiles", $where);
812
		$query = $query->result_array();
813
		$gateway_result = array();
814 View Code Duplication
		foreach ($query as $key => $query_value) {
815
			foreach ($query_value as $gateway_key => $gatewau_val) {
816
				if ($gateway_key != "profile_data") {
817
					$gateway_data[$gateway_key] = $gatewau_val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$gateway_data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $gateway_data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
818
				} else {
819
					$tmp = (array) json_decode($gatewau_val);
820
					$gateway_result = array_merge($gateway_data, $tmp);
0 ignored issues
show
Bug introduced by
The variable $gateway_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
821
				}
822
			}
823
		}
824
		$data['grid_fields'] = $this->freeswitch_form->build_fssipprofile_params_list_for_admin();
825
		$data['edited_id'] = $edit_id;
826
		$data['sip_name']=$query[0]['name'];
827
	$data['status']=$query[0]['status'];
828
	$data['sip_ip']= $query[0]['sip_ip'];
829
	$data['sip_port']=$query[0]['sip_port'];
830
	$data['id']=$query[0]['id'];
831
		$data['button_name']="Add Setting";
832
		if($type == 'edit' || isset($sipprofile_data['type']) && $sipprofile_data['type'] == 'save')
833
		{
834
		if($type == 'edit')
835
		{
836
		$data['params_name']=$name_prams;
837
		$data['params_status']=0;
838
		if($gateway_result[$name_prams] == "true" || $gateway_result[$name_prams] == "false")
839
		{
840
		  $data['params_status']=1;
841
		}
842
		$data['params_value']=$gateway_result[$name_prams];
843
		$data['button_name']="Update Setting";
844
		}
845
		if(isset($sipprofile_data['type']) && $sipprofile_data['type'] == 'save'){
846
		$sipprofile_data = $this->input->post();
847
		$tmp[$sipprofile_data['params_name']]=$sipprofile_data['params_value'];
0 ignored issues
show
Bug introduced by
The variable $tmp does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
848
		  $final_data= json_encode($tmp);
849
		  $insert_arr["profile_data"] = json_encode($tmp);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$insert_arr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $insert_arr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
850
		  $update = $this->db->update("sip_profiles", $insert_arr, array('id' => $edit_id));
851
		   if($sipprofile_data['type_settings']=="add_setting"){
852
			$this->session->set_flashdata('astpp_errormsg',$data['sip_name']. " SIP Setting Added Successfully!");
853
				  }else{
854
			$this->session->set_flashdata('astpp_errormsg',$data['sip_name']. " SIP Setting Updated Successfully!");
855
		    
856
				  }
857
				  redirect(base_url() . 'freeswitch/fssipprofile_edit/'.$sipprofile_data['id']);
858
		  exit;
859
860
		}
861
		}
862
		$this->load->view('view_fssipprofile_edit', $data);
863
	}
864
865
   function fssipprofile_save($id) {
866
	$sipprofile_data = $this->input->post();
867
	$insert_arr = array();
868
		$sipprofile_arr = array();
869
	$where = array('id' => $id);
870
		$query = $this->db_model->getSelect("*", "sip_profiles", $where);
871
		$query = $query->result_array();
872
		$gateway_result = array();
873 View Code Duplication
		foreach ($query as $key => $query_value) {
874
			foreach ($query_value as $gateway_key => $gatewau_val) {
875
				if ($gateway_key != "profile_data") {
876
					$gateway_data[$gateway_key] = $gatewau_val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$gateway_data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $gateway_data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
877
				} else {
878
					$tmp = (array) json_decode($gatewau_val);
879
					$gateway_result = array_merge($gateway_data, $tmp);
0 ignored issues
show
Bug introduced by
The variable $gateway_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
880
				}
881
			}
882
		}
883
		$tmp[$sipprofile_data['params_name']]=$sipprofile_data['params_value'];
0 ignored issues
show
Bug introduced by
The variable $tmp does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
884
	$final_data= json_encode($tmp);
885
	$insert_arr["profile_data"] = json_encode($tmp);
886
	$update = $this->db->update("sip_profiles", $insert_arr, array('id' => $id));
887
	$this->load->view('view_fssipprofile_edit', $data);
0 ignored issues
show
Bug introduced by
The variable $data does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
888
	}
889
    
890
	function fssipprofile_delete_params($id,$name) {
891
	$where = array('id' => $id);
892
		$query = $this->db_model->getSelect("*", "sip_profiles", $where);
893
		$query = $query->result_array();
894
		$gateway_result = array();
895 View Code Duplication
		foreach ($query as $key => $query_value) {
896
			foreach ($query_value as $gateway_key => $gatewau_val) {
897
				if ($gateway_key != "profile_data") {
898
					$gateway_data[$gateway_key] = $gatewau_val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$gateway_data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $gateway_data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
899
				} else {
900
					$tmp = (array) json_decode($gatewau_val);
901
					$gateway_result = array_merge($gateway_data, $tmp);
0 ignored issues
show
Bug introduced by
The variable $gateway_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
902
				}
903
			}
904
		}
905
	if(isset($tmp[$name])){
906
	  unset($tmp[$name]);
907
	}
908
	$insert_arr["profile_data"] = json_encode($tmp);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$insert_arr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $insert_arr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $tmp does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
909
	$update = $this->db->update("sip_profiles", $insert_arr, array('id' => $id));
910
		$this->session->set_flashdata('astpp_notification', $name.' SIP Setting Removed Successfully!');
911
		redirect(base_url() . 'freeswitch/fssipprofile_edit/'.$id);
912
	}
913
    
914
	function fssipprofile_delete($profile_id) {
915
	$profile_name = $this->common->get_field_name('name', 'sip_profiles', $profile_id);
916
		$sip_ip = $this->common->get_field_name('sip_ip', 'sip_profiles', $profile_id);
917
	$delete = $this->db_model->delete("sip_profiles", array("id" => $profile_id));
918
		$this->session->set_flashdata('astpp_notification', 'SIP Profile Removed Successfully!');
919
		redirect(base_url() . 'freeswitch/fssipprofile/');
920
	}
921
922
	function fsserver_list() {
923
924
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
925
		$data['page_title'] = 'Freeswitch Servers';
926
		$data['search_flag'] = true;
927
		$data['cur_menu_no'] = 1;
928
		$this->session->set_userdata('advance_search', 0);
929
		$data['grid_fields'] = $this->freeswitch_form->build_fsserver_list();
930
		$data["grid_buttons"] = $this->freeswitch_form->build_fsserver_grid_buttons();
931
932
		$data['form_search'] = $this->form->build_serach_form($this->freeswitch_form->get_search_fsserver_form());
933
		$this->load->view('view_fsserver_list', $data);
934
	}
935
936
	/**
937
	 * -------Here we write code for controller accounts functions account_list------
938
	 * Listing of Accounts table data through php function json_encode
939
	 */
940
	function fsserver_list_json() {
941
		$json_data = array();
942
943
		$count_all = $this->freeswitch_model->get_fsserver_list(false);
944
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
945
		$json_data = $paging_data["json_paging"];
946
		$query = $this->freeswitch_model->get_fsserver_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
947
		$grid_fields = json_decode($this->freeswitch_form->build_fsserver_list());
948
		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
949
950
		echo json_encode($json_data);
951
	}
952
953 View Code Duplication
	function fsserver_add($type = "") {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
954
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
955
		$data['flag'] = 'create';
956
		$data['page_title'] = 'Create Freeswich Server';
957
		$data['form'] = $this->form->build_form($this->freeswitch_form->get_form_fsserver_fields(), '');
958
959
		$this->load->view('view_fsserver_add_edit', $data);
960
	}
961
962 View Code Duplication
	function fsserver_edit($edit_id = '') {
963
		$data['page_title'] = 'Edit Freeswich Server';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
964
		$where = array('id' => $edit_id);
965
		$account = $this->db_model->getSelect("*", "freeswich_servers", $where);
966
		foreach ($account->result_array() as $key => $value) {
967
			$edit_data = $value;
968
		}
969
		$data['form'] = $this->form->build_form($this->freeswitch_form->get_form_fsserver_fields(), $edit_data);
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
970
		$this->load->view('view_fsserver_add_edit', $data);
971
	}
972
973 View Code Duplication
	function fsserver_save() {
974
		$add_array = $this->input->post();
975
976
		$data['form'] = $this->form->build_form($this->freeswitch_form->get_form_fsserver_fields(), $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
977
		if ($add_array['id'] != '') {
978
			$data['page_title'] = 'Edit Freeswitch Server';
979
			if ($this->form_validation->run() == FALSE) {
980
				$data['validation_errors'] = validation_errors();
981
				echo $data['validation_errors'];
982
				exit;
983
			} else {
984
				$this->freeswitch_model->edit_fsserver($add_array, $add_array['id']);
985
				echo json_encode(array("SUCCESS"=> " Freeswitch Server Updated Successfully!"));
986
				exit;
987
			}
988
		} else {
989
			$data['page_title'] = 'Freeswich Server';
990
			if ($this->form_validation->run() == FALSE) {
991
				$data['validation_errors'] = validation_errors();
992
				echo $data['validation_errors'];
993
				exit;
994
			} else {
995
				$this->freeswitch_model->add_fssever($add_array);
996
				echo json_encode(array("SUCCESS"=> "Freeswitch Server Added Successfully!"));
997
				exit;
998
			}
999
		}
1000
		$this->load->view('view_callshop_details', $data);
0 ignored issues
show
Unused Code introduced by
$this->load->view('view_...lshop_details', $data); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
1001
	}
1002
1003 View Code Duplication
	function fsserver_delete($id) {
1004
		$this->freeswitch_model->fsserver_delete($id);
1005
		$this->session->set_flashdata('astpp_notification', 'Freeswitch Server Removed Successfully!');
1006
		redirect(base_url() . 'freeswitch/fsserver_list/');
1007
		exit;
1008
	}
1009
1010 View Code Duplication
	function fsserver_list_search() {
1011
		$ajax_search = $this->input->post('ajax_search', 0);
1012
1013
		if ($this->input->post('advance_search', TRUE) == 1) {
1014
			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
1015
			$action = $this->input->post();
1016
			unset($action['action']);
1017
			unset($action['advance_search']);
1018
			$this->session->set_userdata('fsserver_list_search', $action);
1019
		}
1020
		if (@$ajax_search != 1) {
1021
			redirect(base_url() . 'freeswitch/fsserver_list/');
1022
		}
1023
	}
1024
1025
	function fsserver_list_clearsearchfilter() {
1026
		$this->session->set_userdata('advance_search', 0);
1027
		$this->session->set_userdata('account_search', "");
1028
	}
1029
	function fssipprofile_edit_validation($id,$name){
1030
	$sip_profile_data=$this->common->get_field_name('profile_data','sip_profiles',$id);
1031
	$final_data= json_decode($sip_profile_data,true);
1032
	foreach($final_data as $key=>$value){
1033
		if($key == $name){
1034
			echo 1;
1035
			return true;
1036
		}
1037
	}
1038
	echo 0;
1039
	return true;
1040
	}
1041
}
1042
1043
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1044
 
1045