Skip to content

Commit a59e2e2

Browse files
add DID bulk variable {DID} and update opensips installation
1 parent 8feb4c8 commit a59e2e2

File tree

5 files changed

+182
-156
lines changed

5 files changed

+182
-156
lines changed

build/MagnusBilling-current.tar.gz

80 Bytes
Binary file not shown.

protected/controllers/DiddestinationController.php

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,41 @@
2323
class DiddestinationController extends Controller
2424
{
2525
public $attributeOrder = 't.id';
26-
public $extraValues = array(
26+
public $extraValues = [
2727
'idUser' => 'username',
2828
'idDid' => 'did',
2929
'idIvr' => 'name',
3030
'idQueue' => 'name',
3131
'idSip' => 'name',
32-
);
32+
];
3333

34-
public $fieldsFkReport = array(
35-
'id_user' => array(
34+
public $fieldsFkReport = [
35+
'id_user' => [
3636
'table' => 'pkg_user',
3737
'pk' => 'id',
3838
'fieldReport' => 'username',
39-
),
40-
'id_ivr' => array(
39+
],
40+
'id_ivr' => [
4141
'table' => 'pkg_ivr',
4242
'pk' => 'id',
4343
'fieldReport' => 'name',
44-
), 'id_queue' => array(
44+
], 'id_queue' => [
4545
'table' => 'pkg_queue',
4646
'pk' => 'id',
4747
'fieldReport' => 'name',
48-
),
49-
'id_sip' => array(
48+
],
49+
'id_sip' => [
5050
'table' => 'pkg_sip',
5151
'pk' => 'id',
5252
'fieldReport' => 'name',
53-
),
53+
],
5454

55-
);
55+
];
5656

57-
public $fieldsInvisibleClient = array(
57+
public $fieldsInvisibleClient = [
5858
'id_user',
5959
'idUserusername',
60-
);
60+
];
6161

6262
public function init()
6363
{
@@ -80,11 +80,11 @@ public function beforeSave($values)
8080
$modelUser = User::model()->findByPk($values['id_user']);
8181

8282
if (isset($modelUser->idGroup->idUserType->id) && $modelUser->idGroup->idUserType->id != 3) {
83-
echo json_encode(array(
83+
echo json_encode([
8484
'success' => false,
8585
'rows' => '[]',
8686
'errors' => Yii::t('zii', 'You only can set DID to CLIENTS'),
87-
));
87+
]);
8888
exit;
8989
}
9090

@@ -93,11 +93,11 @@ public function beforeSave($values)
9393

9494
$modelUser->credit = $modelUser->credit + $modelUser->creditlimit;
9595
if ($modelUser->credit < $priceDid) {
96-
echo json_encode(array(
96+
echo json_encode([
9797
'success' => false,
9898
'rows' => '[]',
9999
'errors' => Yii::t('zii', 'Customer not have credit for buy DID') . ' - ' . $did->did,
100-
));
100+
]);
101101
exit;
102102
}
103103
}
@@ -126,11 +126,11 @@ public function checkRelation($values)
126126
}
127127

128128
if (isset($name) && $values['id_user'] != $model->id_user) {
129-
echo json_encode(array(
129+
echo json_encode([
130130
'success' => false,
131-
'rows' => array(),
131+
'rows' => [],
132132
'errors' => ['voip_call' => ['The ' . $name . ' must belong to the DID owner']],
133-
));
133+
]);
134134
exit;
135135
}
136136

@@ -161,11 +161,11 @@ public function checkRelation($values)
161161
}
162162

163163
if (isset($name) && isset($model->id_user) && $id_user != $model->id_user) {
164-
echo json_encode(array(
164+
echo json_encode([
165165
'success' => false,
166-
'rows' => array(),
166+
'rows' => [],
167167
'errors' => ['voip_call' => ['The ' . $name . ' must belong to the DID owner']],
168-
));
168+
]);
169169
exit;
170170
}
171171

@@ -178,8 +178,6 @@ public function actionbulkdestinatintion()
178178
$this->isNewRecord = true;
179179
$values = $this->getAttributesRequest();
180180

181-
182-
183181
$_GET['filter'] = $values['filters'];
184182

185183
$id_user = $values['id_user'];
@@ -191,6 +189,7 @@ public function actionbulkdestinatintion()
191189
foreach ($modelDid as $key => $did) {
192190

193191
$values['id_did'] = $did->id;
192+
$destination = preg_replace('/\{DID\}/', $did->did, $values['destination']);
194193

195194
if ($did->id_user == null && $did->reserved == 0) {
196195

@@ -202,7 +201,7 @@ public function actionbulkdestinatintion()
202201
$modelDiddestination->voip_call = $values['voip_call'];
203202
$modelDiddestination->priority = 1;
204203
if (strlen($values['destination']) && $values['destination'] != 'undefined') {
205-
$modelDiddestination->destination = $values['destination'];
204+
$modelDiddestination->destination = $destination;
206205
}
207206
if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') {
208207
$modelDiddestination->id_ivr = $values['id_ivr'];
@@ -236,7 +235,7 @@ public function actionbulkdestinatintion()
236235
//update destination
237236
$modelDiddestination->voip_call = $values['voip_call'];
238237
if (strlen($values['destination']) && $values['destination'] != 'undefined') {
239-
$modelDiddestination->destination = $values['destination'];
238+
$modelDiddestination->destination = $destination;
240239
}
241240
if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') {
242241
$modelDiddestination->id_ivr = $values['id_ivr'];
@@ -253,7 +252,7 @@ public function actionbulkdestinatintion()
253252
if (strlen($values['context']) && $values['context'] != 'undefined') {
254253
$modelDiddestination->context = $values['context'];
255254
}
256-
$values = $this->beforeSave($values);
255+
$values = $this->beforeSave($values);
257256
$modelDiddestination->save();
258257

259258
} else {
@@ -264,10 +263,10 @@ public function actionbulkdestinatintion()
264263
}
265264

266265
AsteriskAccess::instance()->generateSipDid();
267-
echo json_encode(array(
266+
echo json_encode([
268267
$this->nameSuccess => $this->success,
269268
$this->nameMsg => $this->msg,
270-
));
269+
]);
271270

272271
}
273272

protected/controllers/SipController.php

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,41 @@
1818
class SipController extends Controller
1919
{
2020
public $attributeOrder = 't.id ASC';
21-
public $extraValues = array(
21+
public $extraValues = [
2222
'idUser' => 'username',
2323
'idTrunkGroup' => 'name',
24-
);
24+
];
2525

26-
private $sipShowPeers = array();
26+
private $sipShowPeers = [];
2727

28-
public $fieldsFkReport = array(
29-
'id_user' => array(
28+
public $fieldsFkReport = [
29+
'id_user' => [
3030
'table' => 'pkg_user',
3131
'pk' => 'id',
3232
'fieldReport' => 'username',
33-
),
34-
'id_trunk_group' => array(
33+
],
34+
'id_trunk_group' => [
3535
'table' => 'pkg_trunk_group',
3636
'pk' => 'id',
3737
'fieldReport' => 'name',
38-
),
39-
);
38+
],
39+
];
4040

41-
public $fieldsInvisibleClient = array(
41+
public $fieldsInvisibleClient = [
4242
'id_trunk_group',
43-
);
43+
];
4444

45-
public $fieldsInvisibleAgent = array(
45+
public $fieldsInvisibleAgent = [
4646
'id_trunk_group',
47-
);
47+
];
4848

49-
public $fieldsNotUpdateClient = array(
49+
public $fieldsNotUpdateClient = [
5050
'context',
51-
);
51+
];
5252

53-
public $fieldsNotUpdateAgent = array(
53+
public $fieldsNotUpdateAgent = [
5454
'context',
55-
);
55+
];
5656

5757
public function init()
5858
{
@@ -91,13 +91,13 @@ public function beforeSave($values)
9191
{
9292

9393
if (isset($values['alias']) && strlen($values['alias'])) {
94-
$modelSip = Sip::model()->find('alias = :key AND id_user = (SELECT id_user FROM pkg_sip WHERE id = :key1)', array(':key' => $values['alias'], ':key1' => $values['id']));
94+
$modelSip = Sip::model()->find('alias = :key AND id_user = (SELECT id_user FROM pkg_sip WHERE id = :key1)', [':key' => $values['alias'], ':key1' => $values['id']]);
9595
if (isset($modelSip->id)) {
96-
echo json_encode(array(
96+
echo json_encode([
9797
'success' => false,
98-
'rows' => array(),
98+
'rows' => [],
9999
'errors' => 'Alias alread in use',
100-
));
100+
]);
101101
exit;
102102
}
103103
}
@@ -113,7 +113,7 @@ public function beforeSave($values)
113113
$values['forward'] = $values['type_forward'] . '|' . $values['id_' . $values['type_forward']];
114114

115115
}
116-
} else if ((isset($values['id_sip']) || isset($values['id_ivr']) || isset($values['id_queue'])) & !$this->isNewRecord) {
116+
} else if ((isset($values['id_sip']) || isset($values['id_ivr']) || isset($values['id_queue'])) & ! $this->isNewRecord) {
117117

118118
$modelSip = Sip::model()->findByPk($values['id']);
119119

@@ -133,30 +133,30 @@ public function beforeSave($values)
133133

134134
$modelUser = User::model()->findByPk((int) $values['id_user']);
135135

136-
$modelSipCount = Sip::model()->count("id_user = :id_user", array(':id_user' => (int) $values['id_user']));
136+
$modelSipCount = Sip::model()->count("id_user = :id_user", [':id_user' => (int) $values['id_user']]);
137137

138138
if ($modelUser->idGroup->id_user_type != 3) {
139-
echo json_encode(array(
139+
echo json_encode([
140140
'success' => false,
141-
'rows' => array(),
141+
'rows' => [],
142142
'errors' => 'You only can create SipAccount to clients',
143-
));
143+
]);
144144
exit;
145145
}
146146

147-
if (!Yii::app()->session['isAdmin'] && $modelUser->sipaccountlimit > 0
147+
if ( ! Yii::app()->session['isAdmin'] && $modelUser->sipaccountlimit > 0
148148
&& $modelSipCount >= $modelUser->sipaccountlimit) {
149-
echo json_encode(array(
149+
echo json_encode([
150150
'success' => false,
151-
'rows' => array(),
151+
'rows' => [],
152152
'errors' => 'Limit sip acount exceeded',
153-
));
153+
]);
154154
exit;
155155
}
156156
$values['regseconds'] = 1;
157157
$values['context'] = 'billing';
158158
$values['regexten'] = $values['name'];
159-
if (!$values['callerid']) {
159+
if ( ! $values['callerid']) {
160160
$values['callerid'] = $values['name'];
161161
}
162162

@@ -230,7 +230,7 @@ public function siproxyServer($values, $type)
230230

231231
$remoteProxyIP = trim(end(explode("|", $server->description)));
232232

233-
if (!filter_var($remoteProxyIP, FILTER_VALIDATE_IP)) {
233+
if ( ! filter_var($remoteProxyIP, FILTER_VALIDATE_IP)) {
234234
$remoteProxyIP = $hostname;
235235
}
236236

@@ -264,7 +264,9 @@ public function setAttributesModels($attributes, $models)
264264
$attributes[$i]['lineStatus'] = 'unregistered';
265265
foreach ($this->sipShowPeers as $value) {
266266

267-
if (strtok($value['Name/username'], '/') == $attributes[$i]['name']) {
267+
$name = strlen($attributes[$i]['techprefix']) ? $attributes[$i]['host'] : $attributes[$i]['name'];
268+
269+
if (strtok($value['Name/username'], '/') == $name) {
268270

269271
$attributes[$i]['lineStatus'] = $value['Status'];
270272

@@ -282,7 +284,7 @@ public function setAttributesModels($attributes, $models)
282284
$itemOption = explode("|", $value);
283285
$itemKey = explode("_", $key);
284286

285-
if (!isset($attributes[$i]['type_forward'])) {
287+
if ( ! isset($attributes[$i]['type_forward'])) {
286288
$attributes[$i]['type_forward'] = $itemOption[0];
287289
}
288290

@@ -311,18 +313,19 @@ public function setAttributesModels($attributes, $models)
311313

312314
public function actionGetSipShowPeer()
313315
{
314-
$modelSip = Sip::model()->find('name = :key', array(':key' => $_POST['name']));
316+
$modelSip = Sip::model()->find('name = :key', [':key' => $_POST['name']]);
315317

316318
if ($modelSip->idUser->active == 0) {
317319
$sipShowPeer = 'The username is inactive';
318320
} else {
319-
$sipShowPeer = AsteriskAccess::instance()->sipShowPeer($modelSip->name);
321+
322+
$sipShowPeer = AsteriskAccess::instance()->sipShowPeer(strlen($modelSip->techprefix) ? $modelSip->host : $modelSip->name);
320323
}
321324

322-
echo json_encode(array(
325+
echo json_encode([
323326
'success' => true,
324327
'sipshowpeer' => Yii::app()->session['isAdmin'] ? print_r($sipShowPeer, true) : '',
325-
));
328+
]);
326329
}
327330

328331
public function actionBulk()
@@ -335,26 +338,26 @@ public function actionBulk()
335338
$secret = $_POST['secret'] == "Leave blank to auto generate" ? '' : $_POST['secret'];
336339

337340
if (strlen($secret) > 0 && strlen($secret) < 6 && strlen($secret) < 25) {
338-
echo json_encode(array(
341+
echo json_encode([
339342
'success' => false,
340343
$this->nameMsg => 'Password lenght need be > 5 or blank.',
341-
));
344+
]);
342345
exit;
343346
}
344347

345348
if (preg_match('/ /', $secret)) {
346-
echo json_encode(array(
349+
echo json_encode([
347350
'success' => false,
348351
$this->nameMsg => 'No space allow in password',
349-
));
352+
]);
350353
exit;
351354
}
352355

353356
if ($secret == '123456' || $secret == '12345678' || $secret == '012345') {
354-
echo json_encode(array(
357+
echo json_encode([
355358
'success' => false,
356359
$this->nameMsg => 'No use sequence in the password',
357-
));
360+
]);
358361
exit;
359362
}
360363

@@ -386,10 +389,10 @@ public function actionBulk()
386389

387390
AsteriskAccess::instance()->generateSipPeers();
388391

389-
echo json_encode(array(
392+
echo json_encode([
390393
$this->nameSuccess => true,
391394
$this->nameMsg => $this->msgSuccess,
392-
));
395+
]);
393396
}
394397

395398
}

0 commit comments

Comments
 (0)