|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) MIKO LLC - All Rights Reserved |
|
4
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
|
5
|
|
|
* Proprietary and confidential |
|
6
|
|
|
* Written by Nikolay Beketov, 6 2018 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace MikoPBX\AdminCabinet\Controllers; |
|
11
|
|
|
|
|
12
|
|
|
use MikoPBX\AdminCabinet\Forms\GeneralSettingsEditForm; |
|
13
|
|
|
use MikoPBX\Common\Models\Codecs; |
|
14
|
|
|
use MikoPBX\Common\Models\PbxSettings; |
|
15
|
|
|
|
|
16
|
|
|
class GeneralSettingsController extends BaseController |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Построение формы настроек |
|
21
|
|
|
*/ |
|
22
|
|
|
public function modifyAction(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$parameters = [ |
|
25
|
|
|
'conditions'=>'type="audio"', |
|
26
|
|
|
'order' => 'priority', |
|
27
|
|
|
]; |
|
28
|
|
|
$this->view->audioCodecs = Codecs::find($parameters); |
|
29
|
|
|
$parameters['conditions'] = 'type="video"'; |
|
30
|
|
|
$this->view->videoCodecs = Codecs::find($parameters); |
|
31
|
|
|
|
|
32
|
|
|
$pbxSettings = PbxSettings::getAllPbxSettings(); |
|
33
|
|
|
$this->view->form = new GeneralSettingsEditForm(null, $pbxSettings); |
|
34
|
|
|
$this->view->submitMode = null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Сохранение настроек системы |
|
39
|
|
|
*/ |
|
40
|
|
|
public function saveAction(): void |
|
41
|
|
|
{ |
|
42
|
|
|
if ( ! $this->request->isPost()) { |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
$data = $this->request->getPost(); |
|
46
|
|
|
$pbxSettings = PbxSettings::getDefaultArrayValues(); |
|
47
|
|
|
$this->db->begin(); |
|
48
|
|
|
foreach ($pbxSettings as $key => $value) { |
|
49
|
|
|
$record = PbxSettings::findFirstByKey($key); |
|
50
|
|
|
if ($record === null) { |
|
51
|
|
|
$record = new PbxSettings(); |
|
52
|
|
|
$record->key = $key; |
|
53
|
|
|
$record->value = $value; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
switch ($key) { |
|
57
|
|
|
case 'PBXRecordCalls': |
|
58
|
|
|
case 'AJAMEnabled': |
|
59
|
|
|
case 'AMIEnabled': |
|
60
|
|
|
case 'RestartEveryNight': |
|
61
|
|
|
case 'RedirectToHttps': |
|
62
|
|
|
case 'PBXSplitAudioThread': |
|
63
|
|
|
case '***ALL CHECK BOXES ABOVE***': |
|
64
|
|
|
$record->value = ($data[$key] === 'on') ? '1' : '0'; |
|
65
|
|
|
break; |
|
66
|
|
|
case 'SSHPassword': |
|
67
|
|
|
//Если отправили пароль по-умолчанию, то сделаем его равным паролю WEB |
|
68
|
|
|
if ($data[$key] === $pbxSettings[$key]) { |
|
69
|
|
|
$record->value = $data['WebAdminPassword']; |
|
70
|
|
|
} else { |
|
71
|
|
|
$record->value = $data[$key]; |
|
72
|
|
|
} |
|
73
|
|
|
break; |
|
74
|
|
|
case 'SendMetrics': |
|
75
|
|
|
$record->value = ($data[$key] === 'on') ? '1' : '0'; |
|
76
|
|
|
$this->session->set('SendMetrics', $record->value); |
|
77
|
|
|
break; |
|
78
|
|
|
default: |
|
79
|
|
|
if (array_key_exists($key, $data)) { |
|
80
|
|
|
$record->value = $data[$key]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
if ($record->save() === false) { |
|
84
|
|
|
$errors = $record->getMessages(); |
|
85
|
|
|
$this->flash->warning(implode('<br>', $errors)); |
|
86
|
|
|
$this->view->success = false; |
|
87
|
|
|
$this->db->rollback(); |
|
88
|
|
|
|
|
89
|
|
|
return; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$codecs = json_decode($data['codecs'], true); |
|
94
|
|
|
foreach ($codecs as $codec){ |
|
95
|
|
|
$record = Codecs::findFirstById($codec['codecId']); |
|
96
|
|
|
$record->priority = $codec['priority']; |
|
97
|
|
|
$record->disabled = $codec['disabled']===true?'1':'0'; |
|
98
|
|
|
$record->update(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$this->flash->success($this->translation->_('ms_SuccessfulSaved')); |
|
102
|
|
|
$this->view->success = true; |
|
103
|
|
|
$this->db->commit(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} |