diff --git a/App/Controllers/ModulePhoneBookController.php b/App/Controllers/ModulePhoneBookController.php
index 58b6c2d..c445bbf 100644
--- a/App/Controllers/ModulePhoneBookController.php
+++ b/App/Controllers/ModulePhoneBookController.php
@@ -123,6 +123,7 @@ public function getNewRecordsAction(): void
$parameters['columns'] = [
'call_id',
'number' => 'number_rep',
+ 'created' => 'created',
'DT_RowId' => 'id',
];
$parameters['order'] = ['call_id desc'];
@@ -156,20 +157,18 @@ public function saveAction(): void
$dataId = $this->request->getPost('id', ['string', 'trim']);
$callId = $this->request->getPost('call_id', ['string', 'trim']);
- $number = $this->request->getPost('number', ['alnum']);
- $numberRep = $this->request->getPost('number_rep', ['string', 'trim'], $number);
+ $numberRep = $this->request->getPost('number_rep', ['string', 'trim']);
+ $number = PhoneBook::cleanPhoneNumber($numberRep, TRUE);
if (empty($callId) || empty($number)) {
return;
}
// If we are unable to change the primary field, delete the old record and recreate it
- $oldId = null;
$record = null;
if (stripos($dataId, 'new') === false) {
$record = PhoneBook::findFirstById($dataId);
if ($record->number !== $number) {
- $oldId = $record->id;
$record->delete();
$record = null;
}
@@ -179,39 +178,17 @@ public function saveAction(): void
$record = new PhoneBook();
}
- foreach ($record as $key => $value) {
- switch ($key) {
- case 'id':
- break;
- case 'number':
- $record->number = $number;
- break;
- case 'number_rep':
- $record->number_rep = $numberRep;
- break;
- case 'call_id':
- $record->call_id = $callId;
- break;
- case 'search_index':
- // Collect data for the search index
- $username = mb_strtolower($callId);
- // Combine all fields into a single string
- $record->search_index = $username . $number . $numberRep;
- break;
- default:
- break;
- }
- }
+ $record->setPhonebookRecord($callId, $numberRep);
if ($record->save() === false) {
$errors = $record->getMessages();
$this->flash->error(implode('
', $errors));
$this->view->success = false;
-
+ $this->response->setStatusCode(500);
return;
}
- $this->view->data = ['oldId' => $oldId, 'newId' => $record->id];
+ $this->view->data = ['oldId' => $dataId, 'newId' => $record->id];
$this->view->success = true;
}
@@ -249,9 +226,9 @@ public function deleteAllRecordsAction(): void
}
/**
- * Toggle input mask feature.
+ * Save settings
*/
- public function toggleDisableInputMaskAction(): void
+ public function saveSettingsAction(): void
{
if (!$this->request->isPost()) {
return;
@@ -262,10 +239,19 @@ public function toggleDisableInputMaskAction(): void
$settings = new Settings();
}
- $settings->disableInputMask = $this->request->getPost('disableInputMask') === 'true' ? '1' : '0';
+ if ($this->request->hasPost('disableInputMask')) {
+ $settings->disableInputMask = $this->request->getPost('disableInputMask') === 'true' ? '1' : '0';
+ }
+
+ if ($this->request->hasPost('phoneBookApiUrl')) {
+ $settings->phoneBookApiUrl = empty($this->request->getPost('phoneBookApiUrl')) ? NULL : $this->request->getPost('phoneBookApiUrl', 'trim');
+ $settings->phoneBookLifeTime = empty($this->request->getPost('phoneBookLifeTime')) ? 0 : $this->request->getPost('phoneBookLifeTime', 'int!');
+ }
+
if (!$settings->save()) {
$this->flash->error(implode('
', $settings->getMessages()));
$this->view->success = false;
+ $this->response->setStatusCode(500);
return;
}
$this->view->success = true;
diff --git a/App/Forms/ModuleConfigForm.php b/App/Forms/ModuleConfigForm.php
index ea491e5..9220af7 100644
--- a/App/Forms/ModuleConfigForm.php
+++ b/App/Forms/ModuleConfigForm.php
@@ -21,6 +21,8 @@
namespace Modules\ModulePhoneBook\App\Forms;
use MikoPBX\AdminCabinet\Forms\BaseForm;
+use Phalcon\Forms\Element\Text;
+use Phalcon\Forms\Element\Numeric;
use Phalcon\Forms\Element\Check;
use Phalcon\Forms\Element\File;
@@ -31,6 +33,20 @@ public function initialize($entity = null, $options = null): void
// DisableInputMask
$this->addCheckBox('disableInputMask', intval($entity->disableInputMask) === 1);
+ // phoneBookApiUrl Text field
+ $this->add(
+ new Text('phoneBookApiUrl', [
+ 'placeholder' => 'https://',
+ ])
+ );
+
+ // phoneBookLifeTime Text field
+ $this->add(
+ new Numeric('phoneBookLifeTime', [
+ 'min' => 0
+ ])
+ );
+
// Excel file
$excelFile = new File('excelFile');
$this->add($excelFile);
@@ -49,7 +65,7 @@ public function addCheckBox(string $fieldName, bool $checked, string $checkedVal
{
$checkAr = ['value' => null];
if ($checked) {
- $checkAr = ['checked' => $checkedValue,'value' => $checkedValue];
+ $checkAr = ['checked' => $checkedValue, 'value' => $checkedValue];
}
$this->add(new Check($fieldName, $checkAr));
}
diff --git a/App/Views/ModulePhoneBook/Tabs/phonebookTab.volt b/App/Views/ModulePhoneBook/Tabs/phonebookTab.volt
index aa8bfde..d01f378 100644
--- a/App/Views/ModulePhoneBook/Tabs/phonebookTab.volt
+++ b/App/Views/ModulePhoneBook/Tabs/phonebookTab.volt
@@ -8,7 +8,7 @@