diff --git a/config/ACL.php b/config/ACL.php index 20098f6..6297076 100644 --- a/config/ACL.php +++ b/config/ACL.php @@ -59,6 +59,7 @@ class ACL extends \Zend\Permissions\Acl\Acl '/clients/send/{sid}/{cldbid}', '/channels/{sid}', + '/channels/create/{sid}', '/channels/{sid}/{cid}', '/channels/edit/{sid}/{cid}', '/channels/delete/{sid}/{cid}', diff --git a/config/routes.php b/config/routes.php index f093e24..7f41210 100644 --- a/config/routes.php +++ b/config/routes.php @@ -270,6 +270,11 @@ $container[ChannelInfoAction::class] = function ($container) { }; $app->get('/channels/{sid}/{cid}', ChannelInfoAction::class); +$container[ChannelCreateAction::class] = function ($container) { + return new ChannelCreateAction($container); +}; +$app->post('/channels/create/{sid}', ChannelCreateAction::class); + $container[ChannelEditAction::class] = function ($container) { return new ChannelEditAction($container); }; diff --git a/data/locale/en.yml b/data/locale/en.yml index e03fbbc..8b23a3e 100644 --- a/data/locale/en.yml +++ b/data/locale/en.yml @@ -134,6 +134,15 @@ server_info.send.message: "Message" # channels channels.delete: "Delete" +channels.h.actions: "Actions" +channels.h.details: "Details" +channels.create: "Create a channel" +channels.create.channel_name: "Name" +channels.create.channel_order: "Order" +channels.create.semi_permanent: "Semi permanent" +channels.create.permanent: "Permanent" +channels.create.inherit: "Has a parent?" +channels.create.parent: "Parent" # channel info channel_info.h.files: "Files" diff --git a/src/Control/Actions/ChannelCreateAction.php b/src/Control/Actions/ChannelCreateAction.php new file mode 100644 index 0000000..fd5f525 --- /dev/null +++ b/src/Control/Actions/ChannelCreateAction.php @@ -0,0 +1,30 @@ +getParsedBody(); + $inherit = $body['inherit']; + + $this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']); + $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); + + if (!$inherit) { + unset($body['cpid']); + } + + unset($body['inherit']); + + $channelCreateResult = $this->ts->getInstance()->channelCreate($body); + + $this->flash->addMessage('success', $this->translator->trans('done')); + + return $response->withRedirect('/channels/' . $sid); + } +} \ No newline at end of file diff --git a/src/Control/Actions/ChannelsAction.php b/src/Control/Actions/ChannelsAction.php index a766e33..3dc3cd3 100644 --- a/src/Control/Actions/ChannelsAction.php +++ b/src/Control/Actions/ChannelsAction.php @@ -13,11 +13,23 @@ final class ChannelsAction extends AbstractAction $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); $dataResult = $this->ts->getInstance()->channelList(); + $channels = $this->ts->getInstance()->getElement('data', $dataResult); + $channelParents = []; + + $channelOrders = []; + $channelOrders['---'] = 0; + + foreach ($channels as $channel) { + $channelParents[$channel['channel_name']] = $channel['cid']; + $channelOrders[$channel['channel_name']] = $channel['cid']; + } // render GET $this->view->render($response, 'channels.twig', [ 'title' => $this->translator->trans('channels.title'), - 'data' => $this->ts->getInstance()->getElement('data', $dataResult), + 'channels' => $channels, + 'channelParents' => $channelParents, + 'channelOrders' => $channelOrders, 'sid' => $sid ]); } diff --git a/src/View/material/channels.twig b/src/View/material/channels.twig index 183e368..37dacaa 100644 --- a/src/View/material/channels.twig +++ b/src/View/material/channels.twig @@ -2,8 +2,30 @@ {% block content %}

{{ title }}

- {% if data|length > 0 %} - {% include 'table.twig' with {'data': data, + +

{% trans %}channels.h.actions{% endtrans %}

+ {% include 'form.twig' with { + 'fields': [ + { + 'header_label': 'channels.create'|trans, + 'label': 'check_circle', + 'uri': '/channels/create/' ~ sid, + 'uri_method': 'post', + 'fields': [ + {'type': 'text', 'key': 'channel_name', 'label': 'channels.create.channel_name'|trans}, + {'type': 'select', 'key': 'channel_order', 'options': channelOrders, 'label': 'channels.create.channel_order'|trans}, + {'type': 'checkbox', 'key': 'channel_flag_semi_permanent', 'label': 'channels.create.semi_permanent'|trans}, + {'type': 'checkbox', 'key': 'channel_flag_permanent', 'label': 'channels.create.permanent'|trans}, + {'type': 'checkbox', 'key': 'inherit', 'label': 'channels.create.inherit'|trans}, + {'type': 'select', 'key': 'cpid', 'options': channelParents, 'label': 'channels.create.parent'|trans}, + ] + }, + ] + } %} + + {% if channels|length > 0 %} +

{% trans %}channels.h.details{% endtrans %}

+ {% include 'table.twig' with {'data': channels, 'links': [{'key': 'cid', 'uri': '/channels/' ~ sid}], 'additional_links': [ {