fix CRM contacts

This commit is contained in:
root
2026-01-18 19:19:03 +03:00
parent 77f76c8c28
commit 308c684aa2
6 changed files with 122 additions and 655 deletions
@@ -51,9 +51,14 @@ class TwigGlobalsExtension extends AbstractExtension
// Module subscription functions
new TwigFunction('is_module_active', [$this, 'isModuleActive'], ['is_safe' => ['html']]),
new TwigFunction('is_module_available', [$this, 'isModuleAvailable'], ['is_safe' => ['html']]),
new TwigFunction('csrf_meta', [$this, 'csrf_meta'], ['is_safe' => ['html']]),
];
}
public function csrf_meta()
{
return csrf_meta();
}
// ========================================
// Access Functions для Twig
// ========================================
@@ -249,11 +249,14 @@ class ContactsController extends BaseController
];
}, $contacts);
return $this->response->setJSON([
'success' => true,
'items' => $items,
'total' => count($items),
]);
return $this->response
->setHeader('X-CSRF-TOKEN', csrf_hash())
->setHeader('X-CSRF-HASH', csrf_token())
->setJSON([
'success' => true,
'items' => $items,
'total' => count($items),
]);
}
/**
@@ -263,7 +266,12 @@ class ContactsController extends BaseController
public function ajaxStore()
{
$organizationId = $this->requireActiveOrg();
$customerId = $this->request->getPost('customer_id');
// Поддержка JSON и form-urlencoded данных
$jsonData = $this->request->getJSON(true);
$rawInput = $jsonData ?? $this->request->getPost();
$customerId = $rawInput['customer_id'] ?? null;
// Проверяем клиента если указан
if ($customerId) {
@@ -279,10 +287,10 @@ class ContactsController extends BaseController
$data = [
'organization_id' => $organizationId,
'customer_id' => $customerId ?: null,
'name' => $this->request->getPost('name'),
'email' => $this->request->getPost('email') ?: null,
'phone' => $this->request->getPost('phone') ?: null,
'position' => $this->request->getPost('position') ?: null,
'name' => $rawInput['name'] ?? '',
'email' => $rawInput['email'] ?? null,
'phone' => $rawInput['phone'] ?? null,
'position' => $rawInput['position'] ?? null,
];
// Валидация
@@ -304,17 +312,20 @@ class ContactsController extends BaseController
])->setStatusCode(422);
}
return $this->response->setJSON([
'success' => true,
'message' => 'Контакт создан',
'item' => [
'id' => $contactId,
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'],
'position' => $data['position'],
],
]);
return $this->response
->setHeader('X-CSRF-TOKEN', csrf_hash())
->setHeader('X-CSRF-HASH', csrf_token())
->setJSON([
'success' => true,
'message' => 'Контакт создан',
'item' => [
'id' => $contactId,
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'],
'position' => $data['position'],
],
]);
}
/**
@@ -334,11 +345,15 @@ class ContactsController extends BaseController
])->setStatusCode(404);
}
// Поддержка JSON и form-urlencoded данных
$jsonData = $this->request->getJSON(true);
$rawInput = $jsonData ?? $this->request->getPost();
$data = [
'name' => $this->request->getPost('name'),
'email' => $this->request->getPost('email') ?: null,
'phone' => $this->request->getPost('phone') ?: null,
'position' => $this->request->getPost('position') ?: null,
'name' => $rawInput['name'] ?? '',
'email' => $rawInput['email'] ?? null,
'phone' => $rawInput['phone'] ?? null,
'position' => $rawInput['position'] ?? null,
];
// Валидация
@@ -360,17 +375,20 @@ class ContactsController extends BaseController
])->setStatusCode(422);
}
return $this->response->setJSON([
'success' => true,
'message' => 'Контакт обновлён',
'item' => [
'id' => $id,
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'],
'position' => $data['position'],
],
]);
return $this->response
->setHeader('X-CSRF-TOKEN', csrf_hash())
->setHeader('X-CSRF-HASH', csrf_token())
->setJSON([
'success' => true,
'message' => 'Контакт обновлён',
'item' => [
'id' => $id,
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'],
'position' => $data['position'],
],
]);
}
/**
@@ -392,9 +410,12 @@ class ContactsController extends BaseController
$this->contactModel->delete($id);
return $this->response->setJSON([
'success' => true,
'message' => 'Контакт удалён',
]);
return $this->response
->setHeader('X-CSRF-TOKEN', csrf_hash())
->setHeader('X-CSRF-HASH', csrf_token())
->setJSON([
'success' => true,
'message' => 'Контакт удалён',
]);
}
}
+2 -1
View File
@@ -7,6 +7,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ csrf_meta() }}
<title>{% block title %}Бизнес.Точка{% endblock %}</title>
<!-- Bootstrap CSS -->
@@ -17,7 +18,7 @@
<link href="{{ base_url('assets/css/base.css') }}" rel="stylesheet">
{% block styles %}{% endblock %}
</head>
<body class="bg-light">
<body class="bg-light" data-base-url="{{ base_url('/') }}">
<div class="d-flex" id="wrapper">
<!-- SIDEBAR -->