1<?php 2/** @var action_plugin_bez_default $this */ 3 4use \dokuwiki\plugin\bez; 5 6if ($this->get_param('id') == '') { 7 header('Location: ' . $this->url('threads')); 8} 9 10/** @var bez\mdl\Thread $thread */ 11$thread = $this->model->threadFactory->get_one($this->get_param('id')); 12$this->tpl->set('thread', $thread); 13$this->tpl->set('thread_comments', $this->model->thread_commentFactory->get_from_thread($thread)); 14$this->tpl->set('tasks', $this->model->taskFactory->get_from_thread($thread)); 15$this->tpl->set('task_programs', $this->model->task_programFactory->get_all()); 16 17 18if ($this->get_param('action') == 'commcause_add') { 19 20 /** @var bez\mdl\Thread_comment $thread_comment */ 21 $thread_comment = $this->model->thread_commentFactory->create_object(array('thread' => $thread)); 22 $this->model->thread_commentFactory->initial_save($thread_comment, $_POST); 23 24 $anchor = 'k'.$thread_comment->id; 25 $redirect = true; 26 27} elseif ($this->get_param('action') == 'subscribe') { 28 29 $thread->set_participant_flags($this->model->user_nick, array('subscribent')); 30 $redirect = true; 31 32} elseif ($this->get_param('action') == 'unsubscribe') { 33 34 $thread->remove_participant_flags($this->model->user_nick, array('subscribent')); 35 $this->add_notification($this->getLang('unsubscribed_com')); 36 $redirect = true; 37 38} elseif ($this->get_param('action') == 'invite') { 39 $client = $_POST['client']; 40 41 $thread->invite($client); 42 43 $this->add_notification($this->model->userFactory->get_user_email($client), $this->getLang('invitation_has_been_send')); 44 45 $redirect = true; 46} elseif ($this->get_param('action') == 'commcause_delete') { 47 /** @var bez\mdl\Thread_comment $thread_comment */ 48 $thread_comment = $this->model->thread_commentFactory->get_one($this->get_param('kid'), array('thread' => $thread)); 49 $this->model->thread_commentFactory->delete($thread_comment); 50 51 $redirect = true; 52} elseif ($this->get_param('action') == 'commcause_edit') { 53 /** @var bez\mdl\Thread_comment $thread_comment */ 54 $thread_comment = $this->model->thread_commentFactory->get_one($this->get_param('kid'), array('thread' => $thread)); 55 56 if(count($_POST) === 0) { 57 $this->tpl->set_values($thread_comment->get_assoc()); 58 } else { 59 $this->model->thread_commentFactory->update_save($thread_comment, $_POST); 60 61 $anchor = 'k' . $thread_comment->id; 62 $redirect = true; 63 } 64} elseif ($this->get_param('action') == 'task_add') { 65 66 $defaults = array('thread' => $thread); 67 68 if ($this->get_param('kid') != '') { 69 $thread_comment = $this->model->thread_commentFactory->get_one($this->get_param('kid'), array('thread' => $thread)); 70 $defaults['thread_comment'] = $thread_comment; 71 } 72 /** @var bez\mdl\Task $task */ 73 $task = $this->model->taskFactory->create_object($defaults); 74 $this->tpl->set('task', $task); 75 76 //save 77 if (count($_POST) > 0) { 78 $this->model->taskFactory->initial_save($task, $_POST); 79 80 $anchor = 'z' . $task->id; 81 $redirect = true; 82 } 83} elseif ($this->get_param('action') == 'task_edit') { 84 /** @var bez\mdl\Task $task */ 85 $task = $this->model->taskFactory->get_one($this->get_param('tid'), array('thread' => $thread)); 86 $this->tpl->set('task', $task); 87 88 //save 89 if (count($_POST) === 0) { 90 $this->tpl->set_values($task->get_assoc()); 91 } else { 92 $this->model->taskFactory->update_save($task, $_POST); 93 94 $anchor = 'z' . $task->id; 95 $redirect = true; 96 } 97} 98 99if (isset($redirect) && $redirect == true) { 100 if (isset($anchor)) { 101 $anchor = '#'.$anchor; 102 } else { 103 $anchor = ''; 104 } 105 header('Location: ' . $this->url('thread', 'id', $thread->id) . $anchor); 106} 107