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