1<?php 2/** 3 * Plugin Now: Inserts a timestamp. 4 * 5 */ 6 7// must be run within DokuWiki 8if(!defined('DOKU_INC')) die(); 9 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once DOKU_PLUGIN.'syntax.php'; 12include_once DOKU_PLUGIN."bez/models/issues.php"; 13include_once DOKU_PLUGIN."bez/models/causes.php"; 14include_once DOKU_PLUGIN."bez/models/tasks.php"; 15include_once DOKU_PLUGIN."bez/models/taskactions.php"; 16 17include_once DOKU_PLUGIN."bez/mdl/model.php"; 18 19/** 20 * All DokuWiki plugins to extend the parser/rendering mechanism 21 * need to inherit from this class 22 */ 23class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin { 24 private $value = array(); 25 private $lang_code = ''; 26 private $default_lang = 'pl'; 27 28 private $auth, $model, $validator; 29 30 function getPType() { return 'block'; } 31 function getType() { return 'substition'; } 32 function getSort() { return 99; } 33 34 35 function connectTo($mode) { 36 $this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav'); 37 } 38 39 function __construct() { 40 global $conf, $INFO, $auth; 41 42 $id = $_GET['id']; 43 44 /*usuń : z początku id - link bezwzględny*/ 45 if ($id[0] == ':') 46 $id = substr($id, 1); 47 48 $ex = explode(':', $_GET['id']); 49 50 //wielojęzyczność 51 if ($ex[1] == 'bez') { 52 $this->lang_code = $ex[0]; 53 $ex = array_slice($ex, 1); 54 55 $old_lang = $conf['lang']; 56 $conf['lang'] = $this->lang_code; 57 $this->setupLocale(); 58 $conf['lang'] = $old_lang; 59 60 } else { 61 $this->lang_code = $conf['lang']; 62 } 63 64 for ($i = 0; $i < count($ex); $i += 2) 65 $this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 66 67 $this->model = new BEZ_mdl_Model($auth, $INFO['client'], $this->lang_code); 68 } 69 70 function handle($match, $state, $pos, Doku_Handler $handler) 71 { 72 return true; 73 } 74 75 function render($mode, Doku_Renderer $R, $pass) { 76 global $INFO, $auth; 77 78 $helper = $this->loadHelper('bez'); 79 if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 80 81 $R->info['cache'] = false; 82 83 $data = array( 84 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 85 ); 86 87 88 $data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues')); 89 90 $task_pages = array('issue_tasks', 'task_form', 'issue_task'); 91 $cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task'); 92 $issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages); 93 94 if ($this->value['bez'] == 'issues' || $this->value['bez'] == 'issue_report') { 95 if ($helper->user_editor()) { 96 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report')); 97 } 98 $data['bez:issues']['open'] = true; 99 } 100 if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) { 101 if ($helper->user_editor()) { 102 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report')); 103 } 104 $data['bez:issues']['open'] = true; 105 $id = (int)$this->value[id]; 106 107 $isso = new Issues(); 108 $issue_opened = $isso->opened($id); 109 $issue_proposal = $isso->is_proposal($id); 110 111 $tasko = new Tasks(); 112 $causo = new Causes(); 113 114 $causes = $causo->get($id); 115 $tasks = $tasko->get_corrections_ids($id); 116 117 $type = 'd'; 118 if (count($causes) + count($tasks) == 0) { 119 $type = 'f'; 120 } 121 122 $pid = "bez:issue:id:$id"; 123 $data[$pid] = array('id' => $pid, 'type' => $type, 'level' => 3, 124 'title' => "#$id", 'open' => true); 125 126 if (count($tasks) > 0) { 127 $pid = "bez:issue_tasks:id:$id"; 128 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 129 'title' => $this->getLang('correction_nav')); 130 if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 131 $data[$pid][open] = true; 132 133 if ($issue_opened) { 134 $rpid = "bez:task_form:id:$id"; 135 if ($helper->user_admin() && !$issue_proposal) 136 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 137 'title' => $this->getLang('add_correction')); 138 } 139 foreach ($tasks as $r) { 140 $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 141 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 142 'title' => '#z'.$r['id']); 143 } 144 } 145 } 146 147 if (count($causes) > 0) { 148 $pid = "bez:issue_causes:id:$id"; 149 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 150 'title' => $this->getLang('causes')); 151 if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 152 $data[$pid][open] = true; 153 if ($issue_opened) { 154 $rpid = "bez:cause_form:id:$id"; 155 if ($helper->user_admin() && !$issue_proposal) 156 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 157 'title' => $this->getLang('add_cause')); 158 } 159 160 foreach ($causes as $r) { 161 $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 162 $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 163 'title' => '#p'.$r[id]); 164 165 if ((int)$this->value['cid'] == $r[id]) { 166 $data[$rpid][open] = true; 167 168 $pres = $tasko->get($id, $r['id']); 169 foreach ($pres as $pr) { 170 $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 171 $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 172 'title' => '#z'.$pr[id]); 173 174 } 175 } 176 } 177 178 } 179 } 180 181 } 182 183 184 $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 185 186 if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task' 187 || $this->value['bez'] == 'task_form_plan' 188 || $this->value['bez'] == 'issue_task' 189 || $this->value['bez'] == 'task_form' 190 || $this->value['bez'] == 'task_report' 191 || $this->value['bez'] == 'issue_cause_task') { 192 $data['bez:tasks']['open'] = true; 193 194 if (isset($this->value['year'])) 195 $year = $this->value['year']; 196 else 197 $year = date('Y'); 198 199 200 if (isset($this->value['tid'])) { 201 $tasko = new Tasks(); 202 $this->value['tasktype'] = $tasko->get_type($this->value['tid']); 203 } 204 205 206 $page_id = "bez:tasks:tasktype:-none:year:$year"; 207 if (isset($this->value['tid']) && $this->value['tasktype'] == '') { 208 $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('tasks_no_type'), 'open' => true); 209 210 $page_id = 'bez:show_task:tid:'.$this->value['tid']; 211 //$page_id = $_GET['id']; 212 $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 213 214 } else { 215 $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $this->getLang('tasks_no_type')); 216 } 217 218 $tasktypes = $this->model->tasktypes->get_all(); 219 foreach ($tasktypes as $tasktype) { 220 $page_id = "bez:tasks:tasktype:".$tasktype->id.":year:$year"; 221 222 if ($this->value['tasktype'] == $tasktype->id) { 223 $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $tasktype->type, 'open' => true); 224 225 //~ if ($tasktype->get_level() >= 15) { 226 $report_id = "bez:task_report:tasktype:".$tasktype->id; 227 $data[$report_id] = array('id' => $report_id, 'type' => 'f', 'level' => 4, 'title' => $this->getLang('bds_task_report')); 228 //~ } 229 if (isset($this->value['tid'])) { 230 $page_id = 'bez:show_task:tid:'.$this->value['tid']; 231 //$page_id = $_GET['id']; 232 $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 233 } 234 } else { 235 $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $tasktype->type); 236 } 237 } 238 } 239 240 $isso = new Issues(); 241 $year_now = (int)date('Y'); 242 $mon_now = (int)date('n'); 243 244 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 245 if ($this->value['bez'] == 'report') { 246 $data['bez:report']['open'] = true; 247 248 $oldest = $isso->get_oldest_close_date(); 249 $year_old = (int)date('Y', $oldest); 250 $mon_old = (int)date('n', $oldest); 251 252 $mon = $mon_old; 253 for ($year = $year_old; $year <= $year_now; $year++) { 254 255 $y_key = 'bez:report:year:'.$year; 256 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 257 258 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 259 $data['bez:report:year:'.$year]['open'] = true; 260 261 if ($year == $year_now) 262 $mon_max = $mon_now; 263 else 264 $mon_max = 12; 265 for ( ; $mon <= $mon_max; $mon++) { 266 $m_key = $y_key.':month:'.$mon; 267 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 268 'title' => $mon < 10 ? '0'.$mon : $mon); 269 } 270 } 271 $mon = 1; 272 } 273 } 274 275 $data['bez:activity_report'] = array('id' => 'bez:activity_report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('activity_report')); 276 if ($this->value['bez'] == 'activity_report') { 277 $data['bez:activity_report']['open'] = true; 278 279 $oldest = $isso->get_oldest_close_date(); 280 $year_old = (int)date('Y', $oldest); 281 $mon_old = (int)date('n', $oldest); 282 283 $mon = $mon_old; 284 for ($year = $year_old; $year <= $year_now; $year++) { 285 286 $y_key = 'bez:activity_report:year:'.$year; 287 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 288 289 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 290 $data['bez:activity_report:year:'.$year]['open'] = true; 291 292 if ($year == $year_now) 293 $mon_max = $mon_now; 294 else 295 $mon_max = 12; 296 for ( ; $mon <= $mon_max; $mon++) { 297 $m_key = $y_key.':month:'.$mon; 298 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 299 'title' => $mon < 10 ? '0'.$mon : $mon); 300 } 301 } 302 $mon = 1; 303 } 304 } 305 306 307 308 if (isset($this->value['bez'])) { 309 $data['bez:start']['open'] = true; 310 } else { 311 $data['bez:start']['open'] = false; 312 array_splice($data, 1); 313 } 314 315 if ($helper->user_admin() && $data['bez:start']['open'] == true) { 316 $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 317 $this->getLang('types_manage')); 318 //~ $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 319 //~ $this->getLang('root_causes')); 320 $data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' => 321 $this->getLang('task_types')); 322 } 323 324 $R->doc .= '<div class="plugin__bez">'; 325 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 326 $R->doc .= '</div>'; 327 328 return true; 329 } 330 331 function _bezlink($id, $title) { 332 //$uri = wl($id); 333 $uri = DOKU_URL . 'doku.php?id='.$id; 334 return '<a href="'.$uri.'">'.($title).'</a>'; 335 } 336 337 function _list($item){ 338 339 $ex = explode(':', $item['id']); 340 341 for ($i = 0; $i < count($ex); $i += 2) 342 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 343 344 //pola brane pod uwagę przy określaniu aktualnej strony 345 $fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate'); 346 if ($item_value['bez'] == 'report' || $item_value['bez'] == 'activity_report') { 347 $fields[] = 'month'; 348 $fields[] = 'year'; 349 } 350 if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 351 unset($fields[0]); 352 353 $actual_page = true; 354 foreach ($fields as $field) 355 if ($item_value[$field] != $this->value[$field]) 356 $actual_page = false; 357 358 //specjalny hak dla zadań, boję się ruszać całej procedury 359 if ($item_value['bez'] == 'issue_task' || 360 $item_value['bez'] == 'issue_cause_task' || 361 $item_value['bez'] == 'task_form' || 362 $item_value['bez'] == 'show_task') 363 if ($item_value['tid'] == $this->value['tid']) 364 $actual_page = true; 365 366 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 367 $id = $item['id']; 368 if ($this->lang_code != $this->default_lang) 369 $id = $this->lang_code.':'.$id; 370 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 371 }else{ 372 $id = $item['id']; 373 if ($this->lang_code != $this->default_lang) 374 $id = $this->lang_code.':'.$id; 375 return $this->_bezlink($id, $item['title']); 376 } 377 378 } 379 380 function _li($item){ 381 if($item['type'] == "f"){ 382 return '<li class="level'.$item['level'].'">'; 383 }elseif($item['open']){ 384 return '<li class="open">'; 385 }else{ 386 return '<li class="closed">'; 387 } 388 } 389} 390