1<?php
2/** @var action_plugin_bez $this */
3
4use \dokuwiki\plugin\bez;
5
6if ($this->model->get_level() < BEZ_AUTH_USER) {
7    throw new bez\meta\PermissionDeniedException();
8}
9
10/** @var bez\mdl\Task $task */
11$task = $this->model->taskFactory->create_object();
12
13$this->tpl->set('task', $task);
14$this->tpl->set('task_programs',  $this->model->task_programFactory->get_all([], 'name'));
15
16if ($this->get_param('action') == 'add') {
17    $this->model->taskFactory->initial_save($task, $_POST);
18    $redirect = true;
19} elseif($this->get_param('duplicate') != '') {
20    $task_dup = $this->model->taskFactory->get_one($this->get_param('duplicate'));
21    $this->tpl->set_values($task_dup->get_assoc());
22}
23
24if (isset($redirect) && $redirect == true) {
25    header("Location: " . $this->url('task', 'tid', $task->id));
26}
27