OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
76
app/Domain/Clients/Controllers/DelClient.php
Normal file
76
app/Domain/Clients/Controllers/DelClient.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Clients\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* DelClient Controller - Deleting clients.
|
||||
*/
|
||||
class DelClient extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(ClientService $clientService): void
|
||||
{
|
||||
$this->clientService = $clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the delete client confirmation page.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::DELETE, global: true)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
if ($this->clientService->hasTickets($id)) {
|
||||
$this->tpl->setNotification($this->language->__('notification.client_has_todos'), 'error');
|
||||
}
|
||||
|
||||
$this->tpl->assign('client', $this->clientService->get($id));
|
||||
|
||||
return $this->tpl->display('clients.delClient');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles client deletion.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::DELETE, global: true)]
|
||||
public function post(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
if ($this->clientService->hasTickets($id)) {
|
||||
$this->tpl->setNotification($this->language->__('notification.client_has_todos'), 'error');
|
||||
$this->tpl->assign('client', $this->clientService->get($id));
|
||||
|
||||
return $this->tpl->display('clients.delClient');
|
||||
}
|
||||
|
||||
$this->clientService->delete($id);
|
||||
$this->tpl->setNotification($this->language->__('notification.client_deleted'), 'success');
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/clients/showAll');
|
||||
}
|
||||
}
|
||||
88
app/Domain/Clients/Controllers/EditClient.php
Normal file
88
app/Domain/Clients/Controllers/EditClient.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Clients\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* EditClient Controller - Editing clients.
|
||||
*/
|
||||
class EditClient extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(ClientService $clientService): void
|
||||
{
|
||||
$this->clientService = $clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the edit client form.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
$row = $this->clientService->get($id);
|
||||
|
||||
if ($row === false) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
$this->tpl->assign('values', $row);
|
||||
|
||||
return $this->tpl->display('clients.editClient');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles client edit form submission.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
|
||||
public function post(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
|
||||
$values = [
|
||||
'id' => $id,
|
||||
'name' => $_POST['name'] ?? '',
|
||||
'street' => $_POST['street'] ?? '',
|
||||
'zip' => $_POST['zip'] ?? '',
|
||||
'city' => $_POST['city'] ?? '',
|
||||
'state' => $_POST['state'] ?? '',
|
||||
'country' => $_POST['country'] ?? '',
|
||||
'phone' => $_POST['phone'] ?? '',
|
||||
'internet' => $_POST['internet'] ?? '',
|
||||
'email' => $_POST['email'] ?? '',
|
||||
];
|
||||
|
||||
if ($values['name'] !== '') {
|
||||
$this->clientService->editClient($values);
|
||||
$this->tpl->setNotification('EDIT_CLIENT_SUCCESS', 'success', 'client_updated');
|
||||
} else {
|
||||
$this->tpl->setNotification('NO_NAME', 'error');
|
||||
}
|
||||
|
||||
$this->tpl->assign('values', $values);
|
||||
|
||||
return $this->tpl->display('clients.editClient');
|
||||
}
|
||||
}
|
||||
89
app/Domain/Clients/Controllers/NewClient.php
Normal file
89
app/Domain/Clients/Controllers/NewClient.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Clients\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Core\Exceptions\EntityExistsException;
|
||||
use Leantime\Core\Exceptions\MissingParameterException;
|
||||
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* NewClient Controller - Add a new client.
|
||||
*/
|
||||
class NewClient extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(ClientService $clientService): void
|
||||
{
|
||||
$this->clientService = $clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the new client form.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::CREATE, global: true)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
$values = [
|
||||
'name' => '',
|
||||
'street' => '',
|
||||
'zip' => '',
|
||||
'city' => '',
|
||||
'state' => '',
|
||||
'country' => '',
|
||||
'phone' => '',
|
||||
'internet' => '',
|
||||
'email' => '',
|
||||
];
|
||||
|
||||
$this->tpl->assign('values', $values);
|
||||
|
||||
return $this->tpl->display('clients.newClient');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles new client form submission.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::CREATE, global: true)]
|
||||
public function post(array $params): Response
|
||||
{
|
||||
$values = [
|
||||
'name' => $_POST['name'] ?? '',
|
||||
'street' => $_POST['street'] ?? '',
|
||||
'zip' => $_POST['zip'] ?? '',
|
||||
'city' => $_POST['city'] ?? '',
|
||||
'state' => $_POST['state'] ?? '',
|
||||
'country' => $_POST['country'] ?? '',
|
||||
'phone' => $_POST['phone'] ?? '',
|
||||
'internet' => $_POST['internet'] ?? '',
|
||||
'email' => $_POST['email'] ?? '',
|
||||
];
|
||||
|
||||
try {
|
||||
$id = $this->clientService->createClient($values);
|
||||
$this->tpl->setNotification($this->language->__('notification.client_added_successfully'), 'success', 'new_client');
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$id);
|
||||
} catch (EntityExistsException) {
|
||||
$this->tpl->setNotification($this->language->__('notification.client_exists_already'), 'error');
|
||||
} catch (MissingParameterException) {
|
||||
$this->tpl->setNotification($this->language->__('notification.client_name_not_specified'), 'error');
|
||||
}
|
||||
|
||||
$this->tpl->assign('values', $values);
|
||||
|
||||
return $this->tpl->display('clients.newClient');
|
||||
}
|
||||
}
|
||||
69
app/Domain/Clients/Controllers/RemoveUser.php
Normal file
69
app/Domain/Clients/Controllers/RemoveUser.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Clients\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* RemoveUser Controller - Remove user from client.
|
||||
*/
|
||||
class RemoveUser extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(ClientService $clientService): void
|
||||
{
|
||||
$this->clientService = $clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the remove user confirmation (no state change on GET).
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
$clientId = (int) ($params['id'] ?? $_GET['id'] ?? 0);
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles user removal from client via POST (CSRF-protected).
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
|
||||
public function post(array $params): Response
|
||||
{
|
||||
$clientId = (int) ($params['id'] ?? $_POST['id'] ?? 0);
|
||||
$userId = (int) ($params['userId'] ?? $_POST['userId'] ?? 0);
|
||||
|
||||
if ($clientId === 0 || $userId === 0) {
|
||||
return $this->tpl->display('errors.error403', responseCode: 403);
|
||||
}
|
||||
|
||||
if ($this->clientService->removeUser($clientId, $userId)) {
|
||||
$this->tpl->setNotification(
|
||||
$this->language->__('notification.user_removed_from_client'),
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
$this->tpl->setNotification(
|
||||
$this->language->__('notification.error_removing_user'),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$clientId);
|
||||
}
|
||||
}
|
||||
42
app/Domain/Clients/Controllers/ShowAll.php
Normal file
42
app/Domain/Clients/Controllers/ShowAll.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Clients\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* ShowAll Controller - Show all clients.
|
||||
*/
|
||||
class ShowAll extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(ClientService $clientService): void
|
||||
{
|
||||
$this->clientService = $clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the list of all clients.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::VIEW, global: true)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
if (session('userdata.role') == 'admin') {
|
||||
$this->tpl->assign('admin', true);
|
||||
}
|
||||
|
||||
$this->tpl->assign('allClients', $this->clientService->getAll());
|
||||
|
||||
return $this->tpl->display('clients.showAll');
|
||||
}
|
||||
}
|
||||
161
app/Domain/Clients/Controllers/ShowClient.php
Normal file
161
app/Domain/Clients/Controllers/ShowClient.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Clients\Controllers;
|
||||
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Core\Controller\Frontcontroller;
|
||||
use Leantime\Core\Exceptions\MissingParameterException;
|
||||
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
|
||||
use Leantime\Domain\Clients\Services\Clients as ClientService;
|
||||
use Leantime\Domain\Comments\Services\Comments as CommentService;
|
||||
use Leantime\Domain\Files\Services\Files as FileService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* ShowClient Controller - Show one client.
|
||||
*/
|
||||
class ShowClient extends Controller
|
||||
{
|
||||
private ClientService $clientService;
|
||||
|
||||
private CommentService $commentService;
|
||||
|
||||
private FileService $fileService;
|
||||
|
||||
/**
|
||||
* Initializes dependencies.
|
||||
*/
|
||||
public function init(
|
||||
ClientService $clientService,
|
||||
CommentService $commentService,
|
||||
FileService $fileService
|
||||
): void {
|
||||
$this->clientService = $clientService;
|
||||
$this->commentService = $commentService;
|
||||
$this->fileService = $fileService;
|
||||
|
||||
if (! session()->exists('lastPage')) {
|
||||
session(['lastPage' => BASE_URL.'/clients/showAll']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the client detail page.
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::VIEW, global: true)]
|
||||
public function get(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
$client = $this->clientService->get($id);
|
||||
|
||||
if ($client === false) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
// Handle file deletion via GET param
|
||||
if (isset($_GET['delFile'])) {
|
||||
$result = $this->fileService->deleteFile($_GET['delFile']);
|
||||
|
||||
if ($result === true) {
|
||||
$this->tpl->setNotification($this->language->__('notifications.file_deleted'), 'success', 'clientfile_deleted');
|
||||
|
||||
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$id.'#files');
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notifications.file_deleted_error'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
if (session('userdata.role') == 'admin') {
|
||||
$this->tpl->assign('admin', true);
|
||||
}
|
||||
|
||||
$this->tpl->assign('client', $client);
|
||||
|
||||
$pageData = $this->clientService->getClientPageData($id);
|
||||
array_map([$this->tpl, 'assign'], array_keys($pageData), array_values($pageData));
|
||||
|
||||
return $this->tpl->display('clients.showClient');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles client detail form submissions (save, upload, comment).
|
||||
*
|
||||
* @param array $params Request parameters
|
||||
*/
|
||||
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
|
||||
public function post(array $params): Response
|
||||
{
|
||||
if (! isset($params['id'])) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
$id = (int) $params['id'];
|
||||
$client = $this->clientService->get($id);
|
||||
|
||||
if ($client === false) {
|
||||
return $this->tpl->display('errors.error404', responseCode: 404);
|
||||
}
|
||||
|
||||
// Handle file upload
|
||||
if (isset($_POST['upload'])) {
|
||||
if (isset($_FILES['file']) && $_FILES['file']['tmp_name'] != '') {
|
||||
$this->fileService->upload($_FILES, 'client', $id);
|
||||
$this->tpl->setNotification($this->language->__('notifications.file_upload_success'), 'success', 'clientfile_uploaded');
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notifications.file_upload_error'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Handle comment
|
||||
if (isset($_POST['comment'])) {
|
||||
if ($this->commentService->addComment($_POST, 'client', $id, $client)) {
|
||||
$this->tpl->setNotification($this->language->__('notifications.comment_create_success'), 'success');
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notifications.comment_create_error'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Handle client save
|
||||
if (isset($_POST['save'])) {
|
||||
$values = [
|
||||
'id' => $id,
|
||||
'name' => $_POST['name'] ?? '',
|
||||
'street' => $_POST['street'] ?? '',
|
||||
'zip' => $_POST['zip'] ?? '',
|
||||
'city' => $_POST['city'] ?? '',
|
||||
'state' => $_POST['state'] ?? '',
|
||||
'country' => $_POST['country'] ?? '',
|
||||
'phone' => $_POST['phone'] ?? '',
|
||||
'internet' => $_POST['internet'] ?? '',
|
||||
'email' => $_POST['email'] ?? '',
|
||||
];
|
||||
|
||||
try {
|
||||
$this->clientService->updateClient($values);
|
||||
$this->tpl->setNotification($this->language->__('notification.client_saved_successfully'), 'success');
|
||||
} catch (MissingParameterException) {
|
||||
$this->tpl->setNotification($this->language->__('notification.client_name_not_specified'), 'error');
|
||||
}
|
||||
|
||||
$client = $values;
|
||||
}
|
||||
|
||||
if (session('userdata.role') == 'admin') {
|
||||
$this->tpl->assign('admin', true);
|
||||
}
|
||||
|
||||
$this->tpl->assign('client', $client);
|
||||
|
||||
$pageData = $this->clientService->getClientPageData($id);
|
||||
array_map([$this->tpl, 'assign'], array_keys($pageData), array_values($pageData));
|
||||
|
||||
return $this->tpl->display('clients.showClient');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user