18
18
class SipController extends Controller
19
19
{
20
20
public $ attributeOrder = 't.id ASC ' ;
21
- public $ extraValues = array (
21
+ public $ extraValues = [
22
22
'idUser ' => 'username ' ,
23
23
'idTrunkGroup ' => 'name ' ,
24
- ) ;
24
+ ] ;
25
25
26
- private $ sipShowPeers = array () ;
26
+ private $ sipShowPeers = [] ;
27
27
28
- public $ fieldsFkReport = array (
29
- 'id_user ' => array (
28
+ public $ fieldsFkReport = [
29
+ 'id_user ' => [
30
30
'table ' => 'pkg_user ' ,
31
31
'pk ' => 'id ' ,
32
32
'fieldReport ' => 'username ' ,
33
- ) ,
34
- 'id_trunk_group ' => array (
33
+ ] ,
34
+ 'id_trunk_group ' => [
35
35
'table ' => 'pkg_trunk_group ' ,
36
36
'pk ' => 'id ' ,
37
37
'fieldReport ' => 'name ' ,
38
- ) ,
39
- ) ;
38
+ ] ,
39
+ ] ;
40
40
41
- public $ fieldsInvisibleClient = array (
41
+ public $ fieldsInvisibleClient = [
42
42
'id_trunk_group ' ,
43
- ) ;
43
+ ] ;
44
44
45
- public $ fieldsInvisibleAgent = array (
45
+ public $ fieldsInvisibleAgent = [
46
46
'id_trunk_group ' ,
47
- ) ;
47
+ ] ;
48
48
49
- public $ fieldsNotUpdateClient = array (
49
+ public $ fieldsNotUpdateClient = [
50
50
'context ' ,
51
- ) ;
51
+ ] ;
52
52
53
- public $ fieldsNotUpdateAgent = array (
53
+ public $ fieldsNotUpdateAgent = [
54
54
'context ' ,
55
- ) ;
55
+ ] ;
56
56
57
57
public function init ()
58
58
{
@@ -91,13 +91,13 @@ public function beforeSave($values)
91
91
{
92
92
93
93
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 ' ]] );
95
95
if (isset ($ modelSip ->id )) {
96
- echo json_encode (array (
96
+ echo json_encode ([
97
97
'success ' => false ,
98
- 'rows ' => array () ,
98
+ 'rows ' => [] ,
99
99
'errors ' => 'Alias alread in use ' ,
100
- ) );
100
+ ] );
101
101
exit ;
102
102
}
103
103
}
@@ -113,7 +113,7 @@ public function beforeSave($values)
113
113
$ values ['forward ' ] = $ values ['type_forward ' ] . '| ' . $ values ['id_ ' . $ values ['type_forward ' ]];
114
114
115
115
}
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 ) {
117
117
118
118
$ modelSip = Sip::model ()->findByPk ($ values ['id ' ]);
119
119
@@ -133,30 +133,30 @@ public function beforeSave($values)
133
133
134
134
$ modelUser = User::model ()->findByPk ((int ) $ values ['id_user ' ]);
135
135
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 ' ]] );
137
137
138
138
if ($ modelUser ->idGroup ->id_user_type != 3 ) {
139
- echo json_encode (array (
139
+ echo json_encode ([
140
140
'success ' => false ,
141
- 'rows ' => array () ,
141
+ 'rows ' => [] ,
142
142
'errors ' => 'You only can create SipAccount to clients ' ,
143
- ) );
143
+ ] );
144
144
exit ;
145
145
}
146
146
147
- if (! Yii::app ()->session ['isAdmin ' ] && $ modelUser ->sipaccountlimit > 0
147
+ if ( ! Yii::app ()->session ['isAdmin ' ] && $ modelUser ->sipaccountlimit > 0
148
148
&& $ modelSipCount >= $ modelUser ->sipaccountlimit ) {
149
- echo json_encode (array (
149
+ echo json_encode ([
150
150
'success ' => false ,
151
- 'rows ' => array () ,
151
+ 'rows ' => [] ,
152
152
'errors ' => 'Limit sip acount exceeded ' ,
153
- ) );
153
+ ] );
154
154
exit ;
155
155
}
156
156
$ values ['regseconds ' ] = 1 ;
157
157
$ values ['context ' ] = 'billing ' ;
158
158
$ values ['regexten ' ] = $ values ['name ' ];
159
- if (! $ values ['callerid ' ]) {
159
+ if ( ! $ values ['callerid ' ]) {
160
160
$ values ['callerid ' ] = $ values ['name ' ];
161
161
}
162
162
@@ -230,7 +230,7 @@ public function siproxyServer($values, $type)
230
230
231
231
$ remoteProxyIP = trim (end (explode ("| " , $ server ->description )));
232
232
233
- if (! filter_var ($ remoteProxyIP , FILTER_VALIDATE_IP )) {
233
+ if ( ! filter_var ($ remoteProxyIP , FILTER_VALIDATE_IP )) {
234
234
$ remoteProxyIP = $ hostname ;
235
235
}
236
236
@@ -264,7 +264,9 @@ public function setAttributesModels($attributes, $models)
264
264
$ attributes [$ i ]['lineStatus ' ] = 'unregistered ' ;
265
265
foreach ($ this ->sipShowPeers as $ value ) {
266
266
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 ) {
268
270
269
271
$ attributes [$ i ]['lineStatus ' ] = $ value ['Status ' ];
270
272
@@ -282,7 +284,7 @@ public function setAttributesModels($attributes, $models)
282
284
$ itemOption = explode ("| " , $ value );
283
285
$ itemKey = explode ("_ " , $ key );
284
286
285
- if (! isset ($ attributes [$ i ]['type_forward ' ])) {
287
+ if ( ! isset ($ attributes [$ i ]['type_forward ' ])) {
286
288
$ attributes [$ i ]['type_forward ' ] = $ itemOption [0 ];
287
289
}
288
290
@@ -311,18 +313,19 @@ public function setAttributesModels($attributes, $models)
311
313
312
314
public function actionGetSipShowPeer ()
313
315
{
314
- $ modelSip = Sip::model ()->find ('name = :key ' , array ( ':key ' => $ _POST ['name ' ]) );
316
+ $ modelSip = Sip::model ()->find ('name = :key ' , [ ':key ' => $ _POST ['name ' ]] );
315
317
316
318
if ($ modelSip ->idUser ->active == 0 ) {
317
319
$ sipShowPeer = 'The username is inactive ' ;
318
320
} else {
319
- $ sipShowPeer = AsteriskAccess::instance ()->sipShowPeer ($ modelSip ->name );
321
+
322
+ $ sipShowPeer = AsteriskAccess::instance ()->sipShowPeer (strlen ($ modelSip ->techprefix ) ? $ modelSip ->host : $ modelSip ->name );
320
323
}
321
324
322
- echo json_encode (array (
325
+ echo json_encode ([
323
326
'success ' => true ,
324
327
'sipshowpeer ' => Yii::app ()->session ['isAdmin ' ] ? print_r ($ sipShowPeer , true ) : '' ,
325
- ) );
328
+ ] );
326
329
}
327
330
328
331
public function actionBulk ()
@@ -335,26 +338,26 @@ public function actionBulk()
335
338
$ secret = $ _POST ['secret ' ] == "Leave blank to auto generate " ? '' : $ _POST ['secret ' ];
336
339
337
340
if (strlen ($ secret ) > 0 && strlen ($ secret ) < 6 && strlen ($ secret ) < 25 ) {
338
- echo json_encode (array (
341
+ echo json_encode ([
339
342
'success ' => false ,
340
343
$ this ->nameMsg => 'Password lenght need be > 5 or blank. ' ,
341
- ) );
344
+ ] );
342
345
exit ;
343
346
}
344
347
345
348
if (preg_match ('/ / ' , $ secret )) {
346
- echo json_encode (array (
349
+ echo json_encode ([
347
350
'success ' => false ,
348
351
$ this ->nameMsg => 'No space allow in password ' ,
349
- ) );
352
+ ] );
350
353
exit ;
351
354
}
352
355
353
356
if ($ secret == '123456 ' || $ secret == '12345678 ' || $ secret == '012345 ' ) {
354
- echo json_encode (array (
357
+ echo json_encode ([
355
358
'success ' => false ,
356
359
$ this ->nameMsg => 'No use sequence in the password ' ,
357
- ) );
360
+ ] );
358
361
exit ;
359
362
}
360
363
@@ -386,10 +389,10 @@ public function actionBulk()
386
389
387
390
AsteriskAccess::instance ()->generateSipPeers ();
388
391
389
- echo json_encode (array (
392
+ echo json_encode ([
390
393
$ this ->nameSuccess => true ,
391
394
$ this ->nameMsg => $ this ->msgSuccess ,
392
- ) );
395
+ ] );
393
396
}
394
397
395
398
}
0 commit comments