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