1<?php 2include_once DOKU_PLUGIN."bez/models/issues.php"; 3include_once DOKU_PLUGIN."bez/models/tasks.php"; 4include_once DOKU_PLUGIN."bez/models/causes.php"; 5include_once DOKU_PLUGIN."bez/models/users.php"; 6include_once DOKU_PLUGIN."bez/models/tasktypes.php"; 7include_once DOKU_PLUGIN."bez/models/bezcache.php"; 8 9$causo = new Causes(); 10$bezcache = new Bezcache(); 11 12$issue_id = (int)$nparams['id']; 13$issue = $this->model->issues->get_one($issue_id); 14 15/*casue*/ 16$cause_id = ''; 17if (isset($nparams['cid']) && $nparams['cid'] != '') { 18 $cause_id = (int)$nparams['cid']; 19 $template['cause'] = $causo->join($causo->getone($cause_id)); 20} 21 22/*edycja*/ 23if (isset($nparams['tid'])) { 24 $action = $nparams['action']; 25 $tid = (int)$nparams['tid']; 26 27 $task = $this->model->tasks->get_one($tid); 28 29 $template['auth_level'] = $task->get_level(); 30 $template['state_string'] = $task->state_string(); 31 32 if (isset($nparams['id'])) { 33 $template['causes'] = $causo->get($issue_id); 34 } 35 36 if (!$action) 37 $action = 'edit'; 38 39 if ($action == 'edit') { 40 $value = $task->get_assoc(); 41 } else if ($action == 'update') { 42 try { 43 //checkboxes 44 if (!isset($_POST['all_day_event'])) { 45 $_POST['all_day_event'] = '0'; 46 } 47 $task->set_data($_POST); 48 $task->set_acl($_POST); 49 //for reason 50 $task->set_state($_POST); 51 52 if ($task->any_errors()) { 53 $errors = $task->get_errors(); 54 $value = $_POST; 55 } else { 56 $this->model->tasks->save($task); 57 $bezcache->task_toupdate($task->id); 58 59 $issue->add_participant($task->executor); 60 $issue->update_last_activity(); 61 $this->model->issues->save($issue); 62 63 if ($cause_id == NULL) { 64 header("Location: ?id=bez:issue_task:id:$issue_id:tid:$tid"); 65 } else { 66 header("Location: ?id=bez:issue_cause_task:id:$issue_id:cid:$cause_id:tid:$tid"); 67 } 68 } 69 } catch (Exception $e) { 70 echo nl2br($e); 71 } 72 } 73 74 $template['task_button'] = $bezlang['change_task_button']; 75 76 if ($task->cause == NULL) { 77 $template['task_action'] = $this->id('task_form', 'id', $task->issue, 'tid', $task->id, 'action', 'update'); 78 } else { 79 $template['task_action'] = $this->id('task_form', 'id', $task->issue, 'cid', $task->cause, 'tid', $task->id, 'action', 'update'); 80 } 81 82 83 84/*dodawania*/ 85} else { 86 $defaults = array('issue' => $issue_id, 'cause' => $cause_id); 87 88 $task = $this->model->tasks->create_object($defaults); 89 90 $template['auth_level'] = $task->get_level(); 91 92 93 if (count($_POST) > 0) { 94 try { 95 //checkboxes 96 if (!isset($_POST['all_day_event'])) { 97 $_POST['all_day_event'] = '0'; 98 } 99 $task->set_data($_POST); 100 101 if ($task->any_errors()) { 102 $errors = $task->get_errors(); 103 $value = $_POST; 104 } else { 105 $tid = $this->model->tasks->save($task); 106 107 $issue->add_participant($task->executor); 108 $issue->update_last_activity(); 109 $this->model->issues->save($issue); 110 111 $title = 'Dodano zadanie'; 112 $exec = $task->executor; 113 $subject = "[$conf[title]] $title: #$issue_id #z$tid"; 114 $to = $this->model->users->get_user_full_name($exec).' <'.$this->model->users->get_user_email($exec).'>'; 115 if ($cause_id == '') { 116 $body = "$uri?id=".$this->id('issue_task', 'id', $issue_id, 'tid', $tid); 117 } else { 118 $body = "$uri?id=".$this->id('issue_cause_task', 'id', $issue_id, 'cid', $cause_id, 'tid', $tid); 119 } 120 $this->helper->mail($to, $subject, $body); 121 122 if ($cause_id == '') { 123 header("Location: ?id=bez:issue_task:id:$issue_id:tid:$tid"); 124 } else { 125 header("Location: ?id=bez:issue_cause_task:id:$issue_id:cid:$cause_id:tid:$tid"); 126 } 127 } 128 } catch (Exception $e) { 129 echo nl2br($e); 130 } 131 } else { 132 $value['all_day_event'] = '1'; 133 } 134 135 $template['task_button'] = $bezlang['add']; 136 if ($cause_id == '') { 137 $template['task_action'] = $this->id('task_form', 'id', $issue_id, 'action', 'add'); 138 } else { 139 $template['task_action'] = $this->id('task_form', 'id', $issue_id, 'cid', $cause_id, 'action', 'add'); 140 } 141 142} 143 144if (isset($nparams['id'])) { 145 $isso = new Issues(); 146 $template['issue'] = $isso->get($issue_id); 147} 148 149$template['user'] = $task->get_user(); 150$template['user_name'] = $this->model->users->get_user_full_name($template['user']); 151 152 153$template['users'] = $this->model->users->get_all(); 154$template['tasktypes'] = $this->model->tasktypes->get_all(); 155 156$template['issue_object'] = $this->model->issues->get_one($issue_id); 157 158 159